mne.decoding.XdawnTransformer#

class mne.decoding.XdawnTransformer(n_components=2, reg=None, signal_cov=None, cov_method_params=None, *, restr_type=None, info=None, rank='full')[source]#

Implementation of the Xdawn Algorithm compatible with scikit-learn.

Xdawn is a spatial filtering method designed to improve the signal to signal + noise ratio (SSNR) of the event related responses. Xdawn was originally designed for P300 evoked potential by enhancing the target response with respect to the non-target response. This implementation is a generalization to any type of event related response.

Note

XdawnTransformer does not correct for epochs overlap. To correct overlaps see Xdawn.

Parameters:
n_componentsint (default 2)

The number of components to decompose the signals.

regfloat | str | None (default None)

If not None (same as 'empirical', default), allow regularization for covariance estimation. If float, shrinkage is used (0 <= shrinkage <= 1). For str options, reg will be passed to method to mne.compute_covariance().

signal_covNone | Covariance | array, shape (n_channels, n_channels)

The signal covariance used for whitening of the data. if None, the covariance is estimated from the epochs signal.

cov_method_paramsdict | None

Parameters to pass to mne.compute_covariance().

New in v0.16.

restr_type“restricting” | “whitening” | None

Restricting transformation for covariance matrices before performing generalized eigendecomposition. If “restricting” only restriction to the principal subspace of signal_cov will be performed. If “whitening”, covariance matrices will be additionally rescaled according to the whitening for the signal_cov. If None, no restriction will be applied. Defaults to None.

New in v1.11.

infomne.Info | None

The mne.Info object with information about the sensors and methods of measurement used for covariance estimation and generalized eigendecomposition. If None, one channel type and no projections will be assumed and if rank is dict, it will be sum of ranks per channel type. Defaults to None.

New in v1.11.

rankNone | ‘info’ | ‘full’ | dict

This controls the rank computation that can be read from the measurement info or estimated from the data. When a noise covariance is used for whitening, this should reflect the rank of that covariance, otherwise amplification of noise components can occur in whitening (e.g., often during source localization).

None

The rank will be estimated from the data after proper scaling of different channel types.

'info'

The rank is inferred from info. If data have been processed with Maxwell filtering, the Maxwell filtering header is used. Otherwise, the channel counts themselves are used. In both cases, the number of projectors is subtracted from the (effective) number of channels in the data. For example, if Maxwell filtering reduces the rank to 68, with two projectors the returned value will be 66.

'full'

The rank is assumed to be full, i.e. equal to the number of good channels. If a Covariance is passed, this can make sense if it has been (possibly improperly) regularized without taking into account the true data rank.

dict

Calculate the rank only for a subset of channel types, and explicitly specify the rank for the remaining channel types. This can be extremely useful if you already know the rank of (part of) your data, for instance in case you have calculated it earlier.

This parameter must be a dictionary whose keys correspond to channel types in the data (e.g. 'meg', 'mag', 'grad', 'eeg'), and whose values are integers representing the respective ranks. For example, {'mag': 90, 'eeg': 45} will assume a rank of 90 and 45 for magnetometer data and EEG data, respectively.

The ranks for all channel types present in the data, but not specified in the dictionary will be estimated empirically. That is, if you passed a dataset containing magnetometer, gradiometer, and EEG data together with the dictionary from the previous example, only the gradiometer rank would be determined, while the specified magnetometer and EEG ranks would be taken for granted.

The default is 'full'.

New in v1.11.

Attributes:
classes_array, shape (n_classes)

The event indices of the classes.

filters_array, shape (n_channels, n_channels)

The Xdawn components used to decompose the data for each event type.

patterns_array, shape (n_channels, n_channels)

The Xdawn patterns used to restore the signals for each event type.

Methods

fit(X[, y])

Fit Xdawn spatial filters.

fit_transform(X[, y])

Fit to data, then transform it.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

inverse_transform(X)

Remove selected components from the signal.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

transform(X)

Transform data with spatial filters.

See also

CSP, SPoC, SSD
fit(X, y=None)[source]#

Fit Xdawn spatial filters.

Parameters:
Xarray, shape (n_epochs, n_channels, n_samples)

The target data.

yarray, shape (n_epochs,) | None

The target labels. If None, Xdawn fit on the average evoked.

Returns:
selfXdawn instance

The Xdawn instance.

Examples using fit:

XDAWN Denoising

XDAWN Denoising
fit_transform(X, y=None, **fit_params)[source]#

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()[source]#

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)[source]#

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)[source]#

Remove selected components from the signal.

Given the unmixing matrix, transform data, zero out components, and inverse transform the data. This procedure will reconstruct the signals from which the dynamics described by the excluded components is subtracted.

Parameters:
Xarray, shape (n_epochs, n_components * n_classes, n_times)

The transformed data.

Returns:
Xarray, shape (n_epochs, n_channels * n_classes, n_times)

The inverse transform data.

set_output(*, transform=None)[source]#

Set output container.

See Introducing the set_output API for an example on how to use the API.

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

Configure output of transform and fit_transform.

  • “default”: Default output format of a transformer

  • “pandas”: DataFrame output

  • “polars”: Polars output

  • None: Transform configuration is unchanged

New in v1.4: “polars” option was added.

Returns:
selfestimator instance

Estimator instance.

set_params(**params)[source]#

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)[source]#

Transform data with spatial filters.

Parameters:
Xarray, shape (n_epochs, n_channels, n_samples)

The target data.

Returns:
Xarray, shape (n_epochs, n_components * n_classes, n_samples)

The transformed data.

Examples using mne.decoding.XdawnTransformer#

XDAWN Decoding From EEG data

XDAWN Decoding From EEG data

XDAWN Denoising

XDAWN Denoising