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.