Conduct Classification-based EEG Decoding¶
neurora.decoding module¶
a module for classification-based neural decoding
- neurora.decoding.bidirectional_transfer_decoding(data1, labels1, data2, labels2, n=2, navg=5, time_opt='average', time_win=5, time_step=5, iter=10, normalization=False, pca=True, pca_components=0.95, smooth=True)¶
Conduct bidirectional transfer decoding for EEG-like data
- Parameters
data1 (array) – The neural data under condition1. The shape of data must be [n_subs, n_trials, n_chls, n_ts]. n_subs, n_trials, n_chls and n_ts represent the number of subjects, the number of trails, the number of channels and the number of time-points.
labels1 (array) – The labels of each trials under condition1. The shape of labels must be [n_subs, n_trials]. n_subs and n_trials represent the number of subjects and the number of trials.
data2 (array) – The neural data under condition2.
labels2 (array) – The labels of each trials under condition2.
n (int. Default is 2.) – The number of categories for classification.
navg (int. Default is 5.) – The number of trials used to average.
time_opt (string "average" or "features". Default is "average".) – Average the time-points or regard the time points as features for classification If time_opt=”average”, the time-points in a certain time-window will be averaged. If time_opt=”features”, the time-points in a certain time-window will be used as features for classification.
time_win (int. Default is 5.) – Set a time-window for decoding for different time-points. If time_win=5, that means each decoding process based on 5 time-points.
time_step (int. Default is 5.) – The time step size for each time of decoding.
iter (int. Default is 10.) – The times for iteration.
normalization (boolean True or False. Default is False.) – Normalize the data or not.
pca (boolean True or False. Default is True.) – Apply principal component analysis (PCA).
pca_components (int or float. Default is 0.95.) – Number of components for PCA to keep. If 0<pca_components<1, select the numbder of components such that the amount of variance that needs to be explained is greater than the percentage specified by pca_components.
smooth (boolean True or False, or int. Default is True.) – Smooth the decoding result or not. If smooth = True, the default smoothing step is 5. If smooth = n (type of n: int), the smoothing step is n.
- Returns
Con1toCon2_accuracies (array) – The 1 transfer to 2 decoding accuracies. The shape of accuracies is [n_subs, int((n_ts1-time_win)/time_step)+1, int((n_ts2-time_win)/time_step)+1].
Con2toCon1_accuracies (array) – The 2 transfer to 1 decoding accuracies. The shape of accuracies is [n_subs, int((n_ts2-time_win)/time_step)+1, int((n_ts1-time_win)/time_step)+1].
- neurora.decoding.ct_decoding_holdout(data, labels, n=2, navg=5, time_opt='average', time_win=5, time_step=5, iter=10, test_size=0.3, normalization=False, pca=True, pca_components=0.95, smooth=True)¶
Conduct cross-temporal decoding for EEG-like data (hold-out)
- Parameters
data (array) – The neural data. The shape of data must be [n_subs, n_trials, n_chls, n_ts]. n_subs, n_trials, n_chls and n_ts represent the number of subjects, the number of trails, the number of channels and the number of time-points.
labels (array) – The labels of each trial. The shape of labels must be [n_subs, n_trials]. n_subs and n_trials represent the number of subjects and the number of trials.
n (int. Default is 2.) – The number of categories for classification.
navg (int. Default is 5.) – The number of trials used to average.
time_opt (string "average" or "features". Default is "average".) – Average the time-points or regard the time points as features for classification If time_opt=”average”, the time-points in a certain time-window will be averaged. If time_opt=”features”, the time-points in a certain time-window will be used as features for classification.
time_win (int. Default is 5.) – Set a time-window for decoding for different time-points. If time_win=5, that means each decoding process based on 5 time-points.
time_step (int. Default is 5.) – The time step size for each time of decoding.
iter (int. Default is 10.) – The times for iteration.
test_size (float. Default is 0.3.) – The proportion of the test set. test_size should be between 0.0 and 1.0.
normalization (boolean True or False. Default is False.) – Normalize the data or not.
pca (boolean True or False. Default is True.) – Apply principal component analysis (PCA).
pca_components (int or float. Default is 0.95.) – Number of components for PCA to keep. If 0<pca_components<1, select the numbder of components such that the amount of variance that needs to be explained is greater than the percentage specified by pca_components.
smooth (boolean True or False, or int. Default is True.) – Smooth the decoding result or not. If smooth = True, the default smoothing step is 5. If smooth = n (type of n: int), the smoothing step is n.
- Returns
accuracies – The cross-temporal decoding accuracies. The shape of accuracies is [n_subs, int((n_ts-time_win)/time_step)+1, int((n_ts-time_win)/time_step)+1].
- Return type
array
- neurora.decoding.ct_decoding_kfold(data, labels, n=2, navg=5, time_opt='average', time_win=5, time_step=5, nfolds=5, nrepeats=2, normalization=False, pca=True, pca_components=0.95, smooth=True)¶
Conduct cross-temporal decoding for EEG-like data (cross validation)
- Parameters
data (array) – The neural data. The shape of data must be [n_subs, n_trials, n_chls, n_ts]. n_subs, n_trials, n_chls and n_ts represent the number of subjects, the number of trails, the number of channels and the number of time-points.
labels (array) – The labels of each trial. The shape of labels must be [n_subs, n_trials]. n_subs and n_trials represent the number of subjects and the number of trials.
n (int. Default is 2.) – The number of categories for classification.
navg (int. Default is 5.) – The number of trials used to average.
time_opt (string "average" or "features". Default is "average".) – Average the time-points or regard the time points as features for classification If time_opt=”average”, the time-points in a certain time-window will be averaged. If time_opt=”features”, the time-points in a certain time-window will be used as features for classification.
time_win (int. Default is 5.) – Set a time-window for decoding for different time-points. If time_win=5, that means each decoding process based on 5 time-points.
time_step (int. Default is 5.) – The time step size for each time of decoding.
nfolds (int. Default is 5.) – The number of folds. nfolds should be at least 2.
nrepeats (int. Default is 2.) – The times for iteration.
normalization (boolean True or False. Default is False.) – Normalize the data or not.
pca (boolean True or False. Default is True.) – Apply principal component analysis (PCA).
pca_components (int or float. Default is 0.95.) – Number of components for PCA to keep. If 0<pca_components<1, select the numbder of components such that the amount of variance that needs to be explained is greater than the percentage specified by pca_components.
smooth (boolean True or False, or int. Default is True.) – Smooth the decoding result or not. If smooth = True, the default smoothing step is 5. If smooth = n (type of n: int), the smoothing step is n.
- Returns
accuracies – The cross-temporal decoding accuracies. The shape of accuracies is [n_subs, int((n_ts-time_win)/time_step)+1, int((n_ts-time_win)/time_step)+1].
- Return type
array
- neurora.decoding.tbyt_decoding_holdout(data, labels, n=2, navg=5, time_opt='average', time_win=5, time_step=5, iter=10, test_size=0.3, normalization=False, pca=True, pca_components=0.95, smooth=True)¶
Conduct time-by-time decoding for EEG-like data (hold out)
- Parameters
data (array) – The neural data. The shape of data must be [n_subs, n_trials, n_chls, n_ts]. n_subs, n_trials, n_chls and n_ts represent the number of subjects, the number of trails, the number of channels and the number of time-points.
labels (array) – The labels of each trial. The shape of labels must be [n_subs, n_trials]. n_subs and n_trials represent the number of subjects and the number of trials.
n (int. Default is 2.) – The number of categories for classification.
navg (int. Default is 5.) – The number of trials used to average.
time_opt (string "average" or "features". Default is "average".) – Average the time-points or regard the time points as features for classification If time_opt=”average”, the time-points in a certain time-window will be averaged. If time_opt=”features”, the time-points in a certain time-window will be used as features for classification.
time_win (int. Default is 5.) – Set a time-window for decoding for different time-points. If time_win=5, that means each decoding process based on 5 time-points.
time_step (int. Default is 5.) – The time step size for each time of decoding.
iter (int. Default is 10.) – The times for iteration.
test_size (float. Default is 0.3.) – The proportion of the test set. test_size should be between 0.0 and 1.0.
normalization (boolean True or False. Default is False.) – Normalize the data or not.
pca (boolean True or False. Default is True.) – Apply principal component analysis (PCA).
pca_components (int or float. Default is 0.95.) – Number of components for PCA to keep. If 0<pca_components<1, select the numbder of components such that the amount of variance that needs to be explained is greater than the percentage specified by pca_components.
smooth (boolean True or False, or int. Default is True.) – Smooth the decoding result or not. If smooth = True, the default smoothing step is 5. If smooth = n (type of n: int), the smoothing step is n.
- Returns
accuracies – The time-by-time decoding accuracies. The shape of accuracies is [n_subs, int((n_ts-time_win)/time_step)+1].
- Return type
array
- neurora.decoding.tbyt_decoding_kfold(data, labels, n=2, navg=5, time_opt='average', time_win=5, time_step=5, nfolds=5, nrepeats=2, normalization=False, pca=True, pca_components=0.95, smooth=True)¶
Conduct time-by-time decoding for EEG-like data (cross validation)
- Parameters
data (array) – The neural data. The shape of data must be [n_subs, n_trials, n_chls, n_ts]. n_subs, n_trials, n_chls and n_ts represent the number of subjects, the number of trails, the number of channels and the number of time-points.
labels (array) – The labels of each trial. The shape of labels must be [n_subs, n_trials]. n_subs and n_trials represent the number of subjects and the number of trials.
n (int. Default is 2.) – The number of categories for classification.
navg (int. Default is 5.) – The number of trials used to average.
time_opt (string "average" or "features". Default is "average".) – Average the time-points or regard the time points as features for classification If time_opt=”average”, the time-points in a certain time-window will be averaged. If time_opt=”features”, the time-points in a certain time-window will be used as features for classification.
time_win (int. Default is 5.) – Set a time-window for decoding for different time-points. If time_win=5, that means each decoding process based on 5 time-points.
time_step (int. Default is 5.) – The time step size for each time of decoding.
nfolds (int. Default is 5.) – The number of folds. k should be at least 2.
nrepeats (int. Default is 2.) – The times for iteration.
normalization (boolean True or False. Default is False.) – Normalize the data or not.
pca (boolean True or False. Default is True.) – Apply principal component analysis (PCA).
pca_components (int or float. Default is 0.95.) – Number of components for PCA to keep. If 0<pca_components<1, select the numbder of components such that the amount of variance that needs to be explained is greater than the percentage specified by pca_components.
smooth (boolean True or False, or int. Default is True.) – Smooth the decoding result or not. If smooth = True, the default smoothing step is 5. If smooth = n (type of n: int), the smoothing step is n.
- Returns
accuracies – The time-by-time decoding accuracies. The shape of accuracies is [n_subs, int((n_ts-time_win)/time_step)+1].
- Return type
array
- neurora.decoding.unidirectional_transfer_decoding(data1, labels1, data2, labels2, n=2, navg=5, time_opt='average', time_win=5, time_step=5, iter=10, normalization=False, pca=True, pca_components=0.95, smooth=True)¶
Conduct unidirectional transfer decoding for EEG-like data
- Parameters
data1 (array) – The neural data under condition1. The shape of data must be [n_subs, n_trials, n_chls, n_ts]. n_subs, n_trials, n_chls and n_ts represent the number of subjects, the number of trails, the number of channels and the number of time-points.
labels1 (array) – The labels of each trial under condition1. The shape of labels must be [n_subs, n_trials]. n_subs and n_trials represent the number of subjects and the number of trials.
data2 (array) – The neural data under condition2.
labels2 (array) – The labels of each trial under condition2.
n (int. Default is 2.) – The number of categories for classification.
navg (int. Default is 5.) – The number of trials used to average.
time_opt (string "average" or "features". Default is "average".) – Average the time-points or regard the time points as features for classification If time_opt=”average”, the time-points in a certain time-window will be averaged. If time_opt=”features”, the time-points in a certain time-window will be used as features for classification.
time_win (int. Default is 5.) – Set a time-window for decoding for different time-points. If time_win=5, that means each decoding process based on 5 time-points.
time_step (int. Default is 5.) – The time step size for each time of decoding.
iter (int. Default is 10.) – The times for iteration.
normalization (boolean True or False. Default is False.) – Normalize the data or not.
pca (boolean True or False. Default is True.) – Apply principal component analysis (PCA).
pca_components (int or float. Default is 0.95.) – Number of components for PCA to keep. If 0<pca_components<1, select the numbder of components such that the amount of variance that needs to be explained is greater than the percentage specified by pca_components.
smooth (boolean True or False, or int. Default is True.) – Smooth the decoding result or not. If smooth = True, the default smoothing step is 5. If smooth = n (type of n: int), the smoothing step is n.
- Returns
accuracies – The unidirectional transfer decoding accuracies. The shape of accuracies is [n_subs, int((n_ts1-time_win)/time_step)+1, int((n_ts2-time_win)/time_step)+1].
- Return type
array