0

I have a bspline created with scipy.interpolate.splrep with points (x_0,y_0) to (x_n,y_n). Usual story. But I would like to add a data point (x_n+1,y_n+1) and appropriate knot without recomputing the entire spline. Can anyone think of a way of doing this elegantly?

I could always take the knot list returned by splrep, and add on the last knot of a smaller spline created with (x_n-2, y_n-2) to (x_n+1,y_n+1) but that seems less efficient than it could be.

wtfastro
  • 333
  • 1
  • 2
  • 6

1 Answers1

0

Short answer: No.

Spline construction is a global process, so if you add a data point, you really need to recompute the whole spline. Which involves solving an N-by-N linear system etc.

If you're adding many knots sequentially, you probably can construct a process where you're using a factorization of the colocation matrix on step n to compute things on step n+1. You'll need to carefully check the stability of this process. And splrep and friends do not give you any help here, so you'll need to write this yourself. (If you do, you might find it helpful to check the sources of interpolate.CubicSpline).

But before you start on that, consider using a local interpolator instead.

If all you want is to add a knot given data, then there's scipy.interpolate.insert.

ev-br
  • 24,968
  • 9
  • 65
  • 78