Home > . > DIVA_ForwardModel.m

DIVA_ForwardModel

PURPOSE ^

DIVA_ForwardModel DIVA module Forward Model

SYNOPSIS ^

function out=DIVA_ForwardModel(varargin);

DESCRIPTION ^

 DIVA_ForwardModel DIVA module Forward Model
 The ForwardModel is defined by an HRBF trained on random
 vocaltract 'Babbling'.  

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

 s=DIVA_ForwardModel('motor',m);                     Read-out values from forward model. m 
                                                      is the motor command, and s is a 
                                                      cell array containing the associated 
                                                      sound and sensory percepts.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function out=DIVA_ForwardModel(varargin);
0002 % DIVA_ForwardModel DIVA module Forward Model
0003 % The ForwardModel is defined by an HRBF trained on random
0004 % vocaltract 'Babbling'.
0005 %
0006 % DIVA_ForwardModel('init' [,SessionName]);           Initializes the module
0007 % DIVA_ForwardModel('save' [,SessionName] );          Saves state
0008 % DIVA_ForwardModel('exit');                          Exits the module (without saving)
0009 % DIVA_ForwardModel(PropertyName [,PropertyValue] )   Reads and writes internal model properties
0010 %
0011 % s=DIVA_ForwardModel('motor',m);                     Read-out values from forward model. m
0012 %                                                      is the motor command, and s is a
0013 %                                                      cell array containing the associated
0014 %                                                      sound and sensory percepts.
0015 
0016 % Dependencies:
0017 %
0018 
0019 out=[];
0020 global DIVA_ForwardModel_data
0021 DIVA_ForwardModel_data.current.sound=[];
0022 DIVA_ForwardModel_data.current.sensory=[];
0023 DIVA_ForwardModel_data.current.motor=[];
0024 somethingtoexecute=0;
0025 
0026 for indexargin=1:2:nargin,  
0027   switch(varargin{indexargin}),
0028    case 'init',
0029     SessionFolder=strcat(DIVA('SessionFolder'),filesep);
0030     if nargin<indexargin+1 | isempty(varargin{indexargin+1}), 
0031       initfile=''; 
0032     else, 
0033       initfile=[SessionFolder,'Session_',varargin{indexargin+1},filesep,mfilename,'.mat']; 
0034     end
0035     
0036     if isempty(initfile) | isempty(dir(initfile)),
0037       disp([mfilename, ' : Defining new session...']);
0038       % INITIALIZES INTERNAL MODULE PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0039       DIVA_ForwardModel_data.params=struct(...
0040           'MaedaSpread',DIVA('VocalTract','MaedaSpread'),...
0041           'net',load('trainednet4000_040504')); % RBF of stored articulatory
0042                                                 % configurations and auditory consequences
0043 
0044       % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0045     
0046       name=which(mfilename);
0047       if ~isempty(dir([name(1:end-2),'.mat'])), 
0048         Data = load([name(1:end-2),'.mat']);
0049       else 
0050         Data = struct('paramsSound',[],'paramsSensory',[]); 
0051       end
0052       DIVA_ForwardModel_data.params.Data = Data;
0053       clear Data 
0054     else,
0055       data = load(initfile,'-mat');
0056       DIVA_ForwardModel_data.params = data.params;
0057     end
0058     
0059     % INITIALIZES OTHER (TEMPORAL) PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0060     DIVA_ForwardModel_data.current=struct(...
0061         'motor',[]);
0062     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0063     
0064     % LIST OF MODULE CHANNELS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0065     out={'motor'};
0066     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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_ForwardModel_data.params;
0076     save(initfile,'params'); 
0077     
0078    case 'exit',
0079     clear DIVA_ForwardModel_data;
0080     % CODE FOR CLEARING MEMORY OR THE LIKE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0081     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0082     
0083    case 'disp',
0084     disp(DIVA_ForwardModel_data.params);
0085     out=fieldnames(DIVA_ForwardModel_data.params);
0086     
0087    case 'motor',
0088     if ~nargout,
0089       DIVA_ForwardModel_data.current.motor = varargin{indexargin+1};
0090     else, % reads-out internalmodel value(s)
0091       % Compute Motor to Auditory transformation
0092       
0093       Ninput = size(varargin{indexargin+1},2);
0094       for idx = 1:Ninput,
0095         out(:,idx) = simrbf(DIVA_ForwardModel_data.params.net.net,...
0096                             varargin{indexargin+1}(:,idx));
0097       end      
0098     end
0099             
0100    otherwise,
0101     if isfield(DIVA_ForwardModel_data.params,varargin{indexargin}),
0102       if indexargin==nargin, 
0103         out=DIVA_ForwardModel_data.params.(varargin{indexargin}); 
0104       else, 
0105         DIVA_ForwardModel_data.params.(varargin{indexargin})=varargin{indexargin+1}; 
0106       end
0107     else, 
0108       warning('DIVA_ForwardModel: wrong argument'); 
0109     end
0110   end
0111 end
0112 
0113

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