# Multiple Kernel Stein Spatial Patterns for the Multiclass Discrimination of Motor Imagery Tasks
## 2 Methods
### Spatial Filter Optimization Using Centered Kernel Alignment  
Given the kernel function in Equation (11) and the vector of target labels \(\mathbf{y}=\{y_{n}\}_{n=1}^{N}\), optimization of \(\mathbf{W}_{b}\) is carried out by minimizing the negative logarithm of the Centered Kernel Alignment (CKA) cost function, assessing the similarity between two random variables through the inner product of their representing kernel matrices as defined by Equation (12).  
\[L(\mathcal{X}_{b},\mathbf{y}|\mathbf{W}_{b})=-\log\frac{\langle\overline{\mathbf{K}}_{b}( \mathbf{W}_{b}),\overline{\mathbf{K}}_{y}\rangle_{F}}{||\overline{\mathbf{K}}_{b}(\mathbf{W}_ {b})||_{F}||\overline{\mathbf{K}}_{y}||_{F}} \tag{12}\]  
where kernel matrices \(\mathbf{K}_{b}\in\mathbb{R}^{N\times N}\), with elements \(k_{nm}=k(\mathbf{x}_{nb}(t),\mathbf{x}_{mb}(t)|\mathbf{W}_{b})\), and \(\mathbf{K}_{y}=\{\delta(y_{n},y_{m}):n,m=[1,N]\}\in\{0,1\}^{N\times N}\) hold every pair-wise trial similarity in the component Riemmanian manifold and in the label space, respectively. \(||\mathbf{A}||_{F}=\sqrt{\langle\mathbf{A},\mathbf{A}\rangle_{F}}\) corresponds to the Frobenius norm and \(\delta(\cdot,\cdot)\) denotes the delta Dirac function. \(\overline{\mathbf{K}}\) stands for the centered kernel matrix asociated to \(\mathbf{K}\) and computed as in Equation (13), being \(\mathbf{U}_{N}\) the centering matrix, \(\mathbf{I}_{N}\) the \(N\)-order identity matrix, and \(\mathbf{1}_{N}\) an all ones column vector. The centering operation translates all samples in the Hilbert space reproduced by the kernel \(k(\cdot,\cdot)\) near the convex hull of the samples, so coping with ill-conditioning due to biased pair-wise inner products [23].  
\[\overline{\mathbf{K}} =\mathbf{U}_{N}\mathbf{K}\mathbf{U}_{N} \tag{13}\] \[\mathbf{U}_{N} =\mathbf{I}_{N}-\frac{1}{N}\mathbf{1}_{N}\mathbf{1}^{\top}{}_{N} \tag{14}\]  
Aiming at minimizing the negative logarithm CKA between \(\mathbf{K}_{b}\) and the label matrix \(\mathbf{K}_{y}\), we consider a stochastic gradient descent approach with respect to spatial filter matrix \(\mathbf{W}_{b}\). Using the chain rule, the gradient of the cost function w.r.t. \(\mathbf{W}_{b}\) is expressed as:  
\[\
abla L(\mathbf{W}_{b}) =\sum_{n=1}^{N}\sum_{m=1}^{N}\frac{\partial L}{\partial k_{nm}} \frac{\partial k_{nm}}{\partial D_{nm}}\frac{\partial D_{nm}}{\partial\mathbf{W}_ {b}} \tag{15}\] \[\frac{\partial L}{\partial\mathbf{K}_{b}} =-\frac{\overline{\mathbf{K}}_{y}}{\langle\overline{\mathbf{K}}_{b}, \overline{\mathbf{K}}_{y}\rangle_{F}}+2\frac{\overline{\mathbf{K}}_{b}}{\langle \overline{\mathbf{K}}_{b},\overline{\mathbf{K}}_{b}\rangle_{F}}\] (16) \[\frac{\partial k_{nm}}{\partial D_{nm}} =-\beta e^{-\gamma_{b}D(\mathbf{S}_{nb}\mathbf{S}_{nb}|\mathbf{W}_{b})}=- \gamma_{b}k_{nm}\] (17) \[\frac{\partial D_{nm}}{\partial\mathbf{W}_{b}} =\mathbf{\Sigma}_{nb}\mathbf{W}_{b}[2(\mathbf{W}_{b}^{\top}(\mathbf{\Sigma}_{nb}+ \mathbf{\Sigma}_{mb})\mathbf{W}_{b})^{-1}-(\mathbf{W}_{b}^{\top}\mathbf{\Sigma}_{nb}\mathbf{W}_{b}) ^{-1}]\] (18) \[+\mathbf{\Sigma}_{mb}\mathbf{W}_{b}[2(\mathbf{W}_{b}^{\top}(\mathbf{\Sigma}_{nb}+ \mathbf{\Sigma}_{mb})\mathbf{W}_{b})^{-1}-(\mathbf{W}_{b}^{\top}\mathbf{\Sigma}_{mb}\mathbf{W}_{b}) ^{-1}]\]  
Therefore, maximizing the alignment between samples and their label kernels yields a matrix \(\mathbf{W}_{b}\) rotating the channel data so that the Riemmanian space of component covariances better discriminates the given classes in the frequency band \(b\).