metabci.brainda.algorithms.transfer_learning.same module

source aliasing matrix estimation (SAME) and its multi-stimulus version (msSAME).

A data augmentation method named Source Aliasing Matrix Estimation (SAME) [1] to enhance the performance of state-of-the-art spatial filtering methods (i.e., eTRCA, TDCA) for SSVEP-BCIs. Based on the superposition model of SSVEPs, the task-related components are reconstructed by estimating the source aliasing matrixes. After adding noise, multiple artificial signals are generated and then added to calibrated data in an appropriate proportion.

In 2023, paper [2] proposes an extended version of SAME, called multi-stimulus SAME (msSAME), which exploits the similarity of the aliasing matrix across frequencies to enhance the performance of SSVEP-BCI with insufficient calibration trials.

souce code of SAME: https://github.com/RuixinLuo/Source-Aliasing-Matrix-Estimation-DataAugmentation-SAME-SSVEP

class metabci.brainda.algorithms.transfer_learning.same.MSSAME(n_jobs=None, fs=250, flist=None, plist=None, Nh=5, n_Aug=5, n_Neig=12, alpha=0.05)[source]

Bases: BaseEstimator, TransformerMixin

multi-stimulus source aliasing matrix estimation (msSAME) [1]_.

author: Ruixin Luo <ruixin_luo@tju.edu.cn>

Created on: 2023-11-13

update log:

Parameters:
  • fs (int) – Sampling rate.

  • flist (list) – Frequency of all class.

  • plist (list) – Phase of all class.

  • Nh (int) – The number of harmonics.

  • n_Aug (int) – The number of generated signals

  • n_Neig (int) – The number of neighborhood frequency

  • alpha (float) – Intensity of noise, default 0.05.

T_

Average template for different classes of data.

Type:

list

classes_

number of classes.

Type:

ndarray

Raises:

ValueError – None

References

Tip

A example using MSSAME
1 from metabci.brainda.algorithms.transfer_learning import MSSAME
2 mssame = MSSAME(fs = 250, Nh = 5, flist = freq_list, plist=phase_list, n_Aug=4, n_Neig=14)
3 mssame.fit(X_train , y_train)
4 X_aug, y_aug = mssame.augment()
5 X_train_new = np.concatenate((X_train, X_aug), axis=0)
6 y_train_new = np.concatenate((y_train, y_aug), axis=0)
augment()[source]

Calculating augmentation signals.

Returns:

  • X_aug (ndarray) – augmentation data, shape(n_events*n_aug, n_channels, n_samples).

  • y_aug (ndarray) – Label of augmentation data, shape(n_events*n_aug,).

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

model training

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

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

class metabci.brainda.algorithms.transfer_learning.same.SAME(n_jobs=None, fs=250, flist=None, Nh=5, n_Aug=5, alpha=0.05)[source]

Bases: BaseEstimator, TransformerMixin

source aliasing matrix estimation (SAME) [1]_.

author: Ruixin Luo <ruixin_luo@tju.edu.cn>

Created on: 2023-01-09

update log:

2023-09-06 by Ruixin Luo <ruixin_luo@tju.edu.cn>

2023-10-03 by Jie Mei <chmeijie@tju.edu.cn>

Parameters:
  • fs (int) – Sampling rate.

  • flist (list) – Frequency of all class.

  • Nh (int) – The number of harmonics.

  • n_Aug (int) – The number of generated signals

  • alpha (float) – Intensity of noise, default 0.05.

T_

Average template for different classes of data.

Type:

list

classes_

number of classes.

Type:

ndarray

Raises:

ValueError – None

References

Tip

A example using SAME
1 from metabci.brainda.algorithms.transfer_learning import SAME
2 same = SAME(fs = 250, Nh = 5, flist = freq_list, n_Aug = 4)
3 same.fit(X_train , y_train)
4 X_aug, y_aug = same.augment()
5 X_train_new = np.concatenate((X_train, X_aug), axis=0)
6 y_train_new = np.concatenate((y_train, y_aug), axis=0)
augment()[source]

Calculating augmentation signals.

Returns:

  • X_aug (ndarray) – augmentation data, shape(n_events*n_aug, n_channels, n_samples).

  • y_aug (ndarray) – Label of augmentation data, shape(n_events*n_aug,).

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

model training

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

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

metabci.brainda.algorithms.transfer_learning.same.TRCs_estimation(data, mean_target)[source]

source signal estimation using LST [1]_

author: Ruixin Luo <ruixin_luo@tju.edu.cn>

Created on: 2023-01-09

update log:

2023-09-06 by Ruixin Luo <ruixin_luo@tju.edu.cn>

Parameters:
  • data (ndarray) – Reference signal, shape(n_channel_1, n_times).

  • mean_target (ndarray) – Average template, shape(n_channel_2, n_times).

Returns:

data_after – Source signal, shape(n_channel_2, n_times).

Return type:

ndarray

References

metabci.brainda.algorithms.transfer_learning.same.get_augment_noiseAfter(fs, f, Nh, n_Aug, mean_temp, alpha=0.05)[source]

Artificially generated signals by SAME

author: Ruixin Luo <ruixin_luo@tju.edu.cn>

Created on: 2023-01-09

update log:

2023-09-06 by Ruixin Luo <ruixin_luo@tju.edu.cn>

Parameters:
  • fs (int) – Sampling rate.

  • f (float) – Frequency of signal.

  • Nh (int) – The number of harmonics.

  • n_Aug (int) – The number of generated signals.

  • mean_temp (ndarray) – Average template, shape(n_channels, n_times).

  • alpha (float) – Intensity of noise, default 0.05.

Returns:

data_aug – Artificially generated signals, shape(n_channel, n_times, n_Aug).

Return type:

ndarray

Note

Please note that we apply SAME before filter bank analysis in the MetaBCI version. This is convenient for compatibility with MetaBCI and saves computational effort. After testing, it still has a similar improvement effect.

metabci.brainda.algorithms.transfer_learning.same.get_augment_noiseAfter_ms(fs, f_list, phi_list, Nh, n_Aug, mean_temp_all, iEvent, n_Templates, alpha=0.05)[source]

Artificially generated signals by msSAME

author: Ruixin Luo <ruixin_luo@tju.edu.cn>

Created on: 2023-11-09

update log:

Parameters:
  • fs (int) – Sampling rate.

  • f_list (list) – The all frequency of reference signal.

  • phi_list (list) – The all phase of reference signal

  • Nh (int) – The number of harmonics.

  • n_Aug (int) – The number of generated signals

  • mean_temp_all (ndarray-like (n_channel, n_times, n_events)) – Average template of all events.

  • iEvent (int) – the i-th event for the selection of neighboring frequencies

  • n_Templates (int) – The number of neighboring frequencies

  • alpha (float) – Intensity of noise, default 0.05.

Returns:

data_aug – Artificially generated signals.

Return type:

ndarray-like (n_channel, n_times, n_Aug)

Note

Please note that we apply msSAME before filter bank analysis in the MetaBCI version. This is convenient for compatibility with MetaBCI and saves computational effort. After testing, it still has a similar improvement effect.