pyriemann.preprocessing.Whitening

class pyriemann.preprocessing.Whitening(metric='euclid', dim_red=None, verbose=False)

Whitening, and optional unsupervised dimension reduction.

Implementation of the whitening, and an optional unsupervised dimension reduction, with SPD matrices as inputs.

Parameters
metricstr, default=’euclid’

The metric for the estimation of mean matrix used for whitening and dimension reduction.

dim_redNone | dict, default=None
If None :

no dimension reduction during whitening.

If {'n_components': val} :

dimension reduction defining the number of components; val must be an integer superior to 1.

If {'expl_var': val} :

dimension reduction selecting the number of components such that the amount of variance that needs to be explained is greater than the percentage specified by val. val must be a float in (0,1], typically 0.99.

If {'max_cond': val} :

dimension reduction selecting the number of components such that the condition number of the mean matrix is lower than val. This threshold has a physiological interpretation, because it can be viewed as the ratio between the power of the strongest component (usually, eye-blink source) and the power of the lowest component you don’t want to keep (acquisition sensor noise). val must be a float strictly superior to 1, typically 100.

verbosebool, default=False

Verbose flag.

Notes

New in version 0.2.7.

Attributes
n_components_int

If fit, the number of components after dimension reduction.

filters_ndarray, shape (n_channels_, n_components_)

If fit, the spatial filters to whiten SPD matrices.

inv_filters_ndarray, shape (n_components_, n_channels_)

If fit, the spatial filters to unwhiten SPD matrices.

__init__(metric='euclid', dim_red=None, verbose=False)

Init.

fit(X, y=None, sample_weight=None)

Train whitening spatial filters.

Parameters
Xndarray, shape (n_matrices, n_channels, n_channels)

Set of SPD matrices.

yNone

Ignored as unsupervised.

sample_weightNone | ndarray, shape (n_matrices,), default=None

Weight of each matrix, to compute the weighted mean matrix used for whitening and dimension reduction. If None, it uses equal weights.

Returns
selfWhitening instance

The Whitening instance.

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
Xarray-like of shape (n_samples, n_features)

Input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters.

Returns
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True)

Get parameters for this estimator.

Parameters
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsdict

Parameter names mapped to their values.

inverse_transform(X)

Apply inverse whitening spatial filters.

Parameters
Xndarray, shape (n_matrices, n_components, n_components)

Set of whitened, and optionally reduced, SPD matrices.

Returns
Xiwndarray, shape (n_matrices, n_channels, n_channels)

Set of unwhitened, and optionally unreduced, SPD matrices.

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
**paramsdict

Estimator parameters.

Returns
selfestimator instance

Estimator instance.

transform(X)

Apply whitening spatial filters.

Parameters
Xndarray, shape (n_matrices, n_channels, n_channels)

Set of SPD matrices.

Returns
Xwndarray, shape (n_matrices, n_components, n_components)

Set of whitened, and optionally reduced, SPD matrices.