moabb.pipelines.classification.SSVEP_CCA#
- class moabb.pipelines.classification.SSVEP_CCA(n_harmonics=3)[source]#
Classifier based on Canonical Correlation Analysis for SSVEP.
Canonical Correlation Analysis (CCA) is a multivariate statistical method used to find linear relationships between two sets of variables. For SSVEP detection, CCA finds spatial filters that maximize the correlation between multi-channel EEG signals and predefined sinusoidal reference signals at stimulation frequencies [1].
Mathematical Formulation
Given multi-channel EEG signal \mathbf{X} \in \mathbb{R}^{N_c \times N_s} and reference signal \mathbf{Y}_f \in \mathbb{R}^{2N_h \times N_s}, CCA finds weight vectors \mathbf{w}_x and \mathbf{w}_y that maximize the correlation between linear combinations x = \mathbf{X}^T \mathbf{w}_x and y = \mathbf{Y}_f^T \mathbf{w}_y:
\max_{\mathbf{w}_x, \mathbf{w}_y} \rho(x, y) = \frac{E[\mathbf{w}_x^T \mathbf{X} \mathbf{Y}_f^T \mathbf{w}_y]} {\sqrt{E[\mathbf{w}_x^T \mathbf{X} \mathbf{X}^T \mathbf{w}_x] E[\mathbf{w}_y^T \mathbf{Y}_f \mathbf{Y}_f^T \mathbf{w}_y]}}
Reference Signal Construction
The reference signals \mathbf{Y}_f for stimulus frequency f consist of sine and cosine pairs at the fundamental frequency and its harmonics:
\mathbf{Y}_f = \begin{bmatrix} \sin(2\pi f t) \\ \cos(2\pi f t) \\ \sin(2\pi \cdot 2f \cdot t) \\ \cos(2\pi \cdot 2f \cdot t) \\ \vdots \\ \sin(2\pi \cdot N_h \cdot f \cdot t) \\ \cos(2\pi \cdot N_h \cdot f \cdot t) \end{bmatrix}
where N_h is the number of harmonics and t is the time vector.
Classification Rule
For a test signal \mathbf{X}, the predicted class is the stimulus frequency that yields the maximum canonical correlation:
\hat{f} = \arg\max_{f \in \mathcal{F}} \rho_f
where \mathcal{F} is the set of stimulus frequencies and \rho_f is the canonical correlation between the test signal and reference \mathbf{Y}_f.
- Parameters:
n_harmonics (int, default=3) – Number of harmonics N_h to include in the reference signal. Higher values capture more harmonic components of the SSVEP response.
- classes_#
Encoded class labels (0 to n_classes-1).
- Type:
ndarray of shape (n_classes,)
- le_#
Fitted label encoder for frequency strings.
- Type:
LabelEncoder
- Yf#
Dictionary mapping frequency strings to reference signals \mathbf{Y}_f of shape
(2 * n_harmonics, n_times).- Type:
References
[1]Bin, G., Gao, X., Yan, Z., Hong, B., & Gao, S. (2009). An online multi-channel SSVEP-based brain-computer interface using a canonical correlation analysis method. Journal of neural engineering, 6(4), 046002. https://doi.org/10.1088/1741-2560/6/4/046002
Notes
Changed in version 1.1.0: Use MNE Epochs object as input data instead of numpy array, fix label encoding.
- fit(X, y, sample_weight=None)[source]#
Compute reference sinusoid signal.
These sinusoid are generated for each frequency in the dataset
- Parameters:
X (MNE Epochs) – The training data as MNE Epochs object.
y (Unused,) – Only for compatibility with scikit-learn
sample_weight (Unused,) – Only for compatibility with scikit-learn
- Returns:
self – Instance of classifier.
- Return type:
SSVEP_CCA object
- predict_proba(X)[source]#
Probability could be computed from the correlation coefficient.
- Parameters:
X (MNE Epochs) – The data to predict as MNE Epochs object.
- Returns:
proba – probability of each class for each trial.
- Return type:
ndarray of shape (n_trials, n_classes)
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SSVEP_CCA[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.Added in version 1.3.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SSVEP_CCA[source]#
Configure whether metadata should be requested to be passed to the
scoremethod.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 toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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.Added in version 1.3.