chemometrics.AsymWhittaker¶
- class chemometrics.AsymWhittaker(penalty, constraint_order=2, asym_factor=0.99)¶
Bases:
TransformerMixin
,BaseEstimator
Background correction X with an asymmetric Whittaker filter
AsymWhittaker smooths X with an asymmetric Whittaker filter. The filter estimates the background by a non-parametric line constraint by its derivative smoothness. penalty defines the penalty on non-smoothness.
- Parameters
penalty (float) – Scaling factor of the penalty term for non-smoothness.
constraint_order (int) – Defines on which order of derivative the smoothness constraint acts on.
asym_factor (float) – Relative weight of negative residuals. Positive residuals obtain a weight of 1-asym_factor. The default value is 0.99.
- background_¶
Estimated background from last call to transform.
- Type
(n, m) ndarray
Notes
AsymWhittaker uses sparse matrices for efficiency reasons. X may however be a full matrix. In contrast to the proposed algorithm by Eilers 1, no Cholesky decomposition is used. The reason is twofold. The Cholesky decomposition is not implemented for sparse matrices in Numpy/Scipy. Eilers uses the Cholesky decomposition to prevent Matlab from “reordering the sparse equation systems for minimal bandwidth”. Matlab seems to rely on UMFPACK for sparse matrix devision 2 which implements column reordering for sparsity preservation. As the sparse matrix we are working with is square and positive-definite, we can rely on the builtin factorize method, which solves with UMFPACK if installed, otherwise with SuperLU.
References
Application of whittaker smoother to spectroscopic data 1.
- 1(1,2)
Paul H. Eilers, A perfect smoother, Anal. Chem., vol 75, 14, pp. 3631-3636, 2003.
- 2
UMFPAC, https://en.wikipedia.org/wiki/UMFPACK, accessed 03.May.2020.
- __init__(penalty, constraint_order=2, asym_factor=0.99)¶
Methods
__init__
(penalty[, constraint_order, ...])fit
(X[, y])Calculate regression matrix for later use.
fit_transform
(X[, y])Fit to data, then transform it.
get_params
([deep])Get parameters for this estimator.
set_params
(**params)Set the parameters of this estimator.
transform
(X[, copy])Do asymmetric Whittaker background subtraction
- fit(X, y=None)¶
Calculate regression matrix for later use.
- Parameters
X ((n, m) ndarray) – Data to be pretreated.
n
samples xm
variables (typically wavelengths)y – Ignored
- fit_transform(X, y=None, **fit_params)¶
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters
X (array-like of shape (n_samples, n_features)) – Input samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).
**fit_params (dict) – Additional fit parameters.
- Returns
X_new – Transformed array.
- Return type
ndarray array of shape (n_samples, n_features_new)
- get_params(deep=True)¶
Get parameters for this estimator.
- Parameters
deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
params – Parameter names mapped to their values.
- Return type
dict
- set_params(**params)¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters
**params (dict) – Estimator parameters.
- Returns
self – Estimator instance.
- Return type
estimator instance
- transform(X, copy=True)¶
Do asymmetric Whittaker background subtraction
- Parameters
X ((n, m) ndarray) – Data to be pretreated.
n
samples xm
variables (typically wavelengths)copy (bool (True default)) – Whether to genrate a copy of the input file or calculate in place.