Machine learning: Decoding / MVPA

Authors: Dimitrios Pantazis, Seyed-Mahdi Khaligh-Razavi, Francois Tadel,

This tutorial illustrates how to run MEG decoding (a type of multivariate pattern analysis / MVPA) using support vector machines (SVM).

License

To reference this dataset in your publications, please cite Cichy et al. (2014).

Description of the decoding functions

Two decoding processes are available in Brainstorm:

These two processes work in a similar way, but they use a different classifier, so only SVM is demonstrated here.

In the context of this tutorial, we have two condition types: faces, and objects. The participant was shown different types of images and we want to decode the face images vs. the object images using 306 MEG channels.

Download and installation

Import the recordings

Select files

Decoding with cross-validation

Cross-validation is a model validation technique for assessing how the results of our decoding analysis will generalize to an independent data set.

References

  1. Cichy RM, Pantazis D, Oliva A (2014), Resolving human object recognition in space and time, Nature Neuroscience, 17:455–462.

  2. Guggenmos M, Sterzer P, Cichy RM (2018), Multivariate pattern analysis for MEG: A comparison of dissimilarity measures, NeuroImage, 173:434-447.

  3. King JR, Dehaene S (2014), Characterizing the dynamics of mental representations: the temporal generalization method, Trends in Cognitive Sciences, 18(4): 203-210

  4. Isik L, Meyers EM, Leibo JZ, Poggio T, The dynamics of invariant object recognition in the human visual system, Journal of Neurophysiology, 111(1): 91-102

Additional documentation

Scripting

The following script from the Brainstorm distribution reproduces the analysis presented in this tutorial page: brainstorm3/toolbox/script/tutorial_decoding.m

1 function tutorial_decoding(tutorial_dir, reports_dir) 2 % TUTORIAL_DECODING: Script that runs the Brainstorm decodoing tutorial 3 % https://neuroimage.usc.edu/brainstorm/Tutorials/Decoding 4 % 5 % INPUTS: 6 % - tutorial_dir : Directory where the sample_decoding.zip file has been unzipped 7 % - reports_dir : Directory where to save the execution report (instead of displaying it) 8 9 % @============================================================================= 10 % This function is part of the Brainstorm software: 11 % https://neuroimage.usc.edu/brainstorm 12 % 13 % Copyright (c) University of Southern California & McGill University 14 % This software is distributed under the terms of the GNU General Public License 15 % as published by the Free Software Foundation. Further details on the GPLv3 16 % license can be found at http://www.gnu.org/copyleft/gpl.html. 17 % 18 % FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE 19 % UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY 20 % WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF 21 % MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY 22 % LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE. 23 % 24 % For more information type "brainstorm license" at command prompt. 25 % =============================================================================@ 26 % 27 % Author: Raymundo Cassani, 2026 28 29 % Output folder for reports 30 if (nargin < 2) || isempty(reports_dir) || ~isfolder(reports_dir) 31 reports_dir = []; 32 end 33 % You have to specify the folder in which the tutorial dataset is unzipped 34 if (nargin == 0) || isempty(tutorial_dir) || ~file_exist(tutorial_dir) 35 error('The first argument must be the full path to the dataset folder.'); 36 end 37 38 % Protocol name 39 ProtocolName = 'TutorialDecoding'; 40 % Subject name 41 SubjectName = 'Subject01'; 42 43 % Build the path of the files to import 44 MegFileName = fullfile(tutorial_dir, 'sample_decoding', 'subj04NN_sess01-0_tsss.fif'); 45 % Check if the folder contains the required file 46 if ~file_exist(MegFileName) 47 error(['The folder ' tutorial_dir ' does not contain the folder from the file sample_decoding.zip.']); 48 end 49 50 51 %% ===== CREATE PROTOCOL ===== 52 % Start brainstorm without the GUI 53 if ~brainstorm('status') 54 brainstorm nogui 55 end 56 % Delete existing protocol 57 gui_brainstorm('DeleteProtocol', ProtocolName); 58 % Create new protocol 59 gui_brainstorm('CreateProtocol', ProtocolName, 1, 0); 60 % Start a new report 61 bst_report('Start'); 62 63 64 %% ===== IMPORT THE RECORDINGS ===== 65 % Process: Create link to raw files 66 sFileRaw = bst_process('CallProcess', 'process_import_data_raw', [], [], ... 67 'subjectname', SubjectName, ... 68 'datafile', {MegFileName, 'FIF'}, ... 69 'channelalign', 1); 70 71 72 %% ===== EVENT MARKERS ===== 73 % Process: Read from channel 74 sFileRaw = bst_process('CallProcess', 'process_evt_read', sFileRaw, [], ... 75 'stimchan', 'STI101', ... 76 'trackmode', 'value', ... % Value: detect the changes of channel value 77 'maskcheck', 0, ... 78 'mask', '0', ... 79 'zero', 0, ... 80 'min_duration', 0); 81 % Process: Duplicate / merge events 82 sFileRaw = bst_process('CallProcess', 'process_evt_merge', sFileRaw, [], ... 83 'evtnames', '13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24', ... 84 'newname', 'faces', ... 85 'delete', 0); 86 87 % Process: Duplicate / merge events 88 sFileRaw = bst_process('CallProcess', 'process_evt_merge', sFileRaw, [], ... 89 'evtnames', '49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60', ... 90 'newname', 'objects', ... 91 'delete', 0); 92 93 94 %% ===== IMPORTING DATA EPOCHS ===== 95 % Process: Import MEG/EEG: Events 96 sFiles = bst_process('CallProcess', 'process_import_data_event', sFileRaw, [], ... 97 'subjectname', SubjectName, ... 98 'condition', '', ... 99 'eventname', 'faces, objects', ... 100 'timewindow', [], ... 101 'epochtime', [-0.2, 0.8], ... 102 'split', 0, ... 103 'createcond', 0, ... 104 'ignoreshort', 1, ... 105 'usectfcomp', 1, ... 106 'usessp', 1, ... 107 'freq', [], ... 108 'baseline', [-0.2, 0], ... 109 'blsensortypes', 'MEG'); 110 111 112 %% ===== DECODING WITH CROSS-VALIDATION ===== 113 % Decoding: Over time 114 % Process: SVM decoding 115 sDecodeTimePair = bst_process('CallProcess', 'process_decoding_svm', sFiles, [], ... 116 'sensortypes', 'MEG', ... 117 'ignorebad', 0, ... 118 'lowpass', 30, ... 119 'num_permutations', 100, ... 120 'kfold', 5, ... 121 'method', 1, ... % Pairwise 122 'model', 'svm'); 123 124 % Process: Snapshot: Recordings time series 125 bst_process('CallProcess', 'process_snapshot', sDecodeTimePair, [], ... 126 'type', 'data', ... % Recordings time series 127 'time', 0.1, ... 128 'contact_time', [0, 0.1], ... 129 'contact_nimage', 12, ... 130 'rowname', '', ... 131 'Comment', ''); 132 133 % Decoding: Temporal generalization 134 % Process: SVM decoding 135 sDecodeTimeGen = bst_process('CallProcess', 'process_decoding_svm', sFiles, [], ... 136 'sensortypes', 'MEG', ... 137 'ignorebad', 0, ... 138 'lowpass', 30, ... 139 'num_permutations', 100, ... 140 'kfold', 5, ... 141 'method', 2, ... % Temporal generalization 142 'model', 'svm'); 143 144 % Snapshot 145 hFig = view_matrix(sDecodeTimeGen.FileName, 'Image'); 146 bst_report('Snapshot', hFig, sDecodeTimeGen.FileName); 147 close(hFig); 148 149 150 %% ===== SAVE REPORT ===== 151 % Save and display report 152 ReportFile = bst_report('Save', []); 153 if ~isempty(reports_dir) && ~isempty(ReportFile) 154 bst_report('Export', ReportFile, reports_dir); 155 else 156 bst_report('Open', ReportFile); 157 end 158 159 disp([10 'DEMO> Decoding tutorial completed' 10]); 160





Feedback on the documentation (typos, unclear sections, missing information)
For questions, bug reports, and feature requests, please use the Brainstorm Forum.
Email address (if you expect an answer):


Tutorials/Decoding (last edited 2026-08-11 15:39:27 by RaymundoCassani)