metabci.brainda.algorithms.decomposition.sceTRCA module

class metabci.brainda.algorithms.decomposition.sceTRCA.BasicFBTRCA(standard: bool | None = True, ensemble: bool | None = True, n_components: int | None = 1, n_bands: int = 1, ratio: float = 0.5)[source]

Bases: object

abstract fit(X_train: ndarray, y_train: ndarray, sine_template: ndarray)[source]

Load in training dataset and train model.

Parameters:
  • X_train (ndarray) – (Nb,Ne*Nt,…,Np). Training dataset.

  • y_train (ndarray) – (Ne*Nt,). Labels for X_train.

predict(X_test: ndarray)[source]

Calculating the prediction labels based on the decision coefficients.

Parameters:

X_test (ndarray) – (Nt*Nte,Nc,Np). Test dataset.

Returns:

(Nt*Nte,). Predict labels of sc-TRCA. y_ensemble (ndarray): (Nt*Nte,). Predict labels of sc-eTRCA.

Return type:

y_standard (ndarray)

transform(X_test: ndarray)[source]

Using filter-bank algorithms to calculate decision coefficients.

Parameters:

X_test (ndarray) – (Nb,Ne*Nte,Nc,Np). Test dataset.

Returns:

(Ne*Nte,Ne). Decision coefficients.

Not empty when self.standard is True.

erou (ndarray): (Ne*Nte,Ne). Decision coefficients (ensemble).

Not empty when self.ensemble is True.

Return type:

rou (ndarray)

class metabci.brainda.algorithms.decomposition.sceTRCA.BasicTRCA(standard: bool | None = True, ensemble: bool | None = True, n_components: int | None = 1, ratio: float = 0.5)[source]

Bases: object

abstract fit(X_train: ndarray, y_train: ndarray, sine_template: ndarray)[source]

Load in training dataset and train model.

Parameters:
  • X_train (ndarray) – (Ne*Nt,…,Np). Training dataset.

  • y_train (ndarray) – (Ne*Nt,). Labels for X_train.

abstract predict(X_test: ndarray)[source]

Predict test data.

Parameters:

X_test (ndarray) – (Ne*Nte,…,Np). Test dataset.

Returns:

(Ne*Nte,). Predict labels. y_ensemble (ndarray): (Ne*Nte,). Predict labels (ensemble).

Return type:

y_standard (ndarray)

abstract transform(X_test: ndarray)[source]

Calculating decision coefficients.

Parameters:

X_test (ndarray) – (Ne*Nte,…,Np). Test dataset.

Returns:

(Ne*Nte,Ne). Decision coefficients.

Not empty when self.standard is True.

erou (ndarray): (Ne*Nte,Ne). Decision coefficients (ensemble).

Not empty when self.ensemble is True.

Return type:

rou (ndarray)

class metabci.brainda.algorithms.decomposition.sceTRCA.FB_SC_TRCA(standard: bool | None = True, ensemble: bool | None = True, n_components: int | None = 1, n_bands: int = 1, ratio: float = 0.5)[source]

Bases: BasicFBTRCA

fit(X_train: ndarray, y_train: ndarray, sine_template: ndarray)[source]

Train filter-bank sc-(e)TRCA model.

Parameters:
  • X_train (ndarray) – (Nb,Ne*Nt,Nc,Np). Training dataset. Nt>=2.

  • y_train (ndarray) – (Ne*Nt,). Labels for X_train.

  • sine_template (ndarray) – (Ne,2*Nh,Np). Sinusoidal template.

class metabci.brainda.algorithms.decomposition.sceTRCA.SC_TRCA(standard: bool | None = True, ensemble: bool | None = True, n_components: int | None = 1, ratio: float = 0.5)[source]

Bases: BasicTRCA

fit(X_train: ndarray, y_train: ndarray, sine_template: ndarray)[source]

Train sc-(e)TRCA model.

Parameters:
  • X_train (ndarray) – (Ne*Nt,Nc,Np). Training dataset. Nt>=2.

  • y_train (ndarray) – (Ne*Nt,). Labels for X_train.

  • sine_template (ndarray) – (Ne,2*Nh,Np). Sinusoidal template.

predict(X_test: ndarray)[source]

Calculating the prediction labels based on the decision coefficients.

Parameters:

X_test (ndarray) – (Nt*Nte,Nc,Np). Test dataset.

Returns:

(Nt*Nte,). Predict labels of sc-TRCA. y_ensemble (ndarray): (Nt*Nte,). Predict labels of sc-eTRCA.

Return type:

y_standard (ndarray)

transform(X_test: ndarray)[source]

Using sc-(e)TRCA algorithm to compute decision coefficients.

Parameters:

X_test (ndarray) – (Nt*Nte,Nc,Np). Test dataset.

Returns:

(Nt*Nte,Ne). Decision coefficients of sc-TRCA.

Not empty when self.standard is True.

erou (ndarray): (Nt*Nte,Ne). Decision coefficients of sc-eTRCA.

Not empty when self.ensemble is True.

Return type:

rou (ndarray)

metabci.brainda.algorithms.decomposition.sceTRCA.combine_fb_feature(features: List[Any])[source]

Coefficient-level integration specially for filter-bank design.

Parameters:

features (List[Any]) – Coefficient matrices of different sub-bands.

Returns:

Integrated coefficients.

Return type:

coef (float)

metabci.brainda.algorithms.decomposition.sceTRCA.combine_feature(features: ~typing.List[~numpy.ndarray], func: ~typing.Any = <function sign_sta>)[source]

Coefficient-level integration.

Parameters:
  • features (List[float or int or ndarray]) – Different features.

  • func (function) – Quantization function.

Returns:

Integrated coefficients.

Return type:

coef (the same type with elements of features)

metabci.brainda.algorithms.decomposition.sceTRCA.pearson_corr(X: ndarray, Y: ndarray)[source]

Pearson correlation coefficient (1-D or 2-D).

Parameters:
  • X (ndarray) – (…, n_points)

  • Y (ndarray) – (…, n_points). The dimension must be same with X.

Returns:

corrcoef (float)

metabci.brainda.algorithms.decomposition.sceTRCA.pick_subspace(descend_order: List[Tuple[int, float]], e_val_sum: float, ratio: float)[source]

Config the number of subspaces.

Parameters:
  • descend_order (List[Tuple[int,float]]) – See it in solve_gep() or solve_ep().

  • e_val_sum (float) – Trace of covariance matrix.

  • ratio (float) – 0-1. The ratio of the sum of eigenvalues to the total.

Returns:

The number of subspaces.

Return type:

n_components (int)

metabci.brainda.algorithms.decomposition.sceTRCA.sctrca_compute(X_train: ndarray, y_train: ndarray, sine_template: ndarray, train_info: dict, n_components: int | None = 1, ratio: float = 0.5)[source]

(Ensemble) similarity-constrained TRCA (sc-(e)TRCA).

Parameters:
  • X_train (ndarray) – (Ne*Nt,Nc,Np). Training dataset. Nt>=2.

  • y_train (ndarray) – (Ne*Nt,). Labels for X_train.

  • sine_template (ndarray) – (Ne,2*Nh,Np). Sinusoidal template.

  • train_info (dict) – {‘event_type’:ndarray (Ne,), ‘n_events’:int, ‘n_train’:ndarray (Ne,), ‘n_chans’:int, ‘n_points’:int, ‘standard’:True, ‘ensemble’:True}

  • n_components (int) – Number of eigenvectors picked as filters. Set to ‘None’ if ratio is not ‘None’.

  • ratio (float) – 0-1. The ratio of the sum of eigenvalues to the total. Defaults to be ‘None’.

Return: sc-(e)TRCA model (dict).

Q (ndarray): (Ne,Nc,Nc). Covariance of original data & average template. S (ndarray): (Ne,Nc,Nc). Covariance of template. u (List[ndarray]): Ne*(Nk,Nc). Spatial filters for EEG signal. v (List[ndarray]): Ne*(Nk,2*Nh). Spatial filters for sinusoidal signal. u_concat (ndarray): (Ne*Nk,Nc). Concatenated filter for EEG signal. v_concat (ndarray): (Ne*Nk,2*Nh). Concatenated filter for sinusoidal signal. uX (List[ndarray]): Ne*(Nk,Np). sc-TRCA templates for EEG signal. vY (List[ndarray]): Ne*(Nk,Np). sc-TRCA templates for sinusoidal signal. euX (List[ndarray]): (Ne,Ne*Nk,Np). sc-eTRCA templates for EEG signal. evY (List[ndarray]): (Ne,Ne*Nk,Np). sc-eTRCA templates for sinusoidal signal.

metabci.brainda.algorithms.decomposition.sceTRCA.sign_sta(x: float)[source]

Standardization of decision coefficient based on sign(x).

Parameters:

x (float) –

Returns:

y=sign(x)*x^2

Return type:

y (float)

metabci.brainda.algorithms.decomposition.sceTRCA.solve_gep(A: ndarray, B: ndarray, n_components: int | None = None, ratio: float = 0.5, mode: str | None = 'Max')[source]
Solve generalized problems | generalized Rayleigh quotient:

f(w)=wAw^T/(wBw^T) -> Aw = lambda Bw -> B^{-1}Aw = lambda w

Parameters:
  • A (ndarray) – (m,m).

  • B (ndarray) – (m,m).

  • n_components (int) – Number of eigenvectors picked as filters. Eigenvectors are referring to eigenvalues sorted in descend order.

  • ratio (float) – 0-1. The ratio of the sum of eigenvalues to the total.

  • mode (str) – ‘Max’ or ‘Min’. Depends on target function.

Returns:

(Nk,m). Picked eigenvectors.

Return type:

w (ndarray)