metabci.brainda.algorithms.decomposition.cca module

class metabci.brainda.algorithms.decomposition.cca.ECCA(n_components: int = 1, n_jobs: int | None = None)[source]

Bases: BaseEstimator, TransformerMixin, ClassifierMixin

The Extended Canonical Correlation Analysis (eCCA) method combines the advantages of sCCA and itCCA while applying the individual averaging templates and the positive cosine reference signal correlation information, thus obtaining better recognition performance[1]_.

Parameters:
  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

Yf_

Reference signals.

Type:

ndarray

Us_

Spatial filter.

Type:

ndarray

Vs_

Spatial filter.

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,).

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples).

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') ECCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

transform(X: ndarray)[source]

Transform X into features and calculate the correlation coefficients of the signals from different trials

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

rhos – The correlation coefficients, shape(n_trials, n_fre)

Return type:

ndarray

class metabci.brainda.algorithms.decomposition.cca.FBECCA(filterbank: List[ndarray], n_components: int = 1, filterweights: ndarray | None = None, n_jobs: int | None = None)[source]

Bases: FilterBankSSVEP, ClassifierMixin

Filter bank eCCA method, i.e., an eCCA method that combines the application of multiple filters in order to decompose the SSVEP signal into specific subbands [1]_.

Parameters:
  • filterbank (list[ndarray]) – Filter bank list

  • filterweights (ndarray) – Weights of filter bank

  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

References

Tip

A example using FBECCA
 1import sys
 2import numpy as np
 3from brainda.algorithms.decomposition import FBECCA
 4from brainda.algorithms.decomposition.base import generate_filterbank, generate_cca_references
 5wp=[(5,90),(14,90),(22,90),(30,90),(38,90)]
 6ws=[(3,92),(12,92),(20,92),(28,92),(36,92)]
 7filterbank = generate_filterbank(wp,ws,srate=250,order=15,rp=0.5)
 8filterweights = [(idx_filter+1) ** (-1.25) + 0.25 for idx_filter in range(5)]
 9estimator = FBECCA(filterbank=filterbank,n_components=1,filterweights=np.array(filterweights),n_jobs=-1)
10accs = []
11for k in range(kfold):
12     train_ind, validate_ind, test_ind = match_kfold_indices(k, meta, indices)
13     train_ind = np.concatenate((train_ind, validate_ind))
14     p_labels = estimator.fit(X=X[train_ind],y=y[train_ind], Yf=Yf).predict(X[test_ind])
15     accs.append(np.mean(p_labels==y[test_ind]))
16print(np.mean(accs))
fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') FBECCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

class metabci.brainda.algorithms.decomposition.cca.FBItCCA(filterbank: List[ndarray], n_components: int = 1, method: str = 'itcca2', filterweights: ndarray | None = None, n_jobs: int | None = None)[source]

Bases: FilterBankSSVEP, ClassifierMixin

The filter bank ItCCA method, i.e., the ItCCA method that combines the application of multiple filters in order to decompose the SSVEP signal into specific subbands[1]_.

Parameters:
  • filterbank (list[ndarray]) – Filter bank list

  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • filterweights (ndarray) – Filter weights, defaults to None.

  • n_jobs (int) – The number of CPU working cores, default is None.

  • method (str) – Two pattern feature extraction and fitting classifier model methods judgment, defaulting to ‘itcca2’.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') FBItCCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

class metabci.brainda.algorithms.decomposition.cca.FBMsCCA(filterbank: List[ndarray], n_components: int = 1, filterweights: ndarray | None = None, n_jobs: int | None = None)[source]

Bases: FilterBankSSVEP, ClassifierMixin

The filter bank MsetCCA method, i.e., the MsetCCA method that combines the application of multiple filters in order to decompose the SSVEP signal into specific subbands[1]_.

Parameters:
  • filterbank (list[ndarray]) – Filter bank list.

  • filterweights (ndarray) – Weights of filter banks

  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • method (str) – Two pattern feature extraction and fitting classifier model methods judgment, defaulting to ‘itcca2’.

  • n_jobs (int) – The number of CPU working cores, default is None.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') FBMsCCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

class metabci.brainda.algorithms.decomposition.cca.FBMsetCCA(filterbank: List[ndarray], n_components: int = 1, method: str = 'msetcca2', filterweights: ndarray | None = None, n_jobs: int | None = None)[source]

Bases: FilterBankSSVEP, ClassifierMixin

The filter bank MsetCCA method, i.e., the MsetCCA method that combines the application of multiple filters in order to decompose the SSVEP signal into specific subbands[1]_.

Parameters:
  • filterbank (list[ndarray]) – Filter bank list.

  • filterweights (ndarray) – Weights of filter banks.

  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

  • methods (str) – Two Pattern Feature Extraction and Fitting Classifier Model Methods Judgment, defaulting to ‘msetcca2’.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,).

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples).

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') FBMsetCCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

class metabci.brainda.algorithms.decomposition.cca.FBMsetCCAR(filterbank: List[ndarray], n_components: int = 1, filterweights: ndarray | None = None, n_jobs: int | None = None)[source]

Bases: FilterBankSSVEP, ClassifierMixin

fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') FBMsetCCAR

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

class metabci.brainda.algorithms.decomposition.cca.FBSCCA(filterbank: List[ndarray], n_components: int = 1, filterweights: ndarray | None = None, n_jobs: int | None = None)[source]

Bases: FilterBankSSVEP, ClassifierMixin

Filter bank SCCA methods, i.e., SCCA methods that combine the application of multiple filters in order to decompose the SSVEP signal into specific subbands[1]_ .This class is a FBSCCA classifier.

Parameters:
  • filterbank (list[ndarray]) – Filter bank list

  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • filterweights (ndarray) – Filter weights, defaults to None.

  • n_jobs (int) – The number of CPU working cores, default is None.

References

Tip

A example using FBSCCA
 1import sys
 2import numpy as np
 3from brainda.algorithms.decomposition import FBSCCA
 4from brainda.algorithms.decomposition.base import generate_filterbank, generate_cca_references
 5wp=[(5,90),(14,90),(22,90),(30,90),(38,90)]
 6ws=[(3,92),(12,92),(20,92),(28,92),(36,92)]
 7filterbank = generate_filterbank(wp,ws,srate=250,order=15,rp=0.5)
 8filterweights = [(idx_filter+1) ** (-1.25) + 0.25 for idx_filter in range(5)]
 9estimator = FBSCCA(filterbank=filterbank,n_components=1,filterweights=np.array(filterweights),n_jobs=-1)
10accs = []
11for k in range(kfold):
12    train_ind, validate_ind, test_ind = match_kfold_indices(k, meta, indices)
13    # merge train and validate set
14    train_ind = np.concatenate((train_ind, validate_ind))
15    p_labels = estimator.fit(X=X[train_ind],y=y[train_ind], Yf=Yf).predict(X[test_ind])
16    accs.append(np.mean(p_labels==y[test_ind]))
17    print(np.mean(accs))
predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

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

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

class metabci.brainda.algorithms.decomposition.cca.FBTRCA(filterbank: List[ndarray], n_components: int = 1, ensemble: bool = True, filterweights: ndarray | None = None, n_jobs: int | None = None)[source]

Bases: FilterBankSSVEP, ClassifierMixin

Filter bank TRCA (filter bank Task-Related Component Analysis, fbTRCA) adds the filter bank analysis method to TRCA by combining the fundamental and harmonic components of the signal. The EEG signal is first filtered using multiple subband filters with different cutoff frequencies to obtain the subband filtered signal. Subsequently, the correlation coefficients of the subband signals are summed according to a weighting function, and finally this weighted correlation coefficient sum is used as the feature discriminant [1]_.

Parameters:
  • filterbank (list[ndarray]) – Filter bank list

  • filterweights (ndarray) – Filter weights, defaults to None.

  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

  • ensemble (bool) – Whether to perform spatial filter ensemble for each category of signals, the default is True to perform ensemble.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

templates_

Individual average template

Type:

ndarray

Us_

Spatial filters obtained for each class of training signals.

Type:

ndarray

References

Tip

A example using FBTRCA
 1 import numpy as np
 2 from brainda.algorithms.decomposition import FBTRCA
 3 X = np.zeros((4,22,22))
 4 for i in range(4):
 5     X[i,...] = np.identity(22)*0.5 + np.random.normal(-1,3,(22,22))*2
 6 y = np.array([1,1,2,2])
 7 filterbank = [np.ones((3,6))]
 8 filterweights = np.array([[0.3, -0.1], [0.5, -0.1]])
 9 estimator = FBTRCA(filterbank=filterbank,n_components=1, ensemble=True,filterweights=np.array(filterweights),n_jobs=-1)
10 p_labels = estimator.fit(X, y)
11 print(estimator.predict(np.identity(22)))
fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal, shape(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') FBTRCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

class metabci.brainda.algorithms.decomposition.cca.FBTRCAR(filterbank: List[ndarray], n_components: int = 1, ensemble: bool = True, filterweights: ndarray | None = None, n_jobs: int | None = None)[source]

Bases: FilterBankSSVEP, ClassifierMixin

The filter bank TRCA-R algorithm (filter bank TRCA-R, fbTRCA-R) adds a filter bank analysis method to the TRCA-R algorithm, combining the fundamental and harmonic components of the signal. Multiple subband filters with different cutoff frequencies are utilized to filter the EEG signal to obtain the subband filtered signal. Subsequently, the correlation coefficients of the subband signals are summed according to a weighting function, and finally this weighted correlation coefficient sum is used as the feature discriminant[1]_.

Parameters:
  • filterbank (list[ndarray]) – Filter bank list

  • filterweights (ndarray) – Filter weights, defaults to None.

  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

ensemble

Whether to perform spatial filter ensemble for each category of signals, the default is True to perform ensemble.

Type:

bool

templates_

Individual average template

Type:

ndarray

Us_

Spatial filters obtained for each class of training signals.

Type:

ndarray

Yf

Reference signal(n_classes, 2*n_harmonics, n_samples)

Type:

ndarray

References

Tip

A example using FBTRCAR
 1 import numpy as np
 2 from brainda.algorithms.decomposition import FBTRCAR
 3 X = np.zeros((4,22,22))
 4 for i in range(4):
 5 X[i,...] = np.identity(22)*0.3 + np.random.normal(-1,3,(22,22))*5
 6 y = np.array([1,1,2,2])
 7 Yf = X
 8 filterbank = [np.ones((3,6))]
 9 filterweights = np.array([[0.3, -0.1], [0.5, -0.1]])
10 estimator = FBTRCAR(filterbank=filterbank,n_components=1,ensemble=True,filterweights=np.array(filterweights),n_jobs=-1)
11 p_labels = estimator.fit(X, y, Yf)
12 print(estimator.predict(np.identity(22)))
fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') FBTRCAR

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

class metabci.brainda.algorithms.decomposition.cca.FBTtCCA(filterbank: List[ndarray], n_components: int = 1, filterweights: ndarray | None = None, n_jobs: int | None = None)[source]

Bases: FilterBankSSVEP, ClassifierMixin

Filter bank TtCCA method, i.e., a TtCCA method that combines the application of multiple filters in order to decompose the SSVEP signal into specific subbands[1]_.

Parameters:
  • filterbank (list[ndarray]) – Filter bank list

  • filterweights (ndarray) – Weights of filter banks

  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray | None = None, y_sub: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,).

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples).

  • y_sub (ndarray) – Existing source subject data.

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$', y_sub: bool | None | str = '$UNCHANGED$') FBTtCCA

Request metadata passed to the fit 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 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.

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:
  • Yf (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for Yf parameter in fit.

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

Returns:

self – The updated object.

Return type:

object

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

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

class metabci.brainda.algorithms.decomposition.cca.ItCCA(n_components: int = 1, method: str = 'itcca2', n_jobs: int | None = None)[source]

Bases: BaseEstimator, TransformerMixin, ClassifierMixin

The Individual Template-based Canonical Correlation Analysis (It-CCA) method is an extension of the CCA method in which the reference signal is a VEP template obtained by averaging multiple EEG trials from each individual’s calibration data, and the individual SSVEP training data is used in the CCA method to improve the frequency detection of SSVEP [1]_.This class is a itCCA classifier

Parameters:
  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • method (str) – Two pattern feature extraction and fitting classifier model methods judgment, defaulting to ‘itcca2’.

  • n_jobs (int) – The number of CPU working cores, default is None.

Yf_

Reference signal.

Type:

ndarray

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

templates_

Test data after spatial filtering

Type:

ndarray

Us_

Spatial filter

Type:

ndarray

Vs_

Spatial filter

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') ItCCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

transform(X: ndarray)[source]

Transform the X into features and calculate the correlation coefficients of different trials

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

rhos – Correlation coefficients, shape(n_trials, n_fre).

Return type:

ndarray

class metabci.brainda.algorithms.decomposition.cca.MsCCA(n_components: int = 1, n_jobs: int | None = None)[source]

Bases: BaseEstimator, TransformerMixin, ClassifierMixin

Since the sine-cosine signal may not be the ideal reference signal, the Multiset Canonical Correlation Analysis (MsetCCA) method uses joint spatial filtering of multiple sets of data to create an optimized reference signal that extracts common SSVEP features from multiple sets of EEG data recorded at the same stimulus frequency[1]_. Note: MsCCA heavily depends on Yf, thus the phase information should be included when designs Yf.

Parameters:
  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • method (str) – Two pattern feature extraction and fitting classifier model methods judgment, defaulting to ‘itcca2’.

  • n_jobs (int) – The number of CPU working cores, default is None.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

Yf_

Reference signals

Type:

ndarray

Us_

Spatial filter

Type:

ndarray

Ts_

Spatial filter

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') MsCCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

transform(X: ndarray)[source]

Transform X into features and calculate the correlation coefficients of the signals from different trials.

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

rhos – The correlation coefficients, shape(n_trials, n_fre).

Return type:

ndarray

class metabci.brainda.algorithms.decomposition.cca.MsetCCA(n_components: int = 1, method: str = 'msetcca2', n_jobs: int | None = None)[source]

Bases: BaseEstimator, TransformerMixin, ClassifierMixin

Since the sine-cosine signal may not be the ideal reference signal, the Multiset Canonical Correlation Analysis (MsetCCA) method uses joint spatial filtering of multiple sets of data to create an optimized reference signal that extracts common SSVEP features from multiple sets of EEG data recorded at the same stimulus frequency[1]_.

Parameters:
  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

  • methods (str) – Two Pattern Feature Extraction and Fitting Classifier Model Methods Judgment, defaulting to ‘msetcca2’.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

templates_

Template signals

Type:

ndarray

Yf_

Reference signals

Type:

ndarray

Us_

Spatial filter

Type:

ndarray

Ts_

Spatial filter

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') MsetCCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

transform(X: ndarray)[source]

Transform X into features and calculate the correlation coefficients of the signals from different trials.

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

rhos – The correlation coefficients, shape(n_trials, n_fre)

Return type:

ndarray

class metabci.brainda.algorithms.decomposition.cca.MsetCCAR(n_components: int = 1, n_jobs: int | None = 1)[source]

Bases: BaseEstimator, TransformerMixin, ClassifierMixin

fit(X: ndarray, y: ndarray, Yf: ndarray)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') MsetCCAR

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

transform(X: ndarray)[source]

Transform X into features and calculate the correlation coefficients of the signals from different trials

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

rhos – The correlation coefficients, shape(n_trials, n_fre)

Return type:

ndarray

class metabci.brainda.algorithms.decomposition.cca.SCCA(n_components: int = 1, n_jobs: int | None = None)[source]

Bases: BaseEstimator, TransformerMixin, ClassifierMixin

Standard CCA (sCCA).The Canonical Correlation Analysis (CCA) method finds the coefficients of the linear combination between the test signal and the Fourier series reference signal for a given frequency-periodic signal to find the maximum correlation between the two sets of signals. To identify the frequency of the SSVEP, CCA calculates the typical correlation between the multichannel SSVEP and the reference signal corresponding to each stimulus frequency, and the frequency of the reference signal with the largest correlation is regarded as the frequency of the SSVEP[1]_[2]_.SCCA is the standard CCA method.

Parameters:
  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

Yf_

The reference signal provided, defaults to None.

Type:

ndarray

Raises:

ValueError – None

References

Tip

A example using SCCA
 from metabci.brainda.algorithms.decomposition.cca import SCCA
 estimator = SCCA()
 p_labels = estimator.fit(X=X[train_ind],y=y[train_ind], Yf=Yf).predict(X[test_ind])
fit(X: ndarray | None = None, y: ndarray | None = None, Yf: ndarray | None = None)[source]

model training

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Label, shape(n_trials,)

  • Yf (ndarray) – Sine and cosine reference signal, shape(n_classes, 2*n_harmonics, n_samples).

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') SCCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

transform(X: ndarray)[source]

The correlation coefficients of the signals from different trials were obtained by converting X into features.

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

rhos – he correlation coefficients, shape(n_trials, n_fre)

Return type:

ndarray

class metabci.brainda.algorithms.decomposition.cca.TRCA(n_components: int = 1, ensemble: bool = True, n_jobs: int | None = None)[source]

Bases: BaseEstimator, TransformerMixin, ClassifierMixin

The core idea of Task-Related Component Analysis (TRCA) algorithm is to extract task-related components by improving the repeatability between trials, specifically, the algorithm is based on inter-trial covariance matrix maximization to achieve the extraction of task-related components, which belongs to the supervised learning method[1]_.

Parameters:
  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • ensemble (bool) – Whether to perform spatial filter ensemble for each category of signals, the default is True to perform ensemble.

  • n_jobs (int) – The number of CPU working cores, default is None.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

templates_

Individual average template

Type:

ndarray

Us_

Spatial filters obtained for each class of training signals.

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') TRCA

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

transform(X: ndarray)[source]

Transform X into features and calculate the correlation coefficients of the signals from different trials

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

rhos – The correlation coefficients, shape(n_trials, n_fre)

Return type:

ndarray

class metabci.brainda.algorithms.decomposition.cca.TRCAR(n_components: int = 1, ensemble: bool = True, n_jobs: int | None = None)[source]

Bases: BaseEstimator, TransformerMixin, ClassifierMixin

The task-related component analysis algorithm with sine-cosine reference signal (TRCA with sine-cosine reference signal, TRCA-R) is based on the TRCA algorithm, and the main improvement point is to add the step of orthogonal projection of the signal to the subspace of sine-cosine template during the training process, which further extracts the components of the EEG signal that are more correlated with the sine-cosine fluctuations of SSVEP[1]_.

Parameters:
  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

  • ensemble (bool) – Whether to perform spatial filter ensemble for each category of signals, the default is True to perform ensemble.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

templates_

Individual average template.

Type:

ndarray

Yf_

Sine-Cosine reference signal.

Type:

ndarray

Us_

Spatial filters obtained for each class of training signals.

Type:

ndarray

References

Tip

A example using TRCAR
1 import numpy as np
2 from brainda.algorithms.decomposition import TRCAR
3 X = np.array([[[0, -1],[2, -1]], [[2, -1],[0, 1]], [[1, -1],[3, 2]],[[-1, 2],[1, 0]]])
4 y = np.array([1, 1, 2, 2])
5 Yf = np.array([[[0, -0.5],[1, -1]], [[0.2, -1],[0, 1]]])
6 estimator = TRCAR(n_components=1, ensemble=True, n_jobs=-1)
7 p_labels = estimator.fit(X, y, Yf)
8 print(estimator.predict(np.array([[[0, -1.2],[0.5, -1]]])))
fit(X: ndarray, y: ndarray, Yf: ndarray)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$') TRCAR

Request metadata passed to the fit 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 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.

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:

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

Returns:

self – The updated object.

Return type:

object

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

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

transform(X: ndarray)[source]

Transform X into features and calculate the correlation coefficients of the signals from different trials

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

rhos – The correlation coefficients, shape(n_trials, n_fre)

Return type:

ndarray

class metabci.brainda.algorithms.decomposition.cca.TtCCA(n_components: int = 1, n_jobs: int | None = None)[source]

Bases: BaseEstimator, TransformerMixin, ClassifierMixin

The Transfer Template-based Canonical Correlation Analysis (tt-CCA) method migrates SSVEP templates from existing subjects to new subjects to enhance SSVEP detection. EEG templates were generated for the new subjects using the existing source subject dataset, i.e., migrating EEG templates to capture the frequency and phase information of SSVEP[1]_.

Parameters:
  • n_components (int) – The number of feature dimensions after dimensionality reduction, the dimension of the spatial filter, defaults to 1.

  • n_jobs (int) – The number of CPU working cores, default is None.

classes_

Predictive labels, obtained from labeled data by removing duplicate elements from it.

Type:

ndarray

templates_

Individual average template signals.

Type:

ndarray

Yf_

Reference signals.

Type:

ndarray

Us_

Spatial filter.

Type:

ndarray

Vs_

Spatial filter.

Type:

ndarray

References

fit(X: ndarray, y: ndarray, Yf: ndarray, y_sub: ndarray | None = None)[source]

model train

Parameters:
  • X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

  • y (ndarray) – Labels, shape(n_trials,)

  • Yf (ndarray) – Reference signal(n_classes, 2*n_harmonics, n_samples)

  • y_sub (ndarray) – Existing source subject data

predict(X: ndarray)[source]

Predict the labels

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

labels – Predicting labels, shape(n_trials,).

Return type:

ndarray

set_fit_request(*, Yf: bool | None | str = '$UNCHANGED$', y_sub: bool | None | str = '$UNCHANGED$') TtCCA

Request metadata passed to the fit 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 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.

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:
  • Yf (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for Yf parameter in fit.

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

Returns:

self – The updated object.

Return type:

object

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

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

transform(X: ndarray)[source]

Transform X into features and calculate the correlation coefficients of the signals from different trials

Parameters:

X (ndarray) – EEG data, shape(n_trials, n_channels, n_samples).

Returns:

rhos – The correlation coefficients, shape(n_trials, n_fre)

Return type:

ndarray