hyperspy_ml_algorithms.Whitening#

class hyperspy_ml_algorithms.Whitening(method='PCA', centre=True, epsilon=1e-10)#

Bases: object

Decorrelate variables via a whitening transformation.

A whitening transformation decorrelates the variables such that the covariance matrix of the whitened data is the identity matrix.

If X is a random vector with non-singular covariance matrix C, and W is a whitening matrix satisfying W^T W = C^{-1}, then the transformation Y = X @ W^T yields a whitened random vector Y with unit diagonal covariance. In ZCA whitening the matrix W = C^{-1/2}, while in PCA whitening W is derived from the eigensystem of C. More details can be found in [Kessy2015].

Parameters:
method{‘PCA’, ‘ZCA’}, default=’PCA’

Whitening method. PCA whitening is the default for backward compatibility with HyperSpy < 1.6.0.

centrebool, default=True

If True, centre the data by subtracting the feature-wise mean before computing the whitening transform.

epsilonfloat, default=1e-10

Small constant added to eigenvalues before taking the inverse square root to avoid division by zero.

Attributes:
whitening_matrix_array-like, shape (n_features, n_features)

Learned whitening matrix W such that Y = (X - self.mean_) @ self.whitening_matrix_.T.

mean_array-like, shape (n_features,)

Feature-wise mean of the training data. Set to zeros when centre=False.

Notes

The y parameter in fit and fit_transform is ignored (sklearn API compatibility).

References

[Kessy2015]

A. Kessy, A. Lewin, and K. Strimmer, “Optimal Whitening and Decorrelation”, arXiv:1512.00809, (2015), https://arxiv.org/pdf/1512.00809.pdf

__init__(method='PCA', centre=True, epsilon=1e-10)#

Methods

__init__([method, centre, epsilon])

fit(X[, y])

Compute the whitening matrix from the data X.

fit_transform(X[, y])

Fit to X then whiten it in one call.

transform(X)

Whiten data X using the learned whitening matrix.