pyriemann.spatialfilters.CSP¶
- class pyriemann.spatialfilters.CSP(nfilter=4, metric='euclid', log=True, ajd_method='ajd_pham')¶
CSP spatial filtering with covariance matrices as inputs.
Implementation of the famous Common Spatial Pattern algorithm [1] [2], but with covariance matrices as input. In addition, the implementation allows different metric for the estimation of the class-related mean covariance matrices, as described in [3].
This implementation support multiclass CSP by means of approximate joint diagonalization. In this case, the spatial filter selection is achieved according to [4].
- Parameters:
- nfilterint, default=4
The number of components to decompose M/EEG signals.
- metricstr, default=”euclid”
Metric used for the estimation of mean covariance matrices. For the list of supported metrics, see
pyriemann.utils.mean.mean_covariance()
.- logbool, default=True
If true, return the log variance, otherwise return the spatially filtered covariance matrices.
- ajd_methodstring | callable, default=”ajd_pham”
Method for AJD, can be: “ajd_pham”, “rjd”, “uwedge”, or a callable function.
Added in version 0.7.
- Attributes:
- filters_ndarray, shape (min(n_channels, n_filters), n_channels)
If fit, the CSP spatial filters.
- patterns_ndarray, shape (min(n_channels, n_filters), n_channels)
If fit, the CSP spatial patterns.
See also
MDM
SPoC
References
[1]Spatial Patterns Underlying Population Differences in the Background EEG Z. Koles, M. Lazar, and S. Zhou. Brain Topography 2(4), 275-284, 1990.
[2]Optimizing Spatial Filters for Robust EEG Single-Trial Analysis B. Blankertz, R. Tomioka, S. Lemm, M. Kawanabe, K-R. Muller. IEEE Signal Processing Magazine 25(1), 41-56, 2008.
[3]Common Spatial Pattern revisited by Riemannian geometry A. Barachant, S. Bonnet, M. Congedo and C. Jutten. IEEE International Workshop on Multimedia Signal Processing (MMSP), p. 472-476, 2010.
[4]Multiclass common spatial patterns and information theoretic feature extraction IEEE Transactions on Biomedical Engineering, Volume 55, Issue 8, August 2008. pp. 1991 - 2000
- __init__(nfilter=4, metric='euclid', log=True, ajd_method='ajd_pham')¶
Init.
- fit(X, y)¶
Train CSP spatial filters.
- Parameters:
- Xndarray, shape (n_trials, n_channels, n_channels)
Set of covariance matrices.
- yndarray, shape (n_trials,)
Labels for each trial.
- Returns:
- selfCSP instance
The CSP 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.
- set_output(*, transform=None)¶
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
Added in version 1.4: “polars” option was added.
- 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 spatial filters.
- Parameters:
- Xndarray, shape (n_trials, n_channels, n_channels)
Set of covariance matrices.
- Returns:
- Xfndarray, shape (n_trials, n_filters) or ndarray, shape (n_trials, n_filters, n_filters)
Set of spatialy filtered log-variance or covariance, depending on the log input parameter.
Examples using pyriemann.spatialfilters.CSP
¶
Ensemble learning on functional connectivity