Difference: DocSectionsExampleFacesPlaces (2 vs. 3)

Revision 303 Jan 2013 - Main.AdnanNiazi

Line: 1 to 1
 

Example 3: Decoding Visual Attention with real-time FMRI

[under construction- this is a rough sketch]

Line: 30 to 30
 This function intiliazes the stimulus material for each task. Becasue during the 'Classifier' task (in which the traning data is used to trainn the classsifier,) no stimulus is presented therefore, the code skips loading any stimulus related info during this task.

(from table)

Changed:
<
<
bs_trace('scan_count','add'), bs_trace( 'epoch_count', 'add'), bs_trace( 'sequence_count','add'), bs_trace('alphaLevel','add')   
bs_trace.m traces the variable and when these variables change (globally) then it logs the value of the varialbes in the log file. Hence it allows to track what happens to each varaialbe and when.
>
>
bs_trace('scan_count','add'), bs_trace( 'epoch_count', 'add'), bs_trace( 'sequence_count','add'), bs_trace('alphaLevel','add')   

bs_trace.m traces the variable and when these variables change (globally) then it logs the value of the varialbes in the log file. Hence it allows to track what happens to each varaialbe and when.

function event = annotate(event)
% event.stiminfo.num_epochs
% event.stiminfo.num_rest_scans
% event.stiminfo.test.scans_per_epoch
% event.stiminfo.scans_per_epoch;

sc=event.scan_count;
ep=event.epoch_count;
nscans_tsk = event.stiminfo.num_task_scans;
nscans_pre = event.stiminfo.num_pre_scans;

event.scan.task         = event.task;
event.scan.data         = event.data.raw;
event.scan.sample      = event.data.trial.offset;
event.scan.scan_count           = event.scan_count;
event.scan.epoch_count           = event.epoch_count;

% use booleans for actual task or rest (won't get here during cue)
istask = (sc <= nscans_tsk + nscans_pre);

% start with task, then rest
if istask
   % task (training, test, ...)
   % only executes when sc > nscans_pre! This is done in the nextScan function.
   task_idx = sc-nscans_pre; % scan index during the current actual task
   % add label information (add custom labeling via label info field in
   % get_stiminfo_<task> function
   event.scan.label = event.stiminfo.labels{ep}{task_idx};   
else
   % rest
   event.scan.label = struct('label',0,'info','rest');
end

if strcmp(event.task,'test')
   % add labeling for non-training tasks
   event.scan.predict      = event.classifier.predict; % from bs_test_glmnet
   event.scan.X         = event.X; % from bs_test_glmnet
   event.scan.feedback      = event.feedback; % from bs_test_glmnet
end

event.stiminfo contains stimulus information that we make before each task. Annotate function puts this stimulus information for each TR in the structure that is stored once the experiment finish. Hence it makes a data structure that can be used offline to analyze the online real-time run.

 function var = putfld(update, var, field)

% update:   content that should replace content of destination field
%      dstfield) of global variable
% var:      global variable
% field:   field of global variable
Currently dont understand how put work with four input arguments
(G7): put('scan',collect_data,[],'scans')   
 
 function event = init_fmri_buffer(event)

numepochs = event.stiminfos.(event.task).num_epochs ;
numscans    = event.stiminfos.(event.task).scans_per_epoch;

% initialize fixed cell array buffer to collect scan info structures
event.fmri.scans = init_data(cell(1,numscans*numepochs),[],[],'fixed',2);
end

Make a cell array structure and fills it as scans arrive.

 function var = init_data(update, var, field, type, catdim)
% update: size of new buffer
%          if update = 'clear', it assumes buffer is already initialized,
%          but needs to be filled with all zeros
% catdim: dimension along which to fill the buffer
% type:    'ring', 'fixed', or 'concat'
% Note, for type 'concat', initialize with zero catdim dimension

% to clear the buffer, set update='clear' and specify field if assigned to structure field

if nargin < 3, field    = []; end
if nargin < 5, catdim = []; end

% if variable is stored as field of a structure, get it into buf
buf = field2var(var, field);

if ischar(update) && strcmp(update,'clear') 
   % check type buffer
   if isempty(buf) || ~isfield(buf,'isa') || ~strcmp(buf.isa,'buffer_variable')
      error('Can not clear an uninitialized buffer');
   end
   
   buf.data = zeros(buf.dims);
   buf.ptr = 0;
   buf.num = 0;
   if ~buf.concat
      buf.id  = ones(1,buf.len)*nan;% fill with nan's to identify empty entries
   end
else
   buf = buffer_variable(update, type, catdim);
end

% if part of structure, put it back
var = var2field(var,buf,field);

end
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback