Home > . > DIVA_SomatosensoryCortex.m

DIVA_SomatosensoryCortex

PURPOSE ^

DIVA_SomatosensoryCortex Somatosensory cortex model

SYNOPSIS ^

function out=DIVA_SomatosensoryCortex(varargin);

DESCRIPTION ^

 DIVA_SomatosensoryCortex Somatosensory cortex model

 This model computes the cortical representation of a somatosensory input and 
 its difference with the somatosensory target.

 DIVA_SomatosensoryCortex('init' [,SessionName]);          Initializes the module
 DIVA_SomatosensoryCortex('save' [,SessionName] );         Saves state
 DIVA_SomatosensoryCortex('exit');                         Exits the module (without saving)
 DIVA_SomatosensoryCortex(PropertyName [,PropertyValue] )  Reads and writes internal model
                                                           properties

 DIVA_SomatosensoryCortex('target',s2,'somatosensory',s1);
 The model computes the difference between the target signal s2 and the signal s1 and sends it
 to motor cortex (DIVA_MotorCortex). The somatosensory targets are slowly adapted (learning) to
 predict the associated somatosensory inputs.

 The signal s1 is a Sensory representation (see DIVA_Sensory) and the signal s2
 is an indexed categorical representation (see DIVA_SoundMap). The model stores
 weights, WeightsFromTargets used for the comparison between
 targets and current Sensory representation

 Current DIVA_Somatosensory properties are: (* requires re-initialization)
  *   delayToMotorCortex          : delay (in seconds) for signals to MotorCortex
      eps_learn                   : integration constant for somatosensory learning
      WeightsFromTargets          : Weights for target signals (somatosensory targets)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function out=DIVA_SomatosensoryCortex(varargin);
0002 % DIVA_SomatosensoryCortex Somatosensory cortex model
0003 %
0004 % This model computes the cortical representation of a somatosensory input and
0005 % its difference with the somatosensory target.
0006 %
0007 % DIVA_SomatosensoryCortex('init' [,SessionName]);          Initializes the module
0008 % DIVA_SomatosensoryCortex('save' [,SessionName] );         Saves state
0009 % DIVA_SomatosensoryCortex('exit');                         Exits the module (without saving)
0010 % DIVA_SomatosensoryCortex(PropertyName [,PropertyValue] )  Reads and writes internal model
0011 %                                                           properties
0012 %
0013 % DIVA_SomatosensoryCortex('target',s2,'somatosensory',s1);
0014 % The model computes the difference between the target signal s2 and the signal s1 and sends it
0015 % to motor cortex (DIVA_MotorCortex). The somatosensory targets are slowly adapted (learning) to
0016 % predict the associated somatosensory inputs.
0017 %
0018 % The signal s1 is a Sensory representation (see DIVA_Sensory) and the signal s2
0019 % is an indexed categorical representation (see DIVA_SoundMap). The model stores
0020 % weights, WeightsFromTargets used for the comparison between
0021 % targets and current Sensory representation
0022 %
0023 % Current DIVA_Somatosensory properties are: (* requires re-initialization)
0024 %  *   delayToMotorCortex          : delay (in seconds) for signals to MotorCortex
0025 %      eps_learn                   : integration constant for somatosensory learning
0026 %      WeightsFromTargets          : Weights for target signals (somatosensory targets)
0027 
0028 % Dependencies:
0029 %
0030 
0031 out=[];
0032 global DIVA_SomatosensoryCortex_data
0033 
0034 %%%%%%%%%%%%%%%% INITIALIZATION %%%%%%%%%
0035 %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 for indexargin=1:2:nargin,
0038   switch(varargin{indexargin}),
0039    case 'init',
0040     SessionFolder=strcat(DIVA('SessionFolder'),filesep);
0041     if nargin<indexargin+1 | isempty(varargin{indexargin+1}),
0042       initfile='';
0043     else,
0044       initfile=[SessionFolder,'Session_',varargin{indexargin+1},filesep,mfilename,'.mat'];
0045     end
0046     if isempty(initfile) | isempty(dir(initfile)),
0047       disp([mfilename, ' : Defining new session...']);
0048       DIVA_SomatosensoryCortex_data.params=struct(...
0049           'eps_learn',.3,...             % integration constant for somatosensory learning
0050           'delayToMotorCortex',.005,...
0051           'WeightsFromTargets',[]);      % Weights for target signals (somatosensory targets)
0052 
0053     else,
0054       data=load(initfile,'-mat');
0055       DIVA_SomatosensoryCortex_data.params=data.params;
0056     end
0057     DIVA_SomatosensoryCortex_data.params.nSensory = DIVA('Sensory','nSensory');
0058     DIVA_SomatosensoryCortex_data.params.TimeStep = DIVA('TimeStep');
0059     DIVA_SomatosensoryCortex_data.params.default_somatosensory = ...
0060         zeros(DIVA_SomatosensoryCortex_data.params.nSensory,1);
0061     DIVA_SomatosensoryCortex_data.params.current.target = [];
0062 
0063     % Parameter used to appropriately update the
0064     % WeightsFromTargets, see below
0065     DIVA_SomatosensoryCortex_data.params.current.somatoupdate = 0;
0066     out={'target','somatosensory'};
0067 
0068    case 'save',
0069     SessionFolder=strcat(DIVA('SessionFolder'),filesep);
0070     if nargin<indexargin+1,
0071       initfile=[SessionFolder,'Session_','default',filesep,mfilename,'.mat'];
0072     else,
0073       initfile=[SessionFolder,'Session_',varargin{indexargin+1},filesep,mfilename,'.mat'];
0074     end
0075     params=DIVA_SomatosensoryCortex_data.params;
0076     save(initfile,'params');
0077 
0078    case 'exit',
0079     clear DIVA_SomatosensoryCortex_data;
0080 
0081    case 'disp',
0082     disp(DIVA_SomatosensoryCortex_data.params);
0083     out=fieldnames(DIVA_SomatosensoryCortex_data.params);
0084 
0085     %%%%%%%%%%%%%%%% ACTION %%%%%%%%%%%%%%%%%
0086     %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%
0087 
0088    case 'target'
0089     % current somatosensory target projection
0090     DIVA_SomatosensoryCortex_data.params.current.target=varargin{indexargin+1};
0091     if ~nargout,
0092       DIVA('ModelStatePlot','SomatosensoryCortex','target');
0093     end
0094 
0095    case 'somatosensory'
0096     ntimepoints = DIVA('AuditoryCortexCategorical','ntimepoints');
0097     DIVA_SomatosensoryCortex_data.params.current.somatosensory = varargin{indexargin+1};
0098     if ~isempty(DIVA_SomatosensoryCortex_data.params.current.target),
0099       % initializes target if it does not exist
0100 
0101       % Need 'round' incoming target indices due to time-normalization
0102       % in AuditoryCortexCategorical
0103       idx = union(floor(DIVA_SomatosensoryCortex_data.params.current.target),...
0104                   ceil(DIVA_SomatosensoryCortex_data.params.current.target));
0105 
0106       % Add enough space to end of WeightsFromTargets for "new" target representations
0107       if max(idx)+ntimepoints>size(DIVA_SomatosensoryCortex_data.params.WeightsFromTargets,2),
0108         idxnew=size(DIVA_SomatosensoryCortex_data.params.WeightsFromTargets,2)+1:max(idx)+ntimepoints;
0109         DIVA_SomatosensoryCortex_data.params.WeightsFromTargets(:,idxnew) = ...
0110             DIVA_SomatosensoryCortex_data.params.default_somatosensory(:,ones(1,length(idxnew)));
0111       end
0112 
0113       % Get Current Target
0114       if length(idx)>1,
0115         DIVA_SomatosensoryCortex_data.params.current.targetsomatosensory = ...
0116             fastinterp1(idx,DIVA_SomatosensoryCortex_data.params.WeightsFromTargets(:,idx),...
0117                         DIVA_SomatosensoryCortex_data.params.current.target);
0118       else,
0119         DIVA_SomatosensoryCortex_data.params.current.targetsomatosensory = ...
0120             DIVA_SomatosensoryCortex_data.params.WeightsFromTargets(:,idx*ones(1,size(DIVA_SomatosensoryCortex_data.params.current.target,2)));
0121       end
0122 
0123       % Error computation, simple difference between targets and current configuration
0124       out = DIVA_SomatosensoryCortex_data.params.current.targetsomatosensory - ...
0125             DIVA_SomatosensoryCortex_data.params.current.somatosensory;
0126 
0127       if ~nargout,
0128         % Projects output to MotorCortex
0129         DIVA_SomatosensoryCortex_data.params.current.error=out;
0130         DIVA('MotorCortex',...
0131              'error_somatosensory',...
0132              DIVA_SomatosensoryCortex_data.params.current.error,...
0133              DIVA_SomatosensoryCortex_data.params.delayToMotorCortex);
0134 
0135         % Learning new Somatosensory Weights
0136         if DIVA_SomatosensoryCortex_data.params.eps_learn > 0,
0137           % Find Weights associated with input
0138           targettolearn = DIVA('SomatosensoryCortex','target',[],...
0139                                DIVA_SomatosensoryCortex_data.params.TimeStep*...
0140                                (0:size(DIVA_SomatosensoryCortex_data.params.current.target,2)));
0141           if(targettolearn(end)<targettolearn(end-1))
0142             targettolearn(end)=0;
0143           end
0144           if ~all(targettolearn(1:end-1)>0),
0145             disp('DIVA_SomatosensoryCortex: warning, receiving empty target');
0146           else,
0147             idxvalid = 1:length(targettolearn)-1;
0148             idx=floor(targettolearn(idxvalid(1))):floor(targettolearn(idxvalid(end)));
0149             idx = idx(find(idx>0));
0150             
0151             DIVA_SomatosensoryCortex_data.temp.targettolearn=targettolearn;
0152             DIVA_SomatosensoryCortex_data.temp.parser=diff(floor(targettolearn));
0153             
0154             % Temporary weight update, need to find average update over all instances
0155             % of target indicies per training trial
0156             % For instance, target index sequence might be [1 1.3 1.6 1.9 2.0,...]
0157             % The round() command above creates a sequence [1 1 2 2 2,...], resulting in
0158             % over training of index 2 compared to index 1.  The imaginary part of
0159             % somatoupdate counts the number of consecutive input indicies for use in an
0160             % averaging procedure
0161             if(~DIVA('BlockMode'))
0162               DIVA_SomatosensoryCortex_data.params.current.somatoupdate=...
0163                   DIVA_SomatosensoryCortex_data.params.current.somatoupdate * ...
0164                   (1-DIVA_SomatosensoryCortex_data.params.eps_learn) + ...
0165                   DIVA_SomatosensoryCortex_data.params.current.somatosensory * ...
0166                   DIVA_SomatosensoryCortex_data.params.eps_learn + sqrt(-1);
0167             
0168               if(diff(floor(targettolearn))),
0169                 idx = min(floor(targettolearn(find(targettolearn>0)))):max(ceil(targettolearn(find(targettolearn>0))));
0170                 idx = idx(find(idx>0));
0171                 if(diff(floor(targettolearn))<0)
0172                   idx = idx;
0173                 else
0174                   idx = idx(find(idx<floor(targettolearn(end))));
0175                 end
0176                 
0177                 DIVA_SomatosensoryCortex_data.params.WeightsFromTargets(:,idx)=...
0178                     DIVA_SomatosensoryCortex_data.params.WeightsFromTargets(:,idx)+...
0179                     repmat(real(DIVA_SomatosensoryCortex_data.params.current.somatoupdate)./...
0180                            imag(DIVA_SomatosensoryCortex_data.params.current.somatoupdate),...
0181                            1,length(idx));
0182                 DIVA_SomatosensoryCortex_data.params.current.somatoupdate=...
0183                     zeros(DIVA_SomatosensoryCortex_data.params.nSensory,1);
0184               end
0185             else
0186               idx=unique(floor(targettolearn(find(targettolearn>0))));
0187               blockBound = diff(floor(targettolearn));
0188               for n=1:length(idx),
0189                 if(blockBound(max(find(floor(targettolearn)==idx(n))))>0)                  
0190                   targetIdx = ...
0191                       idx(n):idx(n)+blockBound(max(find(floor(targettolearn)==idx(n))))-1;
0192                 else, %end of block
0193                   targetIdx = idx(n):idx(n)+1;
0194                 end
0195                 DIVA_SomatosensoryCortex_data.params.WeightsFromTargets(:,targetIdx) = ...
0196                     DIVA_SomatosensoryCortex_data.params.WeightsFromTargets(:,targetIdx) * ...
0197                     (1-DIVA_SomatosensoryCortex_data.params.eps_learn) + ...
0198                     DIVA_SomatosensoryCortex_data.params.eps_learn * ...
0199                     repmat(...
0200                         sum(DIVA_SomatosensoryCortex_data.params.current.somatosensory(:,find(floor(targettolearn)==idx(n))),2) / ...
0201                         length(find(floor(targettolearn)==idx(n))),...
0202                         1,length(targetIdx));
0203               end
0204             end
0205           end
0206         end
0207       end
0208       DIVA_SomatosensoryCortex_data.params.current.target=[];
0209     end
0210     if ~nargout, % try to plot model state information
0211       DIVA('ModelStatePlot','SomatosensoryCortex','somatosensory');
0212       DIVA('GUI','other_weights','somatosensory');
0213       DIVA('GUI','other_weights','somatosensory_weight');
0214     end
0215 
0216    otherwise,
0217     if isfield(DIVA_SomatosensoryCortex_data.params,varargin{indexargin}),
0218       if indexargin==nargin,
0219         out=DIVA_SomatosensoryCortex_data.params.(varargin{indexargin});
0220       else,
0221         DIVA_SomatosensoryCortex_data.params.(varargin{indexargin})=varargin{indexargin+1};
0222       end
0223     else,
0224       warning('DIVA_SomatosensoryCortex: wrong argument');
0225     end
0226   end
0227 end
0228

Generated on Tue 27-Mar-2007 12:06:24 by m2html © 2003