moabb.pipelines.classification.SSVEP_eCCA#

class moabb.pipelines.classification.SSVEP_eCCA(n_harmonics=3, freq_map=None)[source]#

Extended CCA (eCCA) for SSVEP detection [1].

Extended CCA combines standard CCA with individual template CCA through a multi-feature fusion approach. It computes four correlation features that capture complementary information from both sinusoidal references and data-driven templates.

Mathematical Formulation

For each test signal \(\mathbf{X}\) and stimulus class \(n\), four correlation features are computed:

\[\begin{split}r_1 &= \rho(\text{CCA}(\mathbf{X}, \mathbf{Y}_n)) \\ r_2 &= \rho(\text{CCA}(\mathbf{X}, \bar{\mathbf{X}}_n)) \\ r_3 &= \rho(\mathbf{X}^T \hat{\mathbf{w}}_{xn}, \bar{\mathbf{X}}_n^T \hat{\mathbf{w}}_{xn}) \\ r_4 &= \rho(\mathbf{X}^T \tilde{\mathbf{w}}_{xn}, \bar{\mathbf{X}}_n^T \tilde{\mathbf{w}}_{xn})\end{split}\]

where:

  • \(\mathbf{Y}_n\) is the sinusoidal reference for frequency \(f_n\)

  • \(\bar{\mathbf{X}}_n\) is the averaged individual template

  • \(\hat{\mathbf{w}}_{xn}\) is the spatial filter from \(\text{CCA}(\mathbf{X}, \mathbf{Y}_n)\)

  • \(\tilde{\mathbf{w}}_{xn}\) is the spatial filter from \(\text{CCA}(\bar{\mathbf{X}}_n, \mathbf{Y}_n)\)

Classification Rule

Features are fused using signed squared correlation:

\[\rho_n = \sum_{l=1}^{4} \text{sign}(r_l) \cdot r_l^2\]

The predicted class is: \(\hat{f} = \arg\max_n \rho_n\)

Parameters:
  • n_harmonics (int, default=3) – Number of harmonics for sinusoidal reference signal generation.

  • freq_map (dict | None, default=None) – Optional explicit mapping {class_label: stimulus_frequency_hz}. If None, frequencies are inferred from X.event_id and event codes.

classes_#

Class labels in the same label space as y.

Type:

ndarray of shape (n_classes,)

freqs_#

Stimulus frequencies from training data.

Type:

list of str

one_hot_#

Mapping from class labels to class indices.

Type:

dict

le_#

Fitted label encoder.

Type:

LabelEncoder

slen_#

Signal length in seconds.

Type:

float

templates_#

Averaged individual templates per frequency.

Type:

dict

Yf#

Sinusoidal reference signals per frequency.

Type:

dict

w_template_#

Spatial filters from CCA(template, sinusoidal reference).

Type:

dict

References

[1]

Chen, X., Wang, Y., Gao, S., Jung, T.-P., & Gao, X. (2015). Filter bank canonical correlation analysis for implementing a high-speed SSVEP-based brain-computer interface. PLOS ONE, 10(12), e0140703. https://doi.org/10.1371/journal.pone.0140703

Notes

Added in version 1.2.0.

fit(X, y, sample_weight=None)[source]#

Compute individual templates, sinusoidal references, and spatial filters.

Parameters:
  • X (MNE Epochs) – Training data as MNE Epochs object.

  • y (ndarray of shape (n_trials,)) – Label vector with frequency strings for each trial.

  • sample_weight (Unused) – Only for compatibility with scikit-learn.

Returns:

self – Fitted instance.

Return type:

SSVEP_eCCA

predict(X)[source]#

Predict class labels using 4-feature fusion.

Parameters:

X (MNE Epochs) – Test data as MNE Epochs object.

Returns:

y – Predicted labels.

Return type:

list of int

predict_proba(X)[source]#

Predict class probabilities from fused correlation features.

Parameters:

X (MNE Epochs) – Test data as MNE Epochs object.

Returns:

P – 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_eCCA[source]#

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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.

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SSVEP_eCCA[source]#

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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.

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self – The updated object.

Return type:

object