-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Knot placement under knot multiplicity #128
Comments
Hi, @dential. I am currently on parental leave and have not had the opportunity to answer you earlier. First, thank you for a presenting your question in such a clear way. The behavior you are observing is related to how the regression problem is solved. Let me try to explain it briefly without oversimplifying. When you call the .bspline_interpolator or .fit method, a linear system of equations is solved for the coefficients of the B-spline. The number of variables is equal to the number of coefficients of the B-spline, which is determined by the knot sequence. The number of equations is equal to the number of data points. Say you have N data points that you wish to interpolate with a B-spline of degree 3. The .bpline_interpolator method will design a knot sequence which gives N coefficients. For this case it will repeat end knots 4 times and remove two internal knots as you pointed out. With N data points (equations) and N coefficients (variables), the linear system becomes square and a unique solution can be found (under some technical assumptions on linear independence). If you manipulate the knot sequence, for example by adding knots, the linear system can become underdetermined. This means that there are more variables than equations and there is no longer a unique solution. The added variables increase the flexibility of the spline. As in your example with an augmented knot sequence, the spline can interpolate all points and begin to oscillate. To avoid this you may either reduce the number of knots to give you N coefficients, or put a penalty on the coefficients to encourage them to be close to zero (this technique is called regularization). If you wish to introduce a discontinuity at a point you have to increase the knot multiplicity, as you already have understood. Combine this with one of the two approaches above to avoid oscillations. If you use the .from_param and .fit method, you have to specify the knot sequence yourself. Designing a good knot sequence can be difficult and may require some knowledge of the data you have. With .bspline_interpolator, Splinter tries to automatically construct a good knot sequence, but it may be suboptimal for some problems. Hope that helps! And thank you for using the library. Kind regards, |
I am trying to build splines with discontinuities by increasing the multiplicity of the knot at the discontinuity. My understanding is that this can be achieved through splinter's support for custom knots; namely, using the two-step procedure described in #76 and #72.
However, as soon as I move away from using the
bspline_interpolator()
builder to building the spline from parameters usingBSpline.from_param()
, I get oscillations (as illustrated below).Oscillations occur, even when I don't introduce knot multiplicity in the interior of the knot vector, i.e. when just trying to replicate
bspline_interpolator()
usingBSpline.from_param()
:Examining the knots of the two splines shows that they differ in that
bspline_interpolator()
has "removed" the second and second-to-last elements (0.02 and 0.98, respectively):Removing these two elements from the knot vector fed into
BSpline.from_param()
makes the two splines identical:Introducing multiple knots at the discontinuity (0.5) leads to oscillations around the discontinuity...
... unless the knots surrounding the discontinuity (0.48 and 0.52) are removed:
I think I am missing something about knot placement. Why do knots surrounding knot multiplicities need to be "removed" in order to avoid oscillations?
The text was updated successfully, but these errors were encountered: