0
$\begingroup$

I'm trying to teach myself Basis splines, from what I have read a basis spline of order K is non-zero in K segments only. Is this correct? I ask because when I use the following code to plot basis splines in R, some of the basis functions only span 2 or 3 segments (first dotted line from left etc.). May be it is just a convention in R, I mainly just want to make sure I understand the concept correctly.

Edit: Based on this link, it seems not all the basis splines produced in this plot are of degree 3. I should add 3 dummy knots on either end to get cubic bsplines between my input data range. Is this correct.

enter image description here

library(splines)
x = seq(1,10,0.01)
b = bs(x, knots = c(2.5, 5, 7.5), degree = 3, intercept = TRUE)
matplot(x, b, type = 'l')
abline(v = c(2.5, 5, 7.5), lty = 2)

EDIT: Below I produce 2 examples of fitting cubic bsplines (line in both the charts) to hypothetical data(dots in both the charts) for x between [0,4]. With 2 imaginary knots (knots at -2,-1,0,1,2,3,4,5,6), the fit is not very good but with 3 imaginary knots (knots at -3,-2,-1,0,1,2,3,4,5,6,7) it is perfect.enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Notice the knots at begin and end are repeated. Either you count the multiplicity of repeating knots (that is zero length segments), or you correct your statement to "non-zero" on $K$ segments at most. $\endgroup$
    – user251257
    Aug 31 '16 at 19:17
1
$\begingroup$

Suppose we're dealing with basis functions of order $k$ (i.e. degree = $k-1$) on the knot sequence $(t_i)$. Then the $i$-th b-spline basis function is non-zero on the interval $[t_i, t_{i+k}]$. If $t_i < \ldots < t_{i+k}$, then there are $k$ "segments" between $t_i$ and $t_{i+k}$. But if some of these knots are equal, then some of these $k$ segments will shrink to zero, so you may choose to not count them as segments at all.

In the example you plotted, it looks like your software automatically added some extra (and duplicated) knots at the ends of your curve. This is a common practice. So, though you asked for knots $(2.5, 5, 7.5)$, you actually got knots $(0,0,0,0,2.5,5,7.5,1,1,1,1)$. The repeated knots give you zero-length segments, and this throws off your segment-counting scheme.

More details in these notes.

$\endgroup$
6
  • $\begingroup$ Thank you. Followup question please - the domain of BSpline curve is the region where it has full support. Now, if I dont introduce multiplicity or imaginary knots (open bspline curve) then the domain will be a subset of x (in my original example). And it is technically correct to define my spline as a linear combination of these BSpline functions over this reduced domain only and not the entire original x. Is this correct, thanks very much for your help. $\endgroup$
    – Innocent
    Sep 4 '16 at 22:23
  • 1
    $\begingroup$ Yes. Correct.The domain of definition of the b-spline will be a proper subset of the the interval whose ends are the first and last knots. Again, Shene's notes have the details. $\endgroup$
    – bubba
    Sep 5 '16 at 1:05
  • $\begingroup$ I asked because some legacy code, that I'm working with, adds only 2 imaginary knots (each with multiplicity of 1 ) on each end for Cubic BSpline. So for 5 knots, they get 5 bsplines/coefficients. Where as based on the notes we must add 3 imaginary knots on each end to correctly express the spline as linear combination of BSplines and we will get 7 bsplines/coefficients for 5 knots. Though the current results still look reasonable, so i'm not sure. Thanks! $\endgroup$
    – Innocent
    Sep 5 '16 at 19:14
  • 1
    $\begingroup$ Using 4 zeros and 4 ones on a cubic spline is "traditional". If you go through the math, you will find that the b-spline value does not actually depend on the first and last knots. So, the first knot can be anything you like, as long as it's $\le0$, so you could actually omit it. Same for the last knot. The purpose of the added (repeated) knots is to get interpolation of the first and last control points. But this is not always what you want. $\endgroup$
    – bubba
    Sep 6 '16 at 0:11
  • $\begingroup$ I updated my question with an example of fit with 2 imaginary knots (at -2,-1 on left end and 5,6 on right end) vs 3 imaginary knots (at -3,-2,-1 on left end and 5,6,7 on right end). The fit in latter case is much better, but you probably suggested it should not matter. Pardon me if this sounds silly, I still have a lot to learn in this area. $\endgroup$
    – Innocent
    Sep 11 '16 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.