ConstrainedSpline
Tensor-product spline fit through noisy data values.
Declaration
classdef ConstrainedSpline < TensorSplineOverview
ConstrainedSpline is the noisy-data fitting counterpart to InterpolatingSpline. It fits a tensor-product spline basis to observations sampled on a one-dimensional grid or a rectilinear tensor grid, with optional robust weighting, correlated observation errors, local point constraints, and global shape constraints.
At each iteratively reweighted least-squares step it solves
\[\min_{\xi}\ (y - \mathbf{B}\xi)^{T} W (y - \mathbf{B}\xi)\]subject to
\[A_{\mathrm{eq}}\xi = b_{\mathrm{eq}}, \qquad A_{\mathrm{ineq}}\xi \le b_{\mathrm{ineq}}.\]When the distribution model provides correlated errors, the code forms an observation covariance
\[\Sigma_{ij} = \sigma_i \rho(x_i,x_j)\sigma_j\]and applies the corresponding weighted solve through a matrix factorization rather than explicitly forming \(\Sigma^{-1}\).
Basic usage
Use ConstrainedSpline.fromData(...) for ordinary one-dimensional noisy-data fitting and ConstrainedSpline.fromGriddedValues(...) when the observations lie on a rectilinear tensor grid.
t = linspace(0,1,20)';
x = exp(-20*(t-0.5).^2) + 0.05*randn(size(t));
spline = ConstrainedSpline.fromData(t, x, S=3, constraints=GlobalConstraint.positive());
xFit = spline(t);
Topics
- Create a constrained tensor spline
ConstrainedSplineCreate a constrained spline from canonical solved state.fromDataCreate a constrained spline fit from one-dimensional samples.fromGriddedValuesCreate a constrained spline fit from values on a rectilinear grid.
- Inspect fit results
dataPointsObservation locations as an N-by-D point matrix.dataValuesObservation values as an N-by-1 vector.distributionError model used while fitting the tensor spline.globalConstraintsGlobal shape constraints used during fitting.gridAxesGrid-axis objects used to define the fitted rectilinear lattice.gridVectorsGrid vectors used to define the fitted rectilinear lattice.pointConstraintsLocal point constraints used during fitting.
- Analyze the fit
smoothingMatrixReturn the smoothing matrix that maps observations to fitted values.
- Choose constraint locations
minimumConstraintPointsReturn a minimal set of one-dimensional locations for universal derivative constraints.
- Prepare knot sequences
terminatedKnotPointsEnsure each knot vector has S+1 repeated knots at its boundaries.
Developer Topics
These items document internal implementation details and are not part of the primary public API.
- Prepare fit inputs
normalizeConstraintInputsSplit typed constraint inputs into point and global arrays.
- Compile constraints
compileGlobalConstraintsCompile global constraints into coefficient inequalities.compilePointConstraintsCompile point constraints into equality and inequality systems.monotonicDifferenceMatrixBuild coefficient-difference inequalities along one dimension.
- Solve fit systems
constrainedWeightedSolutionSolve weighted least squares with optional linear constraints.leftSolveSolve a linear system, falling back to a pseudoinverse if needed.tensorModelSolutionSolve the tensor noisy-data model with iteratively reweighted least squares.weightMatrixFromSigma2Build the observation-weight matrix from per-observation variances.weightedNormalEquationsAssemble weighted normal equations.