Implementations based on eigen decomposition¶
Standard CCA and filterbank CCA¶
Related papers:
Standard CCA: Z. Lin et al., “Frequency recognition based on canonical correlation analysis for SSVEP-based BCIs,” IEEE Trans. Biomed. Eng., vol. 53, no. 12, pp. 2610-2614, 2006. DOI: 10.1109/TBME.2006.886577.
Filterbank CCA: X. Chen et al., “Filter bank canonical correlation analysis for implementing a high-speed SSVEP-based brain-computer interface,” J. Neural Eng., vol. 12, no. 4, p. 046008, 2015. DOI: 10.1088/1741-2560/12/4/046008.
In this toolbox, the standard CCA (sCCA) are regarded as a special case of the filterbank CCA (FBCCA) that only have one filterbank. Spatial filters are found to maximize the similarity between the EEG signals and the sine-cosine-based reference signals, which can be presented as
where \(\mathbf{X}\) denotes the testing multi-channel EEG signal, \(\mathbf{Y}_i\) denotes the sine-cosine-based reference signal of the \(i\text{-th}\) stimulus, \(\mathbf{U}_i\) is the spatial filter of the \(i\text{-th}\) stimulus, and \(\mathbf{V}_i\) is the harmonic weights of the reference signal for the \(i\text{-th}\) stimulus.
The stimulus with the highest similarity is regarded as the target:
where \(I\) denotes the total number of stimuli.
- SSVEPAnalysisToolbox.algorithms.SCCA_canoncorr()¶
FBCCA implemented directly following above equations.
- Parameters
n_component – Number of components of eigen vectors that will be applied as the spatial filters. The default number is
1, which means the eigen vector with the highest eigen value is regarded as the spatial filter.n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.force_output_UV – If
True, \(\left\{\mathbf{U}_i,\mathbf{V}_i\right\}_{i=1,2,\cdots,I}\) will be stored. Otherwise, they will not be stored. Default isFalse.update_UV – If
True, \(\left\{\mathbf{U}_i,\mathbf{V}_i\right\}_{i=1,2,\cdots,I}\) will be re-computed in following testing trials. Otherwise, they will not be re-computed if they are already existed. Default isTrue.
- SSVEPAnalysisToolbox.algorithms.SCCA_qr()¶
FBCCA implemented by the QR decomposition. This implementation is almost same as the “SCCA_canoncorr” model. The only difference is that this implementation does not repeatedly compute the QR decomposition of reference signals, which can improve the computational efficiency.
- Parameters
n_component – Number of components of eigen vectors that will be applied as the spatial filters. The default number is
1, which means the eigen vector with the highest eigen value is regarded as the spatial filter.n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.force_output_UV – If
True, \(\left\{\mathbf{U}_i,\mathbf{V}_i\right\}_{i=1,2,\cdots,I}\) will be stored. Otherwise, they will not be stored. Default isFalse.update_UV – If
True, \(\left\{\mathbf{U}_i,\mathbf{V}_i\right\}_{i=1,2,\cdots,I}\) will be re-computed in following testing trials. Otherwise, they will not be re-computed if they are already existed. Default isTrue.
Note
Although the FBCCA is a training-free method, these models still need run “fit” function to store reference signals in the model.
Individual template CCA (itCCA) and extended CCA (eCCA)¶
Related paper:
Chen, Y. Wang, M. Nakanishi, X. Gao, T.-P. Jung, and S. Gao, “High-speed spelling with a noninvasive brain-computer interface,” Proc. Natl. Acad. Sci., vol. 112, no. 44, pp. E6058-E6067, 2015. DOI: 10.1073/pnas.1508080112.
The itCCA is similar as the sCCA, but it uses the averaged template signals to compute the spatial filters. The corresponding correlation coefficient is
where \(\overline{\mathbf{X}}_i\) denotes the averaged template signal of the \(i\text{-th}\) stimulus.
The eCCA not only applies the sine-cosine-based reference signals but also uses the averaged template signals. Three types of spatial filters are computed:
Four types of corresponding correlation coefficients can be computed:
The target stimulus is predicted by combining four correlation coefficients together:
where \(\text{sign}\left\{\cdot\right\}\) is the signum function.
- SSVEPAnalysisToolbox.algorithms.ITCCA()¶
itCCA. The implementation is similar as the “SCCA_qr” model.
- Parameters
n_component – Number of components of eigen vectors that will be applied as the spatial filters. The default number is
1, which means the eigen vector with the highest eigen value is regarded as the spatial filter.n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.force_output_UV – If
True, \(\left\{\mathbf{U}_i,\mathbf{V}_i\right\}_{i=1,2,\cdots,I}\) will be stored. Otherwise, they will not be stored. Default isFalse.update_UV – If
True, \(\left\{\mathbf{U}_i,\mathbf{V}_i\right\}_{i=1,2,\cdots,I}\) will be re-computed in following testing trials. Otherwise, they will not be re-computed if they are already existed. Default isTrue.
- SSVEPAnalysisToolbox.algorithms.ECCA()¶
eCCA. The implementation is similar as the “SCCA_qr” model.
- Parameters
n_component – Number of components of eigen vectors that will be applied as the spatial filters. The default number is
1, which means the eigen vector with the highest eigen value is regarded as the spatial filter.n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.update_UV – If
True, \(\left\{\mathbf{U}_i,\mathbf{V}_i\right\}_{i=1,2,\cdots,I}\) will be re-computed in following training and testing trials. Otherwise, they will not be re-computed if they are already existed. Default isTrue.
Multi-stimulus CCA¶
Related paper:
Wong, F. Wan, B. Wang, Z. Wang, W. Nan, K. F. Lao, P. U. Mak, M. I. Vai, and A. Rosa, “Learning across multi-stimulus enhances target recognition methods in SSVEP-based BCIs,” J. Neural Eng., vol. 17, no. 1, p. 016026, 2020. DOI: 10.1088/1741-2552/ab2373.
The multi-stimulus CCA (ms-CCA) considers reference signals and template signals of target stimulus and stimuli with stimulus frequencies are close to that of target stimulus, which includes the phase information and thus improve the recognition accuracy. The spatial filters are computed by
where \(\mathbf{A}_i\) is the concatenated template signal defined as \(\mathbf{A}_i = \left[\overline{\mathbf{X}}_{i-m},\cdots,\overline{\mathbf{X}}_{i},\cdots,\overline{\mathbf{X}}_{i+n}\right]\), and \(\mathbf{B}_i\) is the concatenated reference signal defined as \(\mathbf{A}_i = \left[\mathbf{Y}_{i-m},\cdots,\mathbf{Y}_{i},\cdots,\mathbf{Y}_{i+n}\right]\).
Two types of correlation coefficients are computed:
The target stimulus is predicted by combining two correlation coefficients:
- SSVEPAnalysisToolbox.algorithms.MSCCA()¶
ms-CCA. The implementation directly follows above equations.
- Parameters
n_neighbor – Number of neighbers considered for computing the spatial filter of one stimulus. Default is
12.n_component – Number of components of eigen vectors that will be applied as the spatial filters. The default number is
1, which means the eigen vector with the highest eigen value is regarded as the spatial filter.n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.
Multi-set CCA (MsetCCA)¶
Related paper:
Zhang, G. Zhou, J. Jin, X. Wang, A. Cichocki, “Frequency recognition in SSVEP-based BCI using multiset canonical correlation analysis,” Int J Neural Syst., vol. 24, 2014, p. 1450013. DOI: 10.1142/ S0129065714500130.
For each stimulus, the MsetCCA maximize the inter-trial covariance to compute the spatial filters. The spatial filters of different trials are different.
where \(\widetilde{\mathbf{w}}_{i,n}\) denotes the spatial filter of the \(i\text{-th}\) stimulus and the \(n\text{-th}\) training trial, \(N_t\) denotes the number of training trials, and \(\cal{X}_{i,n}\) denotes the calibration data of the \(i\text{-th}\) stimulus and the \(n\text{-th}\) training trial.
Solving this optimization problem is equivalent to solving the following eigenvalue problem:
where
- SSVEPAnalysisToolbox.algorithms.MsetCCA()¶
Multi-set CCA. The implementation directly follows above equations.
- Parameters
n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.
Multi-set CCA with reference signals (MsetCCA-R)¶
Related paper:
Wong, B. Wang, Z. Wang, K. F. Lao, A. Rosa, and F. Wan, “Spatial filtering in SSVEP-based BCIs: Unified framework and new improvements.,” IEEE Transactions on Biomedical Engineering, vol. 67, no. 11, pp. 3057-3072, 2020. DOI: 10.1109/TBME.2020.2975552.
The MsetCCA-R is an extension of the MsetCCA. It also tries to solve the following eigenvalue problem to find the spatial filters:
The key differences are the following two values:
and
where \(\mathbf{Q}_i\) is the QR decomposition of the \(i\text{-th}\) stimulus reference signal:
- SSVEPAnalysisToolbox.algorithms.MsetCCAwithR()¶
Multi-set CCA with reference signals. The implementation directly follows above equations.
- Parameters
n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.
TRCA with reference signals (TRCA-R) and eTRCA with reference signals (eTRCA-R)¶
Related paper:
Wong, B. Wang, Z. Wang, K. F. Lao, A. Rosa, and F. Wan, “Spatial filtering in SSVEP-based BCIs: Unified framework and new improvements.,” IEEE Transactions on Biomedical Engineering, vol. 67, no. 11, pp. 3057-3072, 2020. DOI: 10.1109/TBME.2020.2975552.
The TRCA-R and the eTRCA-R are extensions of the TRCA and the eTRCA respectively. They try to find the spatial filters by solving
where \(\mathbf{X}_i^{(j)}\) denotes the \(j\text{-th}\) trial training EEG signals of \(i\text{-th}\) stimulus, and \(\mathbf{Q}_i\) is obtained from the QR decomposition of the reference signals following the MsetCCA-R.
- SSVEPAnalysisToolbox.algorithms.TRCAwithR()¶
TRCA-R. The implementation directly follows above equations.
- Parameters
n_component – Number of components of eigen vectors that will be applied as the spatial filters. The default number is
1, which means the eigen vector with the highest eigen value is regarded as the spatial filter.n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.
- SSVEPAnalysisToolbox.algorithms.ETRCAwithR()¶
eTRCA-R. The spatial computation is same as the TRCA-R. The only difference is that the recognition uses the same set of spatial filters for all stimuli. This set of saptial filters contain all eigen vectors with the highest eigen value of all stimuli.
- Parameters
n_component – This parameter will not be considered in the eTRCA-R.
n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.
Sum of squared correlations (SSCOR) and Ensemble sum of squared correlations (eSSCOR)¶
Related paper:
Kumar, and M. R. Reddy, “Designing a sum of squared correlations framework for enhancing SSVEP-based BCIs,” IEEE Transactions on Neural Systems and Rehabilitation Engineering, vol. 27, no. 10, pp. 2044-2050, 2019. DOI: 10.1109/TNSRE.2019.2941349.
The key idea of the SSCOR is similar as the TRCA. The SSCOR also finds the common spatial filter across trials, but it assumes the spatial filters of differet trials are different. The SSCOR computes the common spatial filter \(\mathbf{U}_i\) and the spatial filter \(\mathbf{U}_i^{(j)}\) of the \(j\text{-th}\) trial for the \(i\text{-th}\) stimulus by solving
Based on the Cholesky decomposition, we have
Let’s define \(\mathbf{U}_i = \left(\mathbf{K}_i^{\overline{\mathbf{X}}}\right)^{-1}\mathbf{V}_i\), \(\mathbf{U}_i^{(j)} = \left( \mathbf{K}_{i,j}^{\mathbf{X}} \right)^{-1}\mathbf{V}_i^{(j)}\), \(\mathbf{G}_i^{(j)}=\left(\mathbf{K}_i^{\overline{\mathbf{X}}}\right)^{-T}\mathbf{C}_{i,j}^{\overline{\mathbf{X}}}\left(\mathbf{K}_{i,j}^{\mathbf{X}}\right)^{-1}\), and \(\mathbf{C}_{i,j}^{\overline{\mathbf{X}}} = \overline{\mathbf{X}}_i\left( \mathbf{X}_i^{(j)} \right)^T\), we get
\(\mathbf{V}_i\) can be calculated by solving
- SSVEPAnalysisToolbox.algorithms.SSCOR()¶
SSCOR. The implementation directly follows above equations.
- Parameters
n_component – Number of components of eigen vectors that will be applied as the spatial filters. The default number is
1, which means the eigen vector with the highest eigen value is regarded as the spatial filter.n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.
- SSVEPAnalysisToolbox.algorithms.ESSCOR()¶
eSSCOR. The spatial computation is same as the SSCOR. The only difference is that the recognition uses the same set of spatial filters for all stimuli. This set of saptial filters contain all eigen vectors with the highest eigen value of all stimuli.
- Parameters
n_component – This parameter will not be considered in the eTRCA.
n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.
Multi-stimulus TRCA¶
Related paper:
Wong, F. Wan, B. Wang, Z. Wang, W. Nan, K. F. Lao, P. U. Mak, M. I. Vai, and A. Rosa, “Learning across multi-stimulus enhances target recognition methods in SSVEP-based BCIs,” J. Neural Eng., vol. 17, no. 1, p. 016026, 2020. DOI: 10.1088/1741-2552/ab2373.
The multi-stimulus TRCA (ms-TRCA) is similar as the ms-CCA. It also considers training EEG signals of stimuli whose stimulus frequencies are close to the target stimulus to compute spatial filters:
- SSVEPAnalysisToolbox.algorithms.MSETRCA()¶
ms-TRCA. In this toolbox, the ms-TRCA follows the eTRCA scheme to emsemble spatial filters of all stimuli for the recognition.
- Parameters
n_neighbor – Number of neighbers considered for computing the spatial filter of one stimulus. Default is
2.n_component – This parameter will not be considered in this function.
n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.
- SSVEPAnalysisToolbox.algorithms.MSCCA_and_MSETRCA()¶
This method ensembles correlation coefficients of the ms-CCA and the ms-TRCA to recognize the target stimulus. Suppose that \(r_{1,i}\) and \(r_{2,i}\) are correlation coefficients obtained from the ms-CCA and the ms-TRCA respectively, then the ensembled correlation coefficient is
\[r_\text{ms-CCA + ms-TRCA} = \sum_{k=1}^2 \text{sign}\left\{r_{k,i}\right\}\cdot r_{k,i}^2\]- Parameters
n_neighbor_mscca – Number of neighbers considered for computing the spatial filter of one stimulus in the ms-CCA. Default is
12.n_neighber_msetrca – Number of neighbers considered for computing the spatial filter of one stimulus in the ms-TRCA. Default is
2.n_component – Number of components of eigen vectors that will be applied as the spatial filters in the ms-CCA. The default number is
1, which means the eigen vector with the highest eigen value is regarded as the spatial filter.n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.
Task-discriminant component analysis¶
Related paper:
Liu, X. Chen, N. Shi, Y. Wang, S. Gao, X. Gao, “Improving the performance of individually calibrated SSVEP-BCI by task-discriminant component analysis.” IEEE Trans. Neural Syst. Rehabil. Eng., vol. 29, pp. 1998-2007, 2021. DOI: 10.1109/TNSRE.2021.3114340.
Compared with other methods, the task-discriminant component analysis (TDCA) have following three key differences:
The dimensionality of EEG signals is elevated. For one trial EEG signal \(\mathbf{X}\), the augmented EEG trial \(\widetilde{\mathbf{X}}\) is
\[\begin{split}\widetilde{\mathbf{X}} = \left[ \begin{array}{cc} \mathbf{X}, & \mathbf{O}_0\\ \mathbf{X}_1, & \mathbf{O}_1\\ \vdots & \\ \mathbf{X}_L, & \mathbf{O}_L \end{array} \right]\end{split}\]where \(\mathbf{X}_l\) denotes the EEG trial delayed by \(l\) points, \(\mathbf{O}_l\in\mathbb{R}^{N_\text{ch}\times l}\) denotes the zero matrix, and \(L\) is the total number of delays.
After elevating the dimension, EEG trials are then further extended for each stimulus as
\[\mathbf{X}_a = \left[ \widetilde{\mathbf{X}},\;\; \widetilde{\mathbf{X}}\mathbf{Q}_i\mathbf{Q}_i^T \right]\]where \(\mathbf{Q}_i\) is the orthogonal factor of the reference signal of the \(i\text{-th}\) stimulus and can be obtained by the QR decomposition \(\mathbf{Q}_i\mathbf{R}_i=\mathbf{Y}_i^T\).
The two-dimensional linear discriminant analysis is applied to compute spatial filters by solving
\[\mathbf{S}_b\mathbf{U} = \mathbf{S}_w\mathbf{U}\mathbf{\Lambda}\]The \(\mathbf{S}_b\) is the covariance of between-class differences:
\[\mathbf{S}_b = \frac{1}{I} \sum_{i=1}^I \left( \overline{\mathbf{X}}_a^{(i)} - \frac{1}{I}\sum_{i=1}^I\overline{\mathbf{X}}_a^{(i)} \right)\left( \overline{\mathbf{X}}_a^{(i)} - \frac{1}{I}\sum_{i=1}^I\overline{\mathbf{X}}_a^{(i)} \right)^T\]where \(\overline{\mathbf{X}}_a^{(i)}\) is the averaged \(\mathbf{X}_a\) over all trials of the \(i\text{-th}\) stimulus, and \(I\) is the total number of stimuli.
The \(\mathbf{S}_w\) is the covariance of within-class differences:
\[\mathbf{S}_w = \frac{1}{N_t} \sum_{i=1}^I \sum_{j=1}^{N_t} \left( \mathbf{X}_a^{(i,j)} - \overline{\mathbf{X}}_a^{(i)} \right) \left( \mathbf{X}_a^{(i,j)} - \overline{\mathbf{X}}_a^{(i)} \right)^T\]where \(N_t\) denotes the total number of trials, and \(\mathbf{X}_a^{(i,j)}\) denotes \(\mathbf{X}_a\) of the \(j\text{-th}\) trial for the \(i\text{-th}\) stimulus.
Finally, the target stimulus can be predicted by
- SSVEPAnalysisToolbox.algorithms.TDCA()¶
TDCA. The implementation directly follows above equations.
- Parameters
n_component – Number of components of eigen vectors that will be applied as the spatial filters. The default number is
1, which means the eigen vector with the highest eigen value is regarded as the spatial filter.n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.n_delay – Total number of delays. Default is
0, which means no delay.
Online adaptive CCA¶
Related paper:
Wong et al., “Online adaptation boosts SSVEP-based BCI performance,” IEEE Trans. Biomed. Eng., vol. 69, no. 6, pp. 2018-2028, 2022. DOI: 10.1109/TBME.2021.3133594.
Compared to sCCA, the spatial filters are fine-turned online. Therefore, as more trials are processed, the performance will be improved until achieving the upper bound.
The OACCA ensembles three parts:
Spatial filters based on the sCCA. These spatial filters can be considered as the baseline reference of the recognition result.
Prototype spatial filters. These spatial filters are fine-turned online. They are calculated by
\[\mathbf{u}_0^{[t+1]}=\arg\max_{\mathbf{u}}\frac{\mathbf{u}^T\left[ \sum_{m=1}^t\widetilde{\mathbf{u}}^{[m]}\left(\widetilde{\mathbf{u}}^{[m]}\right)^T \right]\mathbf{u}}{\mathbf{u}^T\mathbf{u}}\]where \(\widetilde{\mathbf{u}}^{[t]} = \frac{\mathbf{u}^{[t]}}{\left\|\mathbf{u}^{[t]}\right\|}\) and \(\mathbf{u}^{[t]}\) is the spatial filtered obtained from the sCCA at the \(t\text{-th}\) trial.
Spatial filters based on the online ms-CCA. These spatial filters are also fine-turned online. They are calculated by
\[\mathbf{u}^{[t+1]},\;\mathbf{v}^{[t+1]}=\max_{\mathbf{u},\;\mathbf{v}}\frac{\mathbf{u}^T\mathbf{C}_{XY}^{[t]}\mathbf{v}}{\sqrt{\mathbf{u}^T\mathbf{C}_{XY}^{[t]}\mathbf{u} \cdot \mathbf{v}^T\mathbf{v}}}\]where \(\mathbf{C}_{XY}^{[t]}=\sum_{m=1}^t\left(\mathbf{X}^{[t]}\right)^T\mathbf{Y}\).
The basic idea of the OACCA is shown below:
- SSVEPAnalysisToolbox.algorithms.OACCA()¶
OACCA. The implementation directly follows above equations.
- Parameters
n_jobs – Number of threadings. If the given value is larger than 1, the parallel computation will be applied to improve the computational speed. Default is
None, which means the parallel computation will not be applied.weights_filterbank – Weights of filterbanks. It is a list of float numbers. Default is
None, which means all weights of filterbanks are 1.