UserReference:P300ClassifierMethods: Difference between revisions
No edit summary |
m User Reference:Methods moved to UserReference:P300ClassifierMethods: It is most appropriate. |
||
| (21 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== Load BCI2000 Data Files == | |||
Once the BCI2000 data files are check for compatibility, signals are extracted either from each training or testing data file and are arranged in a matrix form as: | |||
<math> | <math> | ||
{\mathbf{X_{i}^{k}(n)}} = | {\mathbf{X_{i}^{k}(n)}} = | ||
\begin{bmatrix} | \begin{bmatrix} | ||
x_{1}^{1}( | x_{1}^{1}(0) & x_{1}^{1}(1) & \cdots & x_{1}^{1}(p-1) & \cdots & x_{1}^{l}(0) & x_{1}^{l}(1) & \cdots & x_{1}^{l}(p-1) \\ | ||
x_{2}^{1}( | x_{2}^{1}(0) & x_{2}^{1}(1) & \cdots & x_{2}^{1}(p-1) & \cdots & x_{2}^{l}(0) & x_{2}^{l}(1) & \cdots & x_{2}^{l}(p-1) \\ | ||
\vdots & \vdots & \cdots &\vdots & \cdots & \vdots & \vdots & \cdots & \vdots \\ | \vdots & \vdots & \cdots &\vdots & \cdots & \vdots & \vdots & \cdots & \vdots \\ | ||
x_{m}^{1}( | x_{m}^{1}(0) & x_{m}^{1}(1) & \cdots & x_{m}^{1}(p-1) & \cdots & x_{m}^{l}(0) & x_{m}^{l}(1) & \cdots & x_{m}^{l}(p-1) \\ | ||
\end{bmatrix} | \end{bmatrix} | ||
</math> | </math> | ||
| Line 17: | Line 19: | ||
<math> k = 1, 2, \ldots, l; </math> | <math> k = 1, 2, \ldots, l; </math> | ||
<math> n = 1 | <math> n = 0, 1, \ldots, p-1; </math> | ||
being <math> m </math> the total number of observations (stimuli), <math> l </math> the total number of channels, and <math> p = t*Fs </math> the total number of samples recorded for each channel. <math> t </math> is the recording stimulus time, and <math> Fs </math> is the sampling frequency. | being <math> m </math> the total number of observations (stimuli), <math> l </math> the total number of channels, and <math> p = t*Fs </math> the total number of samples recorded for each channel. <math> t </math> is the recording stimulus time, and <math> Fs </math> is the sampling frequency. | ||
Consider the following example to help you understand the previous mathematical notation. A BCI data set is recorded during a P300 Speller task using a 6 by 6 matrix of characters. Each row and column of the matrix is randomly intensified resulting in 12 different stimuli. The sets of 12 intensification are repeated 15 times for each intended character to spell. For this example, the subject pretend to spell the word "SEND", a total of 4 characters. | |||
[[Image:P3SpellerScreen.PNG|center|frame|A 6 by 6 speller matrix. Here, the user's task is to spell the word "SEND" (one character at a time). For each character, all rows and columns in the matrix are intensified 15 times (here, the third row is shown intensified).]] | |||
Assume that the data set is recorded from 8 channels at 256 Hz, the elapsed time from the start to the end of each intensification is 800 ms, and the [[User_Reference:P300_classifier#Parameters Pane|'''Decimation Frequency''']] provided by the investigator is 20 Hz. For this example, <math> m = 12x15x4 = 720 </math>, <math> l = 8 </math>, and <math> p = round(256 x 0.800) = 205 </math>. The total number of columns (variables) of the above matrix is <math> 8 x 205 = 1640 </math>. | |||
== Get P300 Responses == | |||
In this step, it is computed the corresponding time samples of a time [[User_Reference:P300_classifier#Parameters Pane|'''Response Window''']] <math> [t_{1}, t_{2}] </math> in (ms). Following the above example, assume that the time Response Window specified by the investigator is [0 800] ms. | |||
<math> | |||
n_{1} = round\left(\frac{t_{1}Fs}{1000}\right) = round\left(\frac{0*256}{1000}\right) = 0 | |||
</math> | |||
<math> | |||
n_{2} = round\left(\frac{t_{2}Fs}{1000}\right) = round\left(\frac{800*256}{1000}\right) = 205 | |||
</math> | |||
Signals of interest are extracted from <math> \mathbf{X_{i}^{k}(n)} </math> and are defined | |||
only for <math> n_{1}\le n < n_{2} </math>. | |||
The coefficients <math> b_{i} </math> of the [http://en.wikipedia.org/wiki/Moving_average Moving Average (MA)] filter are found as | |||
<math> | |||
b_{i} = \frac{1}{N+1} | |||
</math> | |||
for <math> i = 0, 1, 2, \ldots, N </math> where <math> N </math> is the filter order. The filter order can be computed from the sampling frequency <math> Fs </math> and the provided decimation frequency <math> Df </math> as | |||
<math> | |||
N = round \left(\frac{Fs}{Df}\right) = round \left(\frac{256}{20}\right) = 13 | |||
</math> | |||
Thus, the impulse response <math> h(n) </math> can be computed as | |||
<math> | |||
h(n) = \frac{1}{N+1} \sum_{i=0}^{N-1} \delta(n-i). | |||
</math> | |||
To filter the selected signals, each channel <math> k </math> and each observation (stimulus) <math> i </math> of the matrix <math> \mathbf{X_{i}^{k}(n)} </math> is convolved <math> (\star) </math> with the impulse response <math> h(n) </math>. The next equation shows how to filter a signal for channel <math> k = 1 </math> and observation <math> i = 1 </math> | |||
<math> | |||
y_{1}^{1}(n) = x_{1}^{1}(n) \star h(n). | |||
</math> | |||
The output <math> y_{i}^{k}(n)</math>, result of the convolution between all the extracted signals —for channels <math> k = 1, 2, \ldots, l </math> and observations <math> i = 1, 2, \ldots, m </math>— and the impulse response, is [http://en.wikipedia.org/wiki/Downsampling downsampled] by a factor <math> N </math>. | |||
== Generate Feature Weights for a Linear Model using Stepwise Linear Discriminant Analysis (SWLDA) == | |||
Consider a data vector <math> \mathbf {d} </math> of <math> m </math> observations, a vector <math> \mathbf{w} </math> of <math> n </math> model parameters (weights) to estimate, and a matrix <math> \mathbf{G} </math> representing the final linear model. This inverse problem can be written as | |||
<math> | |||
\mathbf{G}\mathbf{w} = \mathbf{d} | |||
</math> | |||
An approximate solution to this problem can be found by minimizing the difference (residuals) between the actual data <math> \mathbf{d} </math> and <math> \mathbf{G}\mathbf{w} </math>. | |||
<math> | |||
\mathbf{r} = \mathbf{d} - \mathbf{G}\mathbf{w} | |||
</math> | |||
The least squares or 2-norm solution has been adopted to minimize these residuals. | |||
<math> | |||
\mathbf{w} = (\mathbf{G^{T}}\mathbf{G})^{-1}\mathbf{G^{T}}\mathbf{d}. | |||
</math> | |||
The symbol <math> T </math> represents the transpose of the matrix <math> \mathbf{G} </math>. Note that least squares solution is only valid for overdetermined systems (<math> m \le n </math>); there must be in the model more observations than variables. If the residuals have a normal distribution, the least squares corresponds to the maximum likelihood criterion. | |||
Latest revision as of 00:08, 14 September 2009
Load BCI2000 Data Files
Once the BCI2000 data files are check for compatibility, signals are extracted either from each training or testing data file and are arranged in a matrix form as:
for
being the total number of observations (stimuli), the total number of channels, and the total number of samples recorded for each channel. is the recording stimulus time, and is the sampling frequency.
Consider the following example to help you understand the previous mathematical notation. A BCI data set is recorded during a P300 Speller task using a 6 by 6 matrix of characters. Each row and column of the matrix is randomly intensified resulting in 12 different stimuli. The sets of 12 intensification are repeated 15 times for each intended character to spell. For this example, the subject pretend to spell the word "SEND", a total of 4 characters.
Assume that the data set is recorded from 8 channels at 256 Hz, the elapsed time from the start to the end of each intensification is 800 ms, and the Decimation Frequency provided by the investigator is 20 Hz. For this example, , , and . The total number of columns (variables) of the above matrix is .
Get P300 Responses
In this step, it is computed the corresponding time samples of a time Response Window in (ms). Following the above example, assume that the time Response Window specified by the investigator is [0 800] ms.
Signals of interest are extracted from and are defined only for .
The coefficients of the Moving Average (MA) filter are found as
for where is the filter order. The filter order can be computed from the sampling frequency and the provided decimation frequency as
Thus, the impulse response can be computed as
To filter the selected signals, each channel and each observation (stimulus) of the matrix is convolved with the impulse response . The next equation shows how to filter a signal for channel and observation
The output , result of the convolution between all the extracted signals —for channels and observations — and the impulse response, is downsampled by a factor .
Generate Feature Weights for a Linear Model using Stepwise Linear Discriminant Analysis (SWLDA)
Consider a data vector of observations, a vector of model parameters (weights) to estimate, and a matrix representing the final linear model. This inverse problem can be written as
An approximate solution to this problem can be found by minimizing the difference (residuals) between the actual data and .
The least squares or 2-norm solution has been adopted to minimize these residuals.
The symbol represents the transpose of the matrix . Note that least squares solution is only valid for overdetermined systems (); there must be in the model more observations than variables. If the residuals have a normal distribution, the least squares corresponds to the maximum likelihood criterion.