Regress#

Functions to perform regression on 1D data.

splineops.regress.sparsification.linear_spline(t: ndarray, knots: ndarray, amplitudes: ndarray, polynomial: ndarray) ndarray#

Evaluates a parametrized linear spline at specified location(s) t.

The spline is represented as:

s(t) = at + b + sum_{k=0}^{K} a_k (t - τ_k)_+

where a and b are the parameters of the linear component, and a_k and τ_k are the amplitudes and locations of the knots, respectively.

Parameters:
  • t (float or ndarray) – The location(s) where the spline should be evaluated.

  • knots (ndarray) – Knot locations of the spline.

  • amplitudes (ndarray) – Amplitudes of the knots.

  • polynomial (ndarray) – Coefficients (b, a) of the linear component.

Returns:

values – The evaluated spline values at t.

Return type:

float or ndarray

splineops.regress.sparsification.sparsest_interpolant(x: ndarray, y: ndarray, sparsity_tol: float = 1e-05) Tuple[ndarray, ndarray, ndarray]#

Computes the sparsest piecewise-linear spline that interpolates the given data points.

This function implements a method for finding the sparsest linear spline, based on total variation regularization on the second derivative. This approach promotes solutions with the fewest number of knots while maintaining fidelity to the data.

The optimal spline can be evaluated using the linear_spline() function with the outputs of this function.

Parameters:
  • x (ndarray) – Array of x-coordinates of data points.

  • y (ndarray) – Array of y-coordinates of data points.

  • sparsity_tol (float, optional) – Threshold for eliminating knots with small amplitude (default is 1e-5).

Returns:

  • knots (ndarray) – Array of knot locations for the optimal sparse spline.

  • amplitudes (ndarray) – Corresponding amplitudes of the knots.

  • polynomial (ndarray) – Coefficients (b, a) of the linear component p(t) = at + b.