incline.SmoothingSpline¶
- class incline.SmoothingSpline(penalty=None)[source]¶
Cubic smoothing spline with a second-derivative roughness penalty.
With independent errors this wraps
scipy.interpolate.make_smoothing_spline(), SciPy’s implementation of Woltring’s generalized cross-validation algorithm. With a non-diagonal or heteroskedastic covariance it selects the penalty by generalized maximum likelihood and solves the corresponding penalized generalized least-squares problem. A fixed penalty makes the smoother linear; selecting it from the data makes the fit nonlinear.- Variables:
penalty (float | None) – Roughness penalty. Chosen by generalized cross-validation when None – which makes the fit data-dependent and therefore nonlinear.
- Parameters:
penalty (float | None)
Note
The GCV algorithm is due to Herman J. Woltring (1986), https://doi.org/10.1016/0141-1195(86)90098-7. The correlated-error penalized-GLS and GML formulation follows Diggle and Hutchinson (1989), https://doi.org/10.1111/j.1467-842X.1989.tb00510.x, and Wang (1998), https://doi.org/10.1080/01621459.1998.10474115. Incline selects the penalty conditional on the fitted
NoiseModel; it does not jointly optimize the covariance and penalty. The independent fit and analytic differentiation delegate toscipy.interpolate.make_smoothing_spline(). The GML fit reports ageneralized_penaltyin its provenance. That value belongs to the covariance-weighted objective and is not interchangeable with the publicpenaltyargument used by the independent-error fit.Methods
__init__([penalty])analytic_operators(axis, derivative_order)State the smoothing and derivative operators directly, if known.
bootstrap_uncertainty(estimate, axis, y, ...)Repeat covariance fitting and GML selection in every Gaussian draw.
evaluate(axis, y, derivative_order)Fit the smoothing spline and differentiate it.
evaluate_with_noise(axis, y, ...)Use covariance-aware GML when an adaptive fit has dependent errors.
fit(axis, y[, derivative_order, ...])Estimate the trend and, optionally, its uncertainty.
native_posterior(axis, y, derivative_order, ...)Uncertainty from the smoother's own probability model.
operators(axis, derivative_order)The smoothing and derivative operators for this configuration.
params()Report the penalty.
scale_of(axis)Invert the bandwidth-to-penalty map.
with_scale(scale, axis)Set the penalty from an equivalent bandwidth.
Attributes
has_native_posteriorLinear when the penalty is fixed, not cross-validated.
linearrequires_regular_gridAdaptive selection uses covariance; a fixed penalty does not.
- evaluate_with_noise(axis, y, derivative_order, noise)[source]¶
Use covariance-aware GML when an adaptive fit has dependent errors.
- bootstrap_uncertainty(estimate, axis, y, derivative_order, noise_model, noise_fit, confidence_level, n_bootstrap, random_state)[source]¶
Repeat covariance fitting and GML selection in every Gaussian draw.
- Parameters:
estimate (TrendEstimate)
axis (TimeAxis)
y (npt.NDArray[np.float64])
derivative_order (int)
noise_model (NoiseModel)
noise_fit (NoiseFit)
confidence_level (float)
n_bootstrap (int)
random_state (int | np.random.Generator | None)
- Return type:
tuple[npt.NDArray[np.float64] | None, npt.NDArray[np.float64] | None, npt.NDArray[np.float64] | None]
- with_scale(scale, axis)[source]¶
Set the penalty from an equivalent bandwidth.
For a cubic smoothing spline the equivalent kernel width behaves like
(penalty / n) ** (1/4), so a target width ofscale * spanimpliespenalty = n * (scale * span) ** 4.