Direct ITR optimisation for SSVEP-based BCI
This repository contains example code for optimising information transfer rate (ITR) in steady-state visual evoked potential based brain computer interfaces. The novelty of the proposed classification method is that it is based on direct ITR maximisation. ITR is a standard measure of performance for BCIs. It combines the accuracy and the speed of the classifier into a single number which shows how much information is transferred by the BCI in one unit of time. Therefore, maximising ITR maximises the amount of information that the user can transfer to an external device (computer, robot, etc) in a fixed time interval.
The method is introduced in the article: Anti Ingel, Ilya Kuzovkin, and Raul Vicente. "Direct information transfer rate optimisation for SSVEP-based BCI." Journal of neural engineering 16.1 (2018). Please cite this article when using our code.
This code requires Python 2.7 with numpy, scipy, matplotlib, pandas, sklearn, rpy2 libraries. Library rpy2 is used to run R commands in Python. The reason for using rpy2 is that we need to calculate skew normal distribution cumulative distribution function values and I have encountered memory leak bugs in the corresponding scipy function.
If you have problems installing rpy2 try following these steps. To install rpy2, download cp27 version from here. Then you need to add system variables (with paths changed according to your system):
R_HOME c:\program files\r\r-3.4.2 R_USER C:\Python27\Lib\site-packages\rpy2 R_LIBS C:/Users/Anti/Documents/R/win-library/3.4;C:/Program Files/R/R-3.4.2/library
If you are also using RStudio, change
R_USER C:\Program Files\RStudio\bin;C:\Python27\Lib\site-packages\rpy2
See here for additional help.
Other required libraries can be easily installed using
Before trying to run the code, please download the required dataset from here. The original dataset can also be found here, but using the previous link is recommended, because it contains folder structure required by the code.
plots folders to the same folder that contains
data folder contains both, the original dataset and processed data. The folder
original_data contains original data. The content of other folders is as follows:
csvfiles with columns corresponding to electrodes and rows corresponding to time. Information about the electrode locations can be found in
1_original_data_to_csv.pycan be used to generate files in
original_data_as_csvfolder from the original files in
MATLABformat in folder
eeg_datacontains EEG data from only electrodes O1 and O2. Since visual stimulation started at second 5 and stopped at second 20 of the recording as described in
original_datafolder, the beginning and end of each trial is removed. For each of the four subjects, five recordings are generated by concatenating data from different trials (each recording contains one trial for each of the three frequencies. Script
2_generate_eeg_data.pycan be used to generate files in
eeg_datafolder from the files in folder
feature_datacontains extracted features for each of the subject and for all of their recordings. PSDA and CCA feature extraction methods were used, both with using 3 harmonics. Script
3_generate_feature_data.pycan be used to generate files in
feature_datafolder from the files in folder
Finally, the script
4_optimise_itr can be used to run ITR optimisation procedure, using the files in
feature_data folder. This script prints into console the results of different classification methods (accuracy, ITR, MDT, confusion matrix) and also produces different kinds of plots into the
plots folder (if
make_plots argument of trainer.start is set to True).
For additional information, feel free to contact the author Anti Ingel (firstname.lastname@example.org).