ArPls#
- class chemotools.baseline.ArPls(lam: float = 10000.0, ratio: float = 0.01, nr_iterations: int = 100, solver_type: Literal['banded', 'sparse'] = 'banded', max_iter_after_warmstart: int = 20)[源代码]
基类:
_BaselineWhittakerMixin,_BaseWhittakerAsymmetrically Reweighted Penalized Least Squares (ArPLS) baseline correction.
This algorithm estimates and removes smooth baselines from spectroscopic data by iteratively reweighting residuals in a penalized least squares framework. A second-order difference operator is used as the penalty term, which promotes a smooth baseline estimate.
The Whittaker smoothing step can be solved using either:
a banded solver (fast and memory-efficient, recommended for most spectra)
a sparse LU solver (more stable for ill-conditioned problems)
For efficiency, the algorithm supports warm-starting: when processing multiple spectra with similar baseline structure, weights from a previous fit can be reused, typically reducing the number of iterations needed.
- 参数:
lam (float, default=1e4) -- Regularization parameter controlling smoothness of the baseline. Larger values yield smoother baselines.
ratio (float, default=0.01) -- Convergence threshold for weight updates.
nr_iterations (int, default=100) -- Maximum number of reweighting iterations.
solver_type (Literal["banded", "sparse"], default="banded") -- If "banded", use the banded solver for Whittaker smoothing. If "sparse", use a sparse LU decomposition.
max_iter_after_warmstart (int, default=20) -- Maximum iterations allowed when warm-starting from previous weights.
- 变量:
n_features_in (int) -- The number of features in the input data.
DtD (np.ndarray) --
The precomputed banded representation of \(D^T D\) for the second-order difference operator.
Stored as a banded representation (
solveh_bandedformat) ifsolver_type='banded'Stored as a
scipy.sparseCSC matrix ifsolver_type='sparse'
self.w_init (np.ndarray) -- The weights set for warm-starting.
引用
- [1] Sung-June Baek, Aaron Park, Young-Jin Ahn, Jaebum Choo.
"Baseline correction using asymmetrically reweighted penalized least squares smoothing." Analyst 140 (1), 250–257 (2015).
示例
>>> from chemotools.baseline import ArPls >>> from chemotools.datasets import load_fermentation_train >>> # Load sample data >>> X, _ = load_fermentation_train() >>> # Instantiate the transformer >>> transformer = ArPls(lam=1e4, nr_iterations=100) ArPls() >>> transformer.fit(X) >>> # Generate baseline-corrected data >>> X_corrected = transformer.transform(X)
Attributes
w_init_- fit(X: ndarray, y=None) ArPls[源代码]
Fit ArPLS model to spectra.
- 参数:
X (np.ndarray of shape (n_samples, n_features)) -- The input spectra to fit the model to.
y (None) -- Ignored to align with API.
- 返回:
self -- Fitted estimator.
- 返回类型:
ArPlS
- transform(X: ndarray, y=None) ndarray[源代码]
Apply ArPLS baseline correction.
- 参数:
X (np.ndarray of shape (n_samples, n_features)) -- The input spectra to transform.
y (None) -- Ignored to align with API.
- 返回:
X_transformed -- The baseline-corrected spectra.
- 返回类型:
np.ndarray of shape (n_samples, n_features)