pybaselines.spline.irsqr
- pybaselines.spline.irsqr(data, lam=100, quantile=0.05, num_knots=100, spline_degree=3, diff_order=3, max_iter=100, tol=1e-06, weights=None, eps=None, x_data=None)[source]
Iterative Reweighted Spline Quantile Regression (IRSQR).
Fits the baseline using quantile regression with penalized splines.
- Parameters:
- dataarray_like, shape (N,)
The y-values of the measured data, with N data points. Must not contain missing data (NaN) or Inf.
- lam
float, optional The smoothing parameter. Larger values will create smoother baselines. Default is 1e6.
- quantile
float, optional The quantile at which to fit the baseline. Default is 0.05.
- 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.
- diff_order
int, optional The order of the differential matrix. Must be greater than 0. Default is 3 (third order differential matrix). Typical values are 3, 2, or 1.
- max_iter
int, optional The max number of fit iterations. Default is 100.
- tol
float, optional The exit criteria. Default is 1e-6.
- 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.
- eps
float, optional A small value added to the square of the residual to prevent dividing by 0. Default is None, which uses the square of the maximum-absolute-value of the fit each iteration multiplied by 1e-6.
- 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.
- 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 quantile is not between 0 and 1.
References
Han, Q., et al. Iterative Reweighted Quantile Regression Using Augmented Lagrangian Optimization for Baseline Correction. 2018 5th International Conference on Information Science and Control Engineering (ICISCE), 2018, 280-284.