2

I have a problem: I have an expensive to compute 1D function (float->float). I want to approximate it with splines for efficiency.

I know I can define a set of knot points with a uniform grid on the function's domain, evaluate the function on that grid and calculate a spline over that set. But the functions are special - they have huge dull regions and some special places with complex behavior. I want an algorithm that adaptively finds some optimal set of the knot points, sapling them more densely where the function has a difficult shape, and less so when the spline makes a good job in approximating it.

How can I find a library (preferably Python, but at this point I will take anything open source) that does it with an automatic knot selection? I tried many Google searches and still found nothing

mpx
  • 3,081
  • 2
  • 26
  • 56
Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68
  • https://stackoverflow.com/questions/37379609/extract-knots-basis-coefficients-and-predictions-for-p-splines-in-adaptive-smo If you had done a search on SO for "adaptive splines" you might have found this. Sometimes it's more convincing to include what you used as a search strategy. My close vote was for the appearance that this was a request for a package recommendation. – IRTFM Aug 27 '21 at 21:21
  • @IRTFM Thank you. I did find methods that start off with the grid of points, and then simplify it. The problem is that in my case (I am approximating distributions) I need a rough grid just let the algorithm get a feel where the "interesting" regions are, and then to let the algorithm sample the function in potentially much finer resolution in order to produce good knots. I am looking for an algorithm that actually uses the function object as an input, with just an auxiliary argument for minimum resolution in which the function will be sampled. – Adam Ryczkowski Aug 27 '21 at 21:33
  • I found this [site](https://jbhender.github.io/Stats506/F18/GP/Group9.html) that uses several machine learning models with best guess knots to find the optimum knot set. They provide the code in R and Python. It is probably not the best approach, but it is a method that could work. – Kat Aug 27 '21 at 23:18
  • You would have a bit of work translating it to Python or R, but this [article](https://doi.org/10.1371/journal.pone.0173857) by Dung and Tjahjowidodo (2017) provides the code for optimal knots in Matlab. – Kat Aug 27 '21 at 23:38
  • In Mathematica there is a https://reference.wolfram.com/language/ref/FunctionInterpolation.html, but that is obviously not an Open Source code. – Adam Ryczkowski Aug 28 '21 at 07:12

1 Answers1

0

I have finally found one, that seems to be working. It's splipy. It's method fit produces a B-Spline interpolation of the function object, with a relatively precise way to control the accuracy of the interpolation.

The source is on GitHub.

Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68