Para speccsp

Jump to: navigation, search

Spectrally Weighted CSP: Advanced paradigm for oscillatory processes via the Spectrally weighted CSP algorithm.

Result = para_speccsp(Input-Data, Operation-Mode, Options...)

The Spec-CSP paradigm [1] is a more advanced variant of CSP, developed for the Berlin Brain-Computer Interface (BBCI); the primary focus was motor imagery BCI, but the algorithm was designed from the outset to be applicable for a wider range of applications. The implementation closely follows the TR [2].

The paradigm is applicable to the majority of oscillatory processes, and is the most advanced spatio-spectrally adaptive method that is currently provided in the toolbox. Whenever the exact frequency and location of some (conjectured) oscillatory process is not known exactly, Spec-CSP can be used, and typically gives better results than CSP with an appropriately unrestricted (e.g., broad-band) spectral filter. Several other methods exist to adapt the spectrum to a process of interest, among others Common Spatio-Spectral Patterns [3], Common Sparse Spectral Spatial Pattern [4], r^2-based heuristics [5], automated parameter search, and manual selection based on visual inspection. Several of these methods have been shown to give approx. comparable results [2]. An alternative and competitive method, especially when there complex interactions between frequency bands and time periods are to be modeled is the Dual-Augmented Lagrange paradigm (para_dal/para_dal_hf).

The method iteratively optimizes spatial and spectral filters in alternation and extracts log-variance features from the resulting (filtered) data. These features are subsequently processed by a (typically simple) machine learning component, by default LDA. Learning is therefore significantly slower than CSP. An option is to impose custom prior knowledge on the relevant data spectrum, for example by placing a focus on the alpha rhythm, without ruling out other frequencies. Note that there are parameters which constrain the spectrum: one is the frequency prior and the other is the spectral filter that is applied before running the alorithm; both need to be adapted when the considered spectrum shall be extended (e.g. to high-gamma oscillations). Other parameters which are frequently adapted are the time window of interest and the learner component (e.g., logistic regression is a good alternative choice).

Some application areas include detection of major brain rhythm modulations (e.g. theta, alpha, beta, gamma), for example related to relaxation/stress, aspects of workload, emotion, sensori-motor imagery, and in general cortical idle oscillations in various modalities.

Example: Consider the goal of predicting the emotion felt by a person at a given time. A possiblecalibration data set for this task would contain a sequence of blocks in each of which the subjectis one out of several possible emotions, indicated by events 'e1','e2','e3','e4' covering theseblocks in regular intervals, for example induced via guided imagery [6].
calib = io_loadset('data sets/bruce/emotions.eeg')
[loss,model,stats] = bci_train({'data',calib,'paradigm',@para_speccsp}, 'epoch',[-2.5 2.5], 'events',{'e1','e2','e3','e4'});

Input Arguments


some data set


'preprocessing', to pre-process the Signal according to the paradigm (and parameters)

'learning', to learn a predictive model from a pre-processed Signal (and parameters)

'prediction', to make predictions given a pre-processed Signal and a Model

User Options...

optional parameters of the paradigm; name-value pairs

--- for preprocessing (see flt_default)

  • 'spectrum': spectral filter (default: [5 45])
  • 'srate': sampling rate, in Hz (default: 200)
  • 'epoch': epoch window, in seconds relative to event (default: [0.5 3.5])
  • 'events': event types to determine epochs and the target variable (user-specified)
  • others, by default turned off: see flt_default

--- for learning

  • 'patterns': the number of pattern pairs that Spec-CSP should produce; feature-space dimension will be twice this number (default: 3)
  • 'prior': function of frequency implementing a prior (default: @(f) f>=7 & f<=30)
  • 'pp': regularization parameter p' (default: 0), can be optimized using search(-1:0.5:1)
  • 'qp': regularization parameter q' (default: 1), can be optimized using search(0:0.5:4)
  • 'steps': number of iterations (spatial optimization, followed by spectral optimization) to execute (default: 3)
  • 'learner': learning function to be used on the features; (default: 'lda')

--- for prediction

  • 'model': the detector model (as produced during the learning)

Output Arguments


depends on the Operation-Mode;

  • for 'preprocessing', this is the preprocessed data set
  • for 'learning', this is the learned model
  • for 'prediction', this is the predictions produced by the model, given the data


% assuming that a calibration data set has been loaded and markers that encode different

% conditions have been defined like in the following

traindata = io_loadset('bcilab:/userdata/tutorial/imag_movements1/calib/DanielS001R01.dat');

markers = {'StimulusCode_2','StimulusCode_3'};

% define a standard Spec-CSP approach, using the defaults (shrinkage LDA classifier)
% note: *after* the approach has been defined, a model can be learned with a command like:
[trainloss,lastmodel,laststats] = bci_train({'data',traindata,'approach',myapproach})
myapproach = {'SpecCSP' 'SignalProcessing',{'EpochExtraction',{'TimeWindow',[0 3.5],'EventTypes',markers}}};

% use a different time window (note: Spec-CSP is less robust on short windows as CSP, as it learns a spectral filter
myapproach = {'SpecCSP' 'SignalProcessing',{'EpochExtraction',{'TimeWindow',[0.5 3],'EventTypes',markers}}};

% use a different spectral filter (here: 10-15 Hz, alpha band)
myapproach = {'SpecCSP' 'SignalProcessing',{'SpectralSelection',[10 15], 'EpochExtraction',{'TimeWindow',[0.5 3],'EventTypes',markers}}};

% use a different number of Spec-CSP pattern pairs (here: 2 pairs instead of the default 3)
myapproach = {'SpecCSP' 'SignalProcessing',{'EpochExtraction',{'TimeWindow',[0.5 3],'EventTypes',markers}}, 'FeatureExtraction',{'PatternPairs',2}};

% use different setting for the regularization parameters P & Q
myapproach = {'SpecCSP' 'SignalProcessing',{'EpochExtraction',{'TimeWindow',[0.5 3],'EventTypes',markers}}, 'FeatureExtraction',{'ParameterP',1,'ParameterQ',1}};

% use a different filter implementation (IIRFilter) instead of SpectralSelection (which is FFT-based)
myapproach = {'SpecCSP' 'SignalProcessing',{'SpectralSelection','off','IIRFilter',[5 7 25 30], 'EpochExtraction',{'TimeWindow',[0.5 3],'EventTypes',markers}}};

% use yet another filter implementation (FIRFilter) instead of the default SpectralSelection
% (note: the FIR filter can have unexpected behavior in the transition regions; keeping them small is usually better)
myapproach = {'SpecCSP' 'SignalProcessing',{'SpectralSelection','off','FIRFilter',[6.5 7 29 30], 'EpochExtraction',{'TimeWindow',[0.5 3],'EventTypes',markers}}};

% use a different learning function (here: shrinkage QDA)
myapproach = {'SpecCSP' 'SignalProcessing',{'SpectralSelection','off','IIRFilter',[5 7 25 30], 'EpochExtraction',{'TimeWindow',[0.5 3],'EventTypes',markers}}, 'MachineLearning',{'Learner','qda'}};

% use a different learning function (here: variational Bayesian Dirichlet process Gaussian mixture models)
myapproach = {'SpecCSP' 'SignalProcessing',{'SpectralSelection','off','IIRFilter',[5 7 25 30], 'EpochExtraction',{'TimeWindow',[0.5 3],'EventTypes',markers}}, 'MachineLearning',{'Learner','gmm'}};

% try a relatively large number of pattern pairs (= features), and use a (slow!) sparse non-linear classifier (HKL)
% this will run faster if a less fine-grained (3x) cross-validation is being used, like the following
[trainloss,lastmodel,laststats] = bci_train({'data',traindata, 'approach',myapproach, 'eval_scheme',{'chron',3,5}})
myapproach = {'SpecCSP' 'SignalProcessing',{'SpectralSelection','off','IIRFilter',[5 7 25 30], 'EpochExtraction',{'TimeWindow',[0.5 3],'EventTypes',markers}}, 'FeatureExtraction',{'PatternPairs',10},'MachineLearning',{'Learner','hkl'}};


[1] Tomioka, R., Dornhege, G., Aihara, K., and Mueller, K.-R. "An iterative algorithm for spatio-temporal filter optimization."

In Proceedings of the 3rd International Brain-Computer Interface Workshop and Training Course 2006.

[2] Ryota Tomioka, Guido Dornhege, Guido Nolte, Benjamin Blankertz, Kazuyuki Aihara, and Klaus-Robert Mueller

"Spectrally Weighted Common Spatial Pattern Algorithm for Single Trial EEG Classification",
Mathematical Engineering Technical Reports (METR-2006-40), July 2006.

[3] Steven Lemm, Benjamin Blankertz, Gabriel Curio, and Klaus-Robert Muller.

"Spatio-spectral filters for improving classification of single trial EEG."
IEEE Trans Biomed Eng, 52(9):1541-1548, 2005.

[4] G. Dornhege, B. Blankertz, M. Krauledat, F. Losch, G. Curio, and K.-R. Muller,

"Combined optimization of spatial and temporal filters for improving brain-computer interfacing,"
IEEE Transactions on Biomedical Engineering, vol. 53, no. 11, pp. 2274?2281, 2006.

[5] Benjamin Blankertz, Ryota Tomioka, Steven Lemm, Motoaki Kawanabe, and Klaus-Robert Mueller.

"Optimizing spatial filters for robust EEG single-trial analysis."
IEEE Signal Process Mag, 25(1):41-56, January 2008

[6] Onton J & Makeig S. "Broadband high-frequency EEG dynamics during emotion imagination."

Frontiers in Human Neuroscience, 2009.
Christian Kothe, Swartz Center for Computational Neuroscience, UCSD