Splines
Let ¶
Is piecewise linear?
Solutions
Yes: it can be written in a piecewise form...
...such that each of the pieces ( and ) are linear.
Is a linear spline? Why or why not?
Solutions
Yes: it is piecewise linear, with one knot at , and at that knot .
Is a cubic spline? Why or why not?
Solutions
No: its derivative at zero is discontinuous; but .
Linear splines, and a basis¶
Suppose is a linear spline. What conditions does it satisfy at its knots? What conditions does it satisfy between its knots?
Solutions
is continuous at the knots and linear between the knots.
Consider the space of all linear splines with a single knot at . It is possible to create a three-dimensional basis for this space, i.e. a set of three functions such that any function in the space can be written as for some suitable choice of coefficients . List three functions that, together, form such a basis.
Solutions
Here’s one option. , , and .
Let ¶
Is its derivative continuous?
SolutionsYes: it is a piecewise quadratic (every piece is a polynomial of degree at most 2) with a knot at and at that knot the limit of the derivative from below agrees with the limit of the derivative from above .
Is it a cubic spline?
SolutionsNo: its second derivative is discontinuous; but .
Let . Is it a cubic spline?¶
Solutions
No: it is piecewise...
...but one of its pieces isn’t a cubic polynomial. The function is piecewise polynomial, but its degree is at most 7.
Write a linear spline¶
Give an example of a linear spline with three knots.
Solutions
Here is a cheeky answer:
This has three knots, sort of, at . There is some ambiguity about what a knot actually is. Does this function really have three knots? It is identically zero everywhere. Yet, the way we defined it, in pieces, it is defined piecewise with four pieces, so in that sense it has three knots. And it is certainly a linear spline (each piece is linear and it is continuous), albeit a trivial one. I wouldn’t take off points for this answer, though it isn’t what we think of as a linear spline with three knots.
Here would be a more conventional sort of answer.
Let . Is it a natural cubic spline?¶
Solutions
No, its first derivative grows unboundedly on the right, . So it is a cubic spline, but not a natural cubic spline.
Fourth derivatives for cubic splines¶
Let be a cubic spline with knots at 0 and 5. What is the fourth derivative of evaluated at 3, ?
Solutions
Zero.
General question type¶
More generally, given any sort of piecewise-defined function,
we might ask you questions like
it is a linear spline?
is it a cubic spline?
is it a natural cubic spline?
is it continuous?
is the first derivative of continuous?
is the second derivative of continuous?
are the pieces constant (true only if )?
are the pieces linear (true only if )?
are the pieces quadratic (true only if )?
You’ll need to be able to calculate the answers to these questions in terms of the coefficients. Because the pieces are all polynomials, any derivative of these pieces themselves will be continuous (e.g., if is a cubic polynomial then every derivative of is continuous). So when you’re thinking about continuity of derivatives for piecewise polynomials, you really just have to check the knots.
Smoothing spline¶
Consider a dataset with features and one numerical response for each of data points. You would like to fit this data using a GAM, with a smoothing spline for each feature. Which of the following will be your biggest challenge?
a. Picking the right regularization strength for each feature.
b. Choosing the right number of knots for each feature.
Solutions
The first answer is correct. With smoothing splines you don’t have to pick knots. But picking the regularization strength (that controls the roughness penalty) can be very challenging.
Generalized additive models (GAMs) make it possible to use methods that penalize “roughness” (integrated squared second derivative) even when is large: construct a one-dimensional component function for each feature and apply the roughness penalty to each component function separately. However, although GAMs make it possible, it isn’t exactly easy, because best results are often found by giving a different strength of roughness penalty to each component feature. Picking those regularization strengths is tricky.