Reputation: 727
I'm trying to find out how the spline interpolation in scipy.interpolate.interp1d
decides what the derivatives of the fitting/smoothing function should be. From the documentation, I understand that interp1d
fits a spline if an int
(or quadratic
or cubic
) is passed to the kind
keyword.
But if I'm not providing any derivative information, how does it decide what the derivatives are? I tried to follow the function calls in the source code, but this only got me to the cryptic spleval
function, which just seems to call FITPACK. And I wasn't really sure how to find information about FITPACK from their website...
Upvotes: 2
Views: 1225
Reputation:
Spline derivatives at the knot points are not explicitly prescribed, they are determined by continuity/smoothness conditions. I'll take the cubic case as an example. You give n x-values and n y-values. A cubic spline has 4*(n-1) coefficients, 4 on each of (n-1) intervals between the given x-values. These coefficients are determined from the following conditions:
The total so far is 4*n-6 equations for 4*n-4 unknowns. Two additional equations are needed; the most popular choice is to require the 3rd derivative to be continuous at the leftmost and rightmost interior knots (this is called the "not a knot" condition). Now we have a linear system of size 4*n-4, which can be solved for the coefficients.
The above should not be confused with Hermite interpolation, which is where one prescribes the values of derivatives as well as of the function itself. This is a less common task, and to my knowledge, SciPy does not have a built-in tool for it.
Upvotes: 2