pyntbci.classifiers.eTRCA

class pyntbci.classifiers.eTRCA(lags: None | ndarray[Any, dtype[_ScalarType_co]], fs: int, cycle_size: float | None = None, template_metric: str = 'mean', score_metric: str = 'correlation', latency: ndarray[Any, dtype[_ScalarType_co]] | None = None, ensemble: bool = False, n_components: int = 1, squeeze_components: bool = True)[source]

ERP TRCA classifier. It computes ERPs as templates for full sequences and performs a TRCA for spatial filtering [2].

Parameters:
  • lags (None | NDArray) – A vector of latencies in seconds per class relative to the first stimulus if stimuli are circularly shifted versions of the first stimulus, or None if all stimuli are different or this circular shift feature should be ignored.

  • fs (int) – The sampling frequency of the EEG data in Hz.

  • cycle_size (float (default: None)) – The time that one cycle of the code takes in seconds. If None, takes the full data length.

  • template_metric (str (default: "mean")) – Metric to use to compute templates: mean, median, OCSVM.

  • score_metric (str (default: "correlation")) – Metric to use to compute the overlap of templates and single-trials during testing: correlation, Euclidean, inner.

  • latency (NDArray (default: None)) – The raster latencies of each of the classes of shape (n_classes,) that the data/templates need to be corrected for.

  • ensemble (bool (default: False)) – Whether to use an ensemble classifier, that is, a separate spatial filter for each class.

  • n_components (int (default: 1)) – The number of CCA components to use.

  • squeeze_components (bool (default: True)) – Remove the component dimension when n_components=1.

trca_

The TRCA used to fit the spatial. If ensemble=False, len(trca_)=1, otherwise len(trca_)=n_classes.

Type:

list[TransformerMixin]

w_

The weight vector representing a spatial filter of shape (n_channels, n_components). If ensemble=True, then the shape is (n_channels, n_components, n_classes).

Type:

NDArray

T_

The template matrix representing the expected responses of shape (n_classes, n_samples, n_components).

Type:

NDArray

References

decision_function(X: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

Apply the classifier to get classification scores for X.

Parameters:

X (NDArray) – The matrix of EEG data of shape (n_trials, n_channels, n_samples).

Returns:

scores – The similarity scores of shape (n_trials, n_classes, n_components).

Return type:

NDArray

fit(X: ndarray[Any, dtype[_ScalarType_co]], y: ndarray[Any, dtype[_ScalarType_co]]) ClassifierMixin[source]

The training procedure to fit eTRCA on supervised EEG data.

Parameters:
  • X (NDArray) – The matrix of EEG data of shape (n_trials, n_channels, n_samples).

  • y (NDArray) – The vector of ground-truth labels of the trials in X of shape (n_trials), i.e., the index of the attended code.

Returns:

self – Returns the instance itself.

Return type:

ClassifierMixin

get_T(n_samples: int | None = None) ndarray[Any, dtype[_ScalarType_co]][source]

Get the templates.

Parameters:

n_samples (int (default: None)) – The number of samples requested. If None, one code cycle is given.

Returns:

T – The templates of shape (n_classes, n_samples).

Return type:

NDArray

predict(X: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

The testing procedure to apply eTRCA to novel EEG data.

Parameters:

X (NDArray) – The matrix of EEG data of shape (n_trials, n_channels, n_samples).

Returns:

y – The predicted labels of shape (n_trials, n_components).

Return type:

NDArray

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') eTRCA

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.

Added 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