pybaselines.spline.pspline_iasls
- pybaselines.spline.pspline_iasls(data, x_data=None, lam=10.0, p=0.01, lam_1=0.0001, num_knots=100, spline_degree=3, max_iter=50, tol=0.001, weights=None, diff_order=2)[source]
A penalized spline version of the IAsLS algorithm.
- Parameters:
- dataarray_like, shape (N,)
The y-values of the measured data, with N data points. Must not contain missing data (NaN) or Inf.
- x_dataarray_like, shape (N,), optional
The x-values of the measured data. Default is None, which will create an array from -1 to 1 with N points.
- lam
float, optional The smoothing parameter. Larger values will create smoother baselines. Default is 1e1.
- p
float, optional The penalizing weighting factor. Must be between 0 and 1. Values greater than the baseline will be given p weight, and values less than the baseline will be given 1 - p weight. Default is 1e-2.
- lam_1
float, optional The smoothing parameter for the first derivative of the residual. Default is 1e-4.
- num_knots
int, optional The number of knots for the spline. Default is 100.
- spline_degree
int, optional The degree of the spline. Default is 3, which is a cubic spline.
- max_iter
int, optional The max number of fit iterations. Default is 50.
- tol
float, optional The exit criteria. Default is 1e-3.
- weightsarray_like, shape (N,), optional
The weighting array. If None (default), then the initial weights will be an array with size equal to N and all values set to 1.
- diff_order
int, optional The order of the differential matrix. Must be greater than 1. Default is 2 (second order differential matrix). Typical values are 2 or 3.
- Returns:
- baseline
numpy.ndarray, shape (N,) The calculated baseline.
- params
dict A dictionary with the following items:
- 'weights': numpy.ndarray, shape (N,)
The weight array used for fitting the data.
- 'tol_history': numpy.ndarray
An array containing the calculated tolerance values for each iteration. The length of the array is the number of iterations completed. If the last value in the array is greater than the input tol value, then the function did not converge.
- baseline
- Raises:
ValueErrorRaised if p is not between 0 and 1 or if diff_order is less than 2.
See also
References
He, S., et al. Baseline correction for raman spectra using an improved asymmetric least squares method, Analytical Methods, 2014, 6(12), 4402-4407.
Eilers, P., et al. Splines, knots, and penalties. Wiley Interdisciplinary Reviews: Computational Statistics, 2010, 2(6), 637-653.