Skip to main content

make_smoothing_spline

Function make_smoothing_spline 

Source
pub fn make_smoothing_spline(
    x: &[f64],
    y: &[f64],
    w: Option<&[f64]>,
    lam: Option<f64>,
) -> Result<SmoothingSpline, ErrorsJSL>
Expand description

The cubic smoothing spline of (x, y) with weights w (default 1) and smoothing parameter lam (SciPy’s make_smoothing_spline). Without lam, the parameter minimising the GCV score n ‖y − ŷ‖² / (n − tr A(λ))² over 0 < λ < n is used, found by the same bounded Brent search as SciPy.

In the cubic B-spline basis with knots x (ends repeated four times), the coefficients solve (Bᵀ W B + λ Ω) c = Bᵀ W y, where Bᵢⱼ = Bⱼ(xᵢ) and Ωᵢⱼ = ∫ Bᵢ'' Bⱼ'', restricted to natural splines by eliminating the two end coefficients. The matrices have half-bandwidth 3, so each solve costs O(n), as does the trace of the influence matrix, from the band of the inverse.