Library hunt: adaptive sampling for parametric plots

Hey all, I’m looking for a library that can adaptively sample parametric plots (for reasonably well-behaved functions). I’m on the verge of writing a little library here but it seems like so many people would want this that I feel it “should” already exist. Does anyone have a pointer?

Problem description

Say I have two functions f, g :: Float64 -> Float64 and I want to plot the parametric plot of the [(f(t), g(t)) for t in T] and the task is to choose T such that the resulting plot shows a decent level of detail in some given interval of f(t) values.

This problem is nontrivial for two reasons:

  1. f is not linear in my case, so I shouldn’t choose T uniformly spaced: this would run the risk of giving me inefficiently many samples in some subset of the f(t) points and too few samples in some other subset, hiding detail.
  2. And then g(t) is of course not necessarily linear in f(t), so ideally I’ll want more samples where it has higher curvature.

Problem 1. is more severe for my specific use case because there’s a high risk of just going “blind”.

An obvious special case of this is non-parametric adaptive plots, i.e., f = identity.

Approach

In my case, f and g are reasonably well-behaved: they’re both differentiable with derivatives computable via ForwardDiff, f is even monotonic, etc.

The algorithm itself is not super complicated: successive bipartition and checking the derivative (or honestly just checking the function value against linear approximation) should do the trick. And then I want some safeguards against too many samples, error threshold, etc.

Some libraries that don’t seem to do the trick

  • AdaptiveSampling.jl seems to be more about compressing oversampled signals than what I wanna do.
  • Someone suggested Mamba could do something clever, but I don’t know and it’s 5 years out of date and incompatible with everything else I’m using by now.
  • One might be able to do something with ApproxFun but I don’t really need global approximation.

This sounds good.
You may want to look at the following reference:
Pagani, Luca and Scott, Paul J. (2018) Curvature based sampling of curves and surfaces. Computer Aided Geometric Design, 59. pp. 32-48. ISSN 0167-839

2 Likes

I have seen one that may fit your need, but it’s in python. GitHub - python-adaptive/adaptive: 📈 Adaptive: parallel active learning of mathematical functions Don’t know if there’s a Julia counterpart.

I see you created ParametricAdaptiveSampling.jl. Since you mention Meshes.jl in your README, I am wondering whether you saw that Meshes.jl already supports parametrized curves. It also already has different sampling methods, which work with the ParametrizedCurve type. I guess your specific implementation of an adaptive sampling you implemented in ParametricAdaptiveSampling.jl is not yet supported (I haven’t looked at your algorithm in detail), but maybe it would make sense to think about adding this sampling method to the set of continuous sampling method. The benefit of this would be that you or any user of the adaptive sampling could use all of the machinery of Meshes.jl and that Meshes.jl already provides some useful helpers that you can probably reuse in your implementation. It would also probably lead to a higher visibility. Another benefit can be that it probably very well generalizes to other types of curves, such as BezierCurve, for which a parametrization is already defined in Meshes.jl. Pinging @juliohm since he might me interested and can also provide better guidance than me if you indeed consider adding this (really nice!) functionality to Meshes.jl.

2 Likes

Thank you for the ping @JoshuaLampert ! I fully agree with your comment and suggestions. IMHO, the Julia community is too tiny to afford isolated efforts.

I couldn’t find the ParametricAdaptiveSampling.jl repository though. The Discourse link is redirecting me to a “Page not found”. What is the full URL?

1 Like

The repository is GitHub - sschuldenzucker/ParametricAdaptiveSampling.jl: Automatic adaptive sampling of one-dimensional parametric curves in Julia, mainly for plotting. It’s not yet registered. I just saw it in another thread.

1 Like

Oooh! Well looks like I was right, it is related! :slight_smile: Thanks a lot for the ping! I’ll cancel my registry inclusion request (in time lock right now) for now and check if this can be leveleraged or maybe become a simple wrapper, or just evaporate tbh. Fully agree on isolated efforts.

2 Likes