What returns scipy.interpolate.InterpolatedUnivariateSpline.get_coeffs?

I tried the following:

spline= interpolate.InterpolatedUnivariateSpline(X, Y, k=3)
coefs= spline.get_coeffs()

With five meanings in each of Xand YI ended up with coefsalso five meanings. Given that five data points imply four sections of splines and that the cubic polynomial has four coefficients, I would expect to get four times four = 16 coefficients. Does anyone know how to interpret the values ​​returned by a method get_coeffs? Is there a place where this is documented?

+4
source share
1 answer

, ** 2 ..: . , B-, , . B- , . , :

xv = [0, 1, 2, 3, 4, 5]
yv = [3, 6, 5, 7, 9, 1]

k = 1 (- ). B- " " :

hats

6 . 1 "" 0 . : y[0]*b[0] + ... + y[5]*b[5]. , get_coeffs , y.

InterpolatedUnivariateSpline(xv, yv, k=1).get_coeffs()  # [ 3.,  6.,  5.,  7.,  9.,  1.]

, "", , , . , B- . (: B- 3 , 1 4, , , - " "..) B- :

b-splines

, splrep splev scipy.interpolate, . tck; , 1 0, (b-).

k = 3
tck = splrep(xv, yv, s=0, k=k)
xx = np.linspace(min(xv), max(xv), 500)
bsplines = []
for j in range(len(xv)):
    tck_mod = (tck[0], np.arange(len(xv)+2*k-2) == j, k)
    bsplines.append(splev(xx, tck_mod))
    plt.plot(xx, bsplines[-1])

, bsplines, , get_coeffs, :

coeffs = InterpolatedUnivariateSpline(xv, yv, k=3).get_coeffs()
interp_spline = sum([coeff*bspline for coeff, bspline in zip(coeffs, bsplines)])
plt.plot(xx, interp_spline)

interpolation

B-, Cox-de Boor B- .

SymPy B-, . , ,

[0, 0, 0, 0, 2, 3, 5, 5, 5, 5]

, 0 5 , 1 4 , ( " " ). ( SymPy (1.1.1) , .)

from sympy import symbols, bspline_basis_set, plot
x = symbols('x')
xv_padded = [0, 0, 0, 0, 2, 3, 5, 5, 5, 5] 
bs = bspline_basis_set(3, xv_padded, x)

bs :

[Piecewise((-x**3/8 + 3*x**2/4 - 3*x/2 + 1, (x >= 0) & (x <= 2)), (0, True)), 
Piecewise((19*x**3/72 - 5*x**2/4 + 3*x/2, (x >= 0) & (x <= 2)), (-x**3/9 + x**2 - 3*x + 3, (x >= 2) & (x <= 3)), (0, True)), 
Piecewise((-31*x**3/180 + x**2/2, (x >= 0) & (x <= 2)), (11*x**3/45 - 2*x**2 + 5*x - 10/3, (x >= 2) & (x <= 3)), (-x**3/30 + x**2/2 - 5*x/2 + 25/6, (x >= 3) & (x <= 5)), (0, True)), 
Piecewise((x**3/30, (x >= 0) & (x <= 2)), (-11*x**3/45 + 5*x**2/3 - 10*x/3 + 20/9, (x >= 2) & (x <= 3)), (31*x**3/180 - 25*x**2/12 + 95*x/12 - 325/36, (x >= 3) & (x <= 5)), (0, True)), 
Piecewise((x**3/9 - 2*x**2/3 + 4*x/3 - 8/9, (x >= 2) & (x <= 3)), (-19*x**3/72 + 65*x**2/24 - 211*x/24 + 665/72, (x >= 3) & (x <= 5)), (0, True)), 
Piecewise((x**3/8 - 9*x**2/8 + 27*x/8 - 27/8, (x >= 3) & (x <= 5)), (0, True))]
+1

All Articles