Smoothing Splines#
Functions to smooth data.
- splineops.smoothing_splines.smoothing_spline.periodize(x: ndarray[tuple[int, ...], dtype[_ScalarType_co]], m: int) ndarray[tuple[int, ...], dtype[_ScalarType_co]]#
Periodize the input array by concatenating m copies of it.
- Parameters:
x (ndarray) – Input array to be periodized.
m (int) – Number of times to concatenate the array.
- Returns:
xp – The periodized array, which has its size multiplied by m along the concatenation axis.
- Return type:
ndarray
Examples
>>> import numpy as np >>> from splineops.interpolate.smooth.smoothing_spline import periodize >>> x = np.array([1, 2, 3]) >>> periodize(x, 2) array([1, 2, 3, 1, 2, 3])
- splineops.smoothing_splines.smoothing_spline.recursive_smoothing_spline(signal: ndarray[tuple[int, ...], dtype[_ScalarType_co]], lamb: float = 1.0) ndarray[tuple[int, ...], dtype[_ScalarType_co]]#
Apply a recursive first-order smoothing spline filter (piecewise-linear).
This implements the symmetric all-pole factorization (causal + anticausal) for the first-order smoothing spline filter.
Notes
This is NOT the cubic smoother (which requires a higher-order recursion).
Includes DC normalization so constant signals remain constant.
- Parameters:
signal (ndarray) – 1D array of data points to smooth.
lamb (float, optional) – Smoothing parameter (>= 0). Default is 1.0.
- Returns:
smoothed_signal – Smoothed data, same length as signal.
- Return type:
ndarray
- splineops.smoothing_splines.smoothing_spline.smoothing_spline(y: ndarray[tuple[int, ...], dtype[_ScalarType_co]], lamb: float, m: int, gamma: float) Tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]]#
Compute the fractional smoothing spline at m-times upsampling of the input.
This function returns samples of the smoothing spline for a given input sequence, sampled at m times the rate of the input. The input is assumed to be sampled at integer locations 0..N-1.
- Parameters:
- Returns:
t (ndarray) – The upsampled time vector, of length approximately N * m.
ys (ndarray) – The smoothing spline samples, of length approximately N * m.
Examples
>>> import numpy as np >>> from splineops.interpolate.smooth.smoothing_spline import smoothing_spline >>> y = np.array([1., 2., 3.]) >>> t, ys = smoothing_spline(y, lamb=0.1, m=2, gamma=1.5) >>> t.shape, ys.shape ((6,), (6,))
- splineops.smoothing_splines.smoothing_spline.smoothing_spline_nd(data: ndarray[tuple[int, ...], dtype[_ScalarType_co]], lamb: float, gamma: float) ndarray[tuple[int, ...], dtype[_ScalarType_co]]#
Apply multi-dimensional fractional smoothing spline to the input data.
- Parameters:
- Returns:
data_smooth – Smoothed data of the same shape as data.
- Return type:
ndarray
Examples
>>> import numpy as np >>> from splineops.interpolate.smooth.smoothing_spline import smoothing_spline_nd >>> x = np.random.rand(4, 4) >>> x_smooth = smoothing_spline_nd(x, lamb=0.5, gamma=1.0) >>> x_smooth.shape (4, 4)