Writing B-spline as Piecewise Cubic

2019-07-04 05:30发布

问题:

I'm using Scipy's SmoothBivariateSpline class to create a cubic B-spline on bivariate data. I now need to write the piecewise polynomial expression for this spline curve.

My mathematical background isn't very strong, so I wasn't able to write my own algorithm for transforming from the t, c, k output of the SmoothBivariateSpline to a polynomial representation. If this is feasible, can you provide pointers on how to approach this? I noticed that Scipy has interpolate.ppform, but I can't find any docs for it - is this relevant?

One method I was considering was breaking down the domain of the spline into regions at each knot (with (n-1)^2 total regions, where n is the number of knots), then performing a cubic regression on many points on the spline curve in each region in order to calculate a cubic regression to the data for every region. Is this a valid approach?

The former method seems much more rigorous, so I'd prefer to use that one, but the latter is also acceptable.

回答1:

B-splines can be converted to piecewise polynomials efficiently.

This can be easily done in Scipy 0.14.0 (to be released in a couple of months) which has scipy.interpolate.PPoly.from_spline.

The algorithm of computing piecewise polynomials from the spline t, c, k itself is very simple, so in the meantime you can write your own function that computes the polynomial coefficients: https://github.com/scipy/scipy/blob/master/scipy/interpolate/interpolate.py#L938