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”

Metric for the estimation of mean matrix used for whitening and dimension reduction. For the list of supported metrics, see pyriemann.utils.mean.mean_covariance().

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_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

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_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') Whitening

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

set_output(*, transform=None)

Set output container.

See sphx_glr_auto_examples_miscellaneous_plot_set_output.py for an example on how to use the API.

Parameters:
transform{“default”, “pandas”}, default=None

Configure output of transform and fit_transform.

  • “default”: Default output format of a transformer

  • “pandas”: DataFrame output

  • None: Transform configuration is unchanged

Returns:
selfestimator instance

Estimator instance.

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.