metabci.brainda.algorithms.decomposition.csp module¶
Common Spatial Patterns and his happy little buddies!
- class metabci.brainda.algorithms.decomposition.csp.CSP(n_components: int | None = None, max_components: int | None = None)[source]¶
Bases:
BaseEstimator,TransformerMixincommon spatial pattern (CSP)
author: Swolf <swolfforever@gmail.com>
Created on:2021-1-07
- update log:
2023-11-06 by Yupeng Wang <zy_wyp@tju.edu.cn>
- Parameters:
n_component (int) – Spatial filter dimension
max_component (int) – The maximum dimension of the selected spatial filter does not exceed half of the number of leads
- n_component¶
Spatial filter dimension
- Type:
int
- max_component¶
The maximum dimension of the selected spatial filter does not exceed half of the number of leads
- Type:
int
- classes_¶
number of classes.
- Type:
ndarray
- W¶
Spatial filter
- Type:
ndarray, shape(n_channels, n_filters)
- D¶
Eigenvector of spatial filter
- Type:
ndarray, shape(n_filters )
- A¶
Spatial pattern
- Type:
ndarray, shape(n_channels, n_filters)
- best_n_components¶
If the number of spatial filters is not set, the optimal number of choices is calculated automatically.
- Type:
int
- class metabci.brainda.algorithms.decomposition.csp.FBCSP(n_components: int | None = None, max_components: int | None = None, n_mutualinfo_components: int | None = None, filterbank: List[ndarray] = [])[source]¶
Bases:
FilterBankFBCSP.
FilterBank CSP based on paper [1]_.
author: Swolf <swolfforever@gmail.com>
Created on:2021-1-07
- update log:
2023-11-06 by Yupeng Wang <zy_wyp@tju.edu.cn>
- Parameters:
n_component (int) – Spatial filter dimension
max_component (int) – The maximum dimension of the selected spatial filter does not exceed half of the number of leads
n_mutualinfo_components (int) – Multiple classification strategy, one to many.
filterbank (Optional, [List,[ndarray]]) – Spatial filter band division range.
- n_component¶
Spatial filter dimension
- Type:
int
- max_component¶
The maximum dimension of the selected spatial filter does not exceed half of the number of leads
- Type:
int
- n_mutualinfo_components¶
Multiple classification strategy, one to many.
- Type:
int
- filterbank¶
Spatial filter band division range.
- Type:
Optional, [List,[ndarray]]
- ajd_method¶
Covariance matrix joint diagonalization method
- Type:
str,’uwedge’
- classes_¶
number of classes.
- Type:
ndarray
- W¶
Spatial filter
- Type:
ndarray, shape(n_channels, n_filters)
- mutualinfo_values_¶
The selected mutual information feature vector has dimension k
- Type:
ndarray, shape(k,)
- A¶
Spatial pattern
- Type:
ndarray, shape(n_channels, n_filters)
- best_n_components¶
If the number of spatial filters is not set, the optimal number of choices is calculated automatically.
- Type:
int
- Raises:
ValueError – None
References
interface[C]//2008 IEEE International Joint Conference on Neural Networks (IEEE World Congress on Computational Intelligence). IEEE, 2008: 2390-2397.
- class metabci.brainda.algorithms.decomposition.csp.FBMultiCSP(n_components: int | None = None, max_components: int | None = None, multiclass: str = 'ovr', ajd_method: str = 'uwedge', n_mutualinfo_components: int | None = None, filterbank: List[ndarray] = [])[source]¶
Bases:
FilterBankFBMultiCSP.
The MultiCSP method based on filter banks is a decoding algorithm formed after adding filter banks and feature selection strategies to the MultiCSP algorithm.
author: Swolf <swolfforever@gmail.com>
Created on:2021-1-07
- update log:
2023-11-06 by Yupeng Wang <zy_wyp@tju.edu.cn>
- Parameters:
n_component (int) – Spatial filter dimension
max_component (int) – The maximum dimension of the selected spatial filter does not exceed half of the number of leads
n_mutualinfo_components (int) – Multiple classification strategy, one to many.
filterbank (Optional, [List,[ndarray]]) – Spatial filter band division range.
- n_component¶
Spatial filter dimension
- Type:
int
- max_component¶
The maximum dimension of the selected spatial filter does not exceed half of the number of leads
- Type:
int
- n_mutualinfo_components¶
Multiple classification strategy, one to many.
- Type:
int
- filterbank¶
Spatial filter band division range.
- Type:
Optional, [List,[ndarray]]
- ajd_method¶
Covariance matrix joint diagonalization method
- Type:
str,’uwedge’
- classes_¶
number of classes.
- Type:
ndarray
- W¶
Spatial filter
- Type:
ndarray, shape(n_channels, n_filters)
- mutualinfo_values_¶
The selected mutual information feature vector has dimension k
- Type:
ndarray, shape(k,)
- A¶
Spatial pattern
- Type:
ndarray, shape(n_channels, n_filters)
- best_n_components¶
If the number of spatial filters is not set, the optimal number of choices is calculated automatically.
- Type:
int
- Raises:
ValueError – None
References
[1] Ang K K, Chin Z Y, Zhang H, et al. Filter bank common spatial pattern (FBCSP) in brain-computer
interface[C]//2008 IEEE International Joint Conference on Neural Networks (IEEE World Congress on Computational Intelligence). IEEE, 2008: 2390-2397.
- class metabci.brainda.algorithms.decomposition.csp.MultiCSP(n_components: int | None = None, max_components: int | None = None, multiclass: str = 'ovr', ajd_method: str = 'uwedge')[source]¶
Bases:
BaseEstimator,TransformerMixinMulti common spatial pattern (MultiCSP) [1]_.
author: Swolf <swolfforever@gmail.com>
Created on:2021-1-07
- update log:
2023-11-06 by Yupeng Wang <zy_wyp@tju.edu.cn>
- Parameters:
n_component (int) – Spatial filter dimension
max_component (int) – The maximum dimension of the selected spatial filter does not exceed half of the number of leads
multiclass (int) – Multiple classification strategy, one to many.
- n_component¶
Spatial filter dimension
- Type:
int
- max_component¶
The maximum dimension of the selected spatial filter does not exceed half of the number of leads
- Type:
int
- multiclass¶
Multiple classification strategy, one to many.
- Type:
int
- ajd_method¶
Covariance matrix joint diagonalization method
- Type:
str,’uwedge’
- classes_¶
number of classes.
- Type:
ndarray
- W¶
Spatial filter
- Type:
ndarray, shape(n_channels, n_filters)
- mutualinfo_values_¶
The selected mutual information feature vector has dimension k
- Type:
ndarray, shape(k,)
- A¶
Spatial pattern
- Type:
ndarray, shape(n_channels, n_filters)
- best_n_components¶
If the number of spatial filters is not set, the optimal number of choices is calculated automatically.
- Type:
int
- Raises:
ValueError – None
References
[1] Grosse-Wentrup, Moritz, and Martin Buss. “Multiclass common spatial patterns and information theoretic
feature extraction. “ Biomedical Engineering, IEEE Transactions on 55, no. 8 (2008): 1991-2000.
- class metabci.brainda.algorithms.decomposition.csp.SPoC(n_components: int | None = None, max_components: int | None = None)[source]¶
Bases:
BaseEstimator,TransformerMixinSource Power Comodulation (SPoC).
For continuous data, not verified.
- metabci.brainda.algorithms.decomposition.csp.ajd(X: ndarray, method: str = 'uwedge') Tuple[ndarray, ndarray][source]¶
Wrapper of AJD methods.
- Parameters:
X (ndarray) – Input covariance matrices, shape (n_trials, n_channels, n_channels)
method (str, optional) – AJD method (default uwedge).
- Returns:
V (ndarray) – The diagonalizer, shape (n_channels, n_filters), usually n_filters == n_channels.
D (ndarray) – The mean of quasi diagonal matrices, shape (n_channels,).
- metabci.brainda.algorithms.decomposition.csp.csp_feature(W: ndarray, X: ndarray, n_components: int = 2) ndarray[source]¶
Return CSP features in paper [1]_.
- Parameters:
W (ndarray) – spatial filters from csp_kernel, shape (n_channels, n_filters)
X (ndarray) – eeg data, shape (n_trials, n_channels, n_samples)
n_components (int, optional) – the first k components to use, usually even number, by default 2
- Returns:
features of shape (n_trials, n_features)
- Return type:
ndarray
- Raises:
ValueError – n_components should less than the number of channels
References
[1] Ramoser H, Muller-Gerking J, Pfurtscheller G. Optimal spatial filtering of single trial EEG during imagined hand movement[J]. IEEE transactions on rehabilitation engineering, 2000, 8(4): 441-446.
- metabci.brainda.algorithms.decomposition.csp.csp_kernel(X: ndarray, y: ndarray) Tuple[ndarray, ndarray, ndarray][source]¶
The kernel in CSP algorithm based on paper [1]_.
- Parameters:
X (ndarray) – eeg data, shape (n_trials, n_channels, n_samples).
y (ndarray) – labels of X, shape (n_trials,).
- Returns:
W (ndarray) – Spatial filters, shape (n_channels, n_filters).
D (ndarray) – Eigenvalues of spatial filters, shape (n_filters,).
A (ndarray) – Spatial patterns, shape (n_channels, n_patterns).
References
[1] Ramoser H, Muller-Gerking J, Pfurtscheller G. Optimal spatial filtering of single trial EEG during imagined hand movement[J]. IEEE transactions on rehabilitation engineering, 2000, 8(4): 441-446.
- metabci.brainda.algorithms.decomposition.csp.gw_csp_kernel(X: ndarray, y: ndarray, ajd_method: str = 'uwedge') Tuple[ndarray, ndarray, ndarray, ndarray][source]¶
Grosse-Wentrup AJD method based on paper [1]_.
- Parameters:
X (ndarray) – eeg data, shape (n_trials, n_channels, n_samples).
y (ndarray) – labels, shape (n_trials).
ajd_method (str, optional) – ajd methods, ‘uwedge’ ‘rjd’ and ‘ajd_pham’, by default ‘uwedge’.
- Returns:
W (ndarray) – Spatial filters, shape (n_channels, n_filters).
D (ndarray) – Eigenvalues of spatial filters, shape (n_filters,).
A (ndarray) – Spatial patterns, shape (n_channels, n_patterns).
mutual_info (ndarray) – Mutual informaiton values, shape (n_filters).
References
[1] Grosse-Wentrup, Moritz, and Martin Buss. “Multiclass common spatial patterns and information theoretic feature extraction.” Biomedical Engineering, IEEE Transactions on 55, no. 8 (2008): 1991-2000.
- metabci.brainda.algorithms.decomposition.csp.spoc_kernel(X: ndarray, y: ndarray) Tuple[ndarray, ndarray, ndarray][source]¶
Source Power Comodulation (SPoC) based on paper [1]_.
It is a continous CSP-like method.
- Parameters:
X (ndarray) – eeg data, shape (n_trials, n_channels, n_samples)
y (ndarray) – labels, shape (n_trials)
- Returns:
W (ndarray) – Spatial filters, shape (n_channels, n_filters).
D (ndarray) – Eigenvalues of spatial filters, shape (n_filters,).
A (ndarray) – Spatial patterns, shape (n_channels, n_patterns).
References
[1] Sven Dähne, Frank C. Meinecke, Stefan Haufe, Johannes Höhne, Michael Tangermann, Klaus-Robert Müller, and Vadim V. Nikulin. SPoC: a novel framework for relating the amplitude of neuronal oscillations to behaviorally relevant parameters. NeuroImage, 86:111–122, 2014. doi:10.1016/j.neuroimage.2013.07.079.