EDIT: Although I have posted an answer based on my current progress, this in incomplete. Please see the "open issues" section in the answer.
Most plotting functions in Mathematica adjust the sampling density dynamically, based on the slope of the function:
DensityPlot[1/(
1 + Exp[10 (Sqrt[x^2 + y^2] - 3)]), {x, 0, 5}, {y, 0, 5},
Mesh -> All, PlotRange -> All]
Unfortunately the internal algorithm that does this is not directly callable.
Question:
I have a slow to compute 2D function (takes up to 10-40 seconds for a single point even though it's in optimized C++ called through LibraryLink) that I need to sample. How can I sample it adaptively, in a convenient and controlled way?
Since the function is so slow to compute,
I'd like to be able to take the existing points, and refine them more if needed (i.e. continue the computation using the existing results)
I can't use DensityPlot directly because I can't control how many points it is going to compute, and I need an upper limit on that (i.e. an upper limit on computation time). It also can't be interrupted and continued later.
I am looking for
effective methods to do this
implementations in Mathematica (either as an answer or pointers to libraries)
The messy details:
I am trying to compute a phase diagram and map the boundaries between the phases precisely. So I don't need the function value everywhere, only where it very suddenly drops. The function is either of magnitude 1 (say, between $0.1 \div 1$), or very small (close to zero).
The function is computed using Monte Carlo methods, so at a small scale it doesn't appear smooth, and I might get inconsistent results close to the phase boundaries on subsequent runs of the function.
This should give you an idea of what sort of function I'd like to apply this to, which might be important when choosing a method.
Plot
than changingMaxRecursion
andPlotPoints
.) $\endgroup$