moabb.pipelines.classification.SSVEP_TRCA#

class moabb.pipelines.classification.SSVEP_TRCA(interval, freqs, downsample=1, is_ensemble=True, method='original', estimator='scm')[source]#

Classifier based on the Task-Related Component Analysis method [1]_ for SSVEP.

Parameters:
  • sfreq (float) – Sampling frequency of the data to be analyzed.

  • freqs (dict with n_classes keys) – Frequencies corresponding to the SSVEP components. These are necessary to design the filterbank bands.

  • downsample (int, default=1) – Factor by which downsample the data. A downsample value of N will result on a sampling frequency of (sfreq // N) by taking one sample every N of the original data. In the original TRCA paper [1]_ data are at 250Hz.

  • is_ensemble (bool, default=False) – If True, predict on new data using the Ensemble-TRCA method described in [1]_.

  • method (str, default='original') – ‘original’ computes euclidean mean for S as in the original paper [1]_. ‘riemann’ variation computes geodesic mean instead. This geodesic mean is more robust to outlier but negatively impacted by ill-conditioned matrices (when only few samples are available for training for instance). If the geometric mean can’t be estimated, please consider trying ‘logeuclid’. It computes log-euclidean mean instead of the affine-invariant one and is more robust computationally. ‘riemann’ and ‘logeuclid’ variations are useful when lots of noisy training data are available. With few training data ‘original’ is more appropriate.

  • estimator (str) – For both methods, regularization to use for covariance matrices estimations. Consider ‘schaefer’, ‘lwf’, ‘oas’ or ‘scm’ for no regularization. In the original implementation from TRCA paper [1]_, no regularization is used. So method=’original’ and regul=’scm’ is similar to original implementation.

fb_coefs#

Alpha coefficients for the fusion of the filterbank sub-bands.

Type:

list of len (n_fbands)

classes_#

Array with the class labels extracted at fit time.

Type:

ndarray of shape (n_classes,)

n_classes#

Number of unique labels/classes.

Type:

int

templates_#

Template data obtained by averaging all training trials for a given class. Each class templates is divided in n_fbands sub-bands extracted from the filterbank approach.

Type:

ndarray of shape (n_classes, n_bands, n_channels, n_samples)

weights_#

Weight coefficients for the different electrodes which are used as spatial filters for the data.

Type:

ndarray of shape (n_fbands, n_classes, n_channels)

Reference#
----------
.. [1] M. Nakanishi, Y. Wang, X. Chen, Y. -T. Wang, X. Gao, and T.-P. Jung,

“Enhancing detection of SSVEPs for a high-speed brain speller using task-related component analysis”, IEEE Trans. Biomed. Eng, 65(1):104-112, 2018.

Code based on the Matlab implementation from authors of [1]_
(https
Type:

//github.com/mnakanishi/TRCA-SSVEP).

Notes

New in version 0.4.4.

fit(X, y)[source]#

Extract spatial filters and templates from the given calibration data.

Parameters:
  • X (ndarray of shape (n_trials, n_channels, n_samples)) – Training data. Trials are grouped by class, divided in n_fbands bands by the filterbank approach and then used to calculate weight vectors and templates for each class and band.

  • y (ndarray of shape (n_trials,)) – Label vector in respect to X.

Returns:

self – Instance of classifier.

Return type:

CCA object

predict(X)[source]#

Make predictions on unseen data.

The new data observation X will be filtered with weights previously extracted and compared to the templates to assess similarity with each of them and select a class based on the maximal value.

Parameters:

X (ndarray of shape (n_trials, n_channels, n_samples)) – Testing data. This will be divided in self.n_fbands using the filter- bank approach, then it will be transformed by the different spatial filters and compared to the previously fit templates according to the selected method for analysis (ensemble or not). Finally, correlation scores for all sub-bands of each class will be combined, resulting on a single correlation score per class, from which the maximal one is identified as the predicted class of the data.

Returns:

y_pred – Prediction vector in respect to X.

Return type:

ndarray of shape (n_trials,)

predict_proba(X)[source]#

Make predictions on unseen data with the associated probabilities.

The new data observation X will be filtered with weights previously extracted and compared to the templates to assess similarity with each of them and select a class based on the maximal value.

Parameters:

X (ndarray of shape (n_trials, n_channels, n_samples)) – Testing data. This will be divided in self.n_fbands using the filter-bank approach, then it will be transformed by the different spatial filters and compared to the previously fit templates according to the selected method for analysis (ensemble or not). Finally, correlation scores for all sub-bands of each class will be combined, resulting on a single correlation score per class, from which the maximal one is identified as the predicted class of the data.

Returns:

y_pred – Prediction vector in respect to X.

Return type:

ndarray of shape (n_trials,)

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

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see 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.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

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