mne.preprocessing.Xdawn#
- class mne.preprocessing.Xdawn(n_components=2, signal_cov=None, correct_overlap='auto', reg=None, *, rank='full')[source]#
Implementation of the Xdawn Algorithm.
Xdawn [1][2] is a spatial filtering method designed to improve the signal to signal + noise ratio (SSNR) of the ERP 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 ERP.
- Parameters:
- n_components
int The number of components to decompose the signals.
- signal_cov
None|Covariance|ndarray, shape (n_channels, n_channels) (default None). The signal covariance used for whitening of the data. if None, the covariance is estimated from the epochs signal.
- correct_overlap‘auto’ | bool
Compute the independent evoked responses per condition, while correcting for event overlaps if any. If ‘auto’, then overlapp_correction = True if the events do overlap.
- reg
float|str|None If not None (same as
'empirical', default), allow regularization for covariance estimation. If float, shrinkage is used (0 <= shrinkage <= 1). For str options,regwill be passed asmethodtomne.compute_covariance().- rank
None| ‘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).
NoneThe 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
Covarianceis passed, this can make sense if it has been (possibly improperly) regularized without taking into account the true data rank.dictCalculate 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 of90and45for 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'. If not'full', the covariances are restricted to theirrank-dimensional principal subspace before computing the spatial filters, which are then projected back out to the full sensor space. This is useful for rank-deficient data, e.g., data with SSP projectors applied or that has been Maxwell filtered.New in v1.13.
- n_components
- Attributes:
- filters_
dictofndarray If fit, the Xdawn components used to decompose the data for each event type, else empty. For each event type, the filters are in the rows of the corresponding array (
n_channelsrows, orrankrows ifrankis not'full').- patterns_
dictofndarray If fit, the Xdawn patterns used to restore the signals for each event type, else empty.
- evokeds_
dictofEvoked If fit, the evoked response for each event type.
- event_id_
dict The event id.
- correct_overlap_bool
Whether overlap correction was applied.
- filters_
Methods
apply(inst[, event_id, include, exclude])Remove selected components from the signal.
fit(epochs[, y])Fit Xdawn from epochs.
fit_transform(X[, y])Fit to data, then transform it.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
Not implemented, see Xdawn.apply() instead.
save(fname, *[, overwrite, verbose])Save the object to disk (in HDF5 format).
set_fit_request(*[, epochs])Configure whether metadata should be requested to be passed to the
fitmethod.set_output(*[, transform])Set output container.
set_params(**params)Set the parameters of this estimator.
set_transform_request(*[, inst])Configure whether metadata should be requested to be passed to the
transformmethod.transform(inst)Apply Xdawn dim reduction.
See also
Notes
New in v0.10.
References
- apply(inst, event_id=None, include=None, exclude=None)[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:
- instinstance of
Raw|Epochs|Evoked The data to be processed.
- event_id
dict|listofstr|None The kind of event to apply. if None, a dict of inst will be return one for each type of event xdawn has been fitted.
- includearray_like of
int|None The indices referring to columns in the ummixing matrix. The components to be kept. If None, the first n_components (as defined in the Xdawn constructor) will be kept.
- excludearray_like of
int|None The indices referring to columns in the ummixing matrix. The components to be zeroed out. If None, all the components except the first n_components will be exclude.
- instinstance of
- Returns:
- out
dict A dict of instance (from the same type as inst input) for each event type in event_id.
- out
- 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_params
dict Additional fit parameters. Pass only if the estimator accepts additional params in its
fitmethod.
- Returns:
- get_metadata_routing()[source]#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routing
MetadataRequest A
MetadataRequestencapsulating routing information.
- routing
- save(fname, *, overwrite=False, verbose=None)[source]#
Save the object to disk (in HDF5 format).
- Parameters:
- fnamepath-like
The file path to save to. Should end with
'.h5'or'.hdf5'.- overwritebool
If True (default False), overwrite the destination file if it exists.
- verbosebool |
str|int|None Control verbosity of the logging output. If
None, use the default verbosity level. See the logging documentation andmne.verbose()for details. Should only be passed as a keyword argument.
Notes
New in v1.12.
- set_fit_request(*, epochs='$UNCHANGED$')[source]#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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 v1.3.
- set_output(*, transform=None)[source]#
Set output container.
Refer to the user guide for more details and Introducing the set_output API for an example on how to use the API.
- Parameters:
- transform{“default”, “pandas”, “polars”}, default=None
Configure output of
transformandfit_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:
- self
estimatorinstance Estimator instance.
- self
- 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.
- set_transform_request(*, inst='$UNCHANGED$')[source]#
Configure whether metadata should be requested to be passed to the
transformmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.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 v1.3.