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:
f
is not linear in my case, so I shouldn’t chooseT
uniformly spaced: this would run the risk of giving me inefficiently many samples in some subset of thef(t)
points and too few samples in some other subset, hiding detail.- And then
g(t)
is of course not necessarily linear inf(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.