AirPls#

class chemotools.baseline.AirPls(lam: float = 10000.0, nr_iterations: int = 100, solver_type: Literal['banded', 'sparse'] = 'banded', max_iter_after_warmstart: int = 20)[源代码]

基类:_BaselineWhittakerMixin, _BaseWhittaker

Adaptive Iteratively Reweighted Penalized Least Squares (AirPls) baseline correction.

AirPls is a widely used algorithm for removing baselines from spectroscopic signals. It iteratively reweights residuals to suppress positive deviations (peaks) while adapting baseline estimates using an exponential weight update. A second-order difference operator (recommended) is used as the penalty term, ensuring the estimated baseline is smooth.

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, AirPls 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 required.

参数:
  • lam (float, default=1e4) -- Regularization parameter controlling smoothness of the baseline. Larger values yield smoother baselines.

  • 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_banded format) if solver_type='banded'

    • Stored as a scipy.sparse CSC matrix if solver_type='sparse'

  • self.w_init (np.ndarray) -- The weights set for warm-starting.

引用

[1] Z.-M. Zhang, S. Chen, Y.-Z. Liang.

"Baseline correction using adaptive iteratively reweighted penalized least squares." Analyst 135 (5), 1138–1146 (2010).

示例

>>> from chemotools.baseline import AirPls
>>> from chemotools.datasets import load_fermentation_train
>>> # Load sample data
>>> X, _ = load_fermentation_train()
>>> # Instantiate the transformer
>>> transformer = AirPls(lam=1e4, nr_iterations=100)
AirPls()
>>> transformer.fit(X)
>>> # Remove baselines
>>> X_corrected = transformer.transform(X)

Attributes

w_init_

fit(X: ndarray, y=None) AirPls[源代码]

Fit AirPls 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.

返回类型:

AirPls

transform(X: ndarray, y=None) ndarray[源代码]

Apply AirPls 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)