Spline baselines in pybaselines are primarily implemented using Basis splines (B-splines) and Penalized B-splines (P-splines).
B-splines
A B-spline is a piecewise joining of individual curves. The number of spline basis functions ($M$) is determined by the number of knots (num_knots) plus the spline degree minus 1.
P-splines
To control the smoothness of the fitting spline, pybaselines uses P-splines. This method adds a penalty on the finite-difference between spline coefficients to the least-squares minimization.
Key parameters for controlling smoothness include:
- Penalty scale factor ($\lambda$): Controls the strength of the smoothness penalty.
- Finite-difference operator order ($d$): The order of the difference used in the penalty.
P-splines use uniformly spaced knots to facilitate the calculation of the finite-difference.
Relationship to Whittaker Smoothing
P-splines are mathematically related to Whittaker smoothing. If the number of basis functions ($M$) is set equal to the number of data points ($N$) and the spline degree is set to 0, the P-spline equation becomes identical to the Whittaker smoothing equation.