Calculate inverse filter for current estimation. (VBMEG public function) [syntax] [VBfilt,Jinfo,bayes_parm] = vb_job_vbfilter(proj_root,filt_parm) [VBfilt,Jinfo,bayes_parm] = vb_job_vbfilter(filt_parm) [input] proj_root: <optional> <<string>> VBMEG project root directory. filt_parm: <<struct>> Parameters for calculation of inverse filter. --- fields of filt_parm bayesfile : <<string>> Current variance file (.bayes.mat). filterfile: <optional> <<string>> inverse filter file (.vbfilt.mat). If this field is not defined, inverse filter file is not saved. basisfile : <optional> <<string>> If this field is given, leadfield file of this field is used for calculation of inverse filter. area_key : <optional> <<string>> Identifier of interested area. If 'area_key' is empty or not given, inverse filter for the (focal) active region are calculated. When using vb_calc_current.m, you must NOT to set this parameter. areafile : <optional> <<string>> Cortical area file (.area.mat). --- [output] If input parameter 'filterfile' is given, the following variables are saved into the file with filename 'filterfile'. VBfilt : <<struct>> Inverse filter and related variables. --- fileds of VBfilt KW : Inverse filter (Njact,Nch,Nwindow,Ntask) W : <<matrix>> Spatial smoothing matrix of focal window. ix_act : <<vector>> Vertex index of Z-current. ix_act_ex: <<vector>> Vertex index of J-current. L : <<int>> Number of current direction. a : Current variance (Njact,Nwindow,Ntask) sx : Observation noise variance (Nwindow,Ntask) Cov : Normalized sensor noise covariance matrix {Ntask}(Nch,Nch) Hj : Model entropy (Nwindow,Ntask) SB_cov : posterior sensor covariance matrix (Nch,Nch,Nwindow,Ntask) --- Jinfo : <<struct>> Information of cortical current. --- fileds of Jinfo Lact : Number of current direction. ix_act : Vertex index corresponding to active current Zact. ix_act_ex : Vertex index corresponding to active current Jact. Wact : Spatial smoothing matrix of focal window. channel_id : Active channel ID for VB-filter calculation. channel_name: Active channel name for VB-filter calculation. --- bayes_parm: <<struct>> Parameters for variational Bayes method (same with the input variable of vb_job_vb.m). [history] 2008-08-01 M. Sato 2009-08-21 M. Sato 2010-06-21 Taku Yoshioka Minor change (verbose level support) Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [VBfilt,Jinfo,bayes_parm] = vb_job_vbfilter(varargin) 0002 % Calculate inverse filter for current estimation. 0003 % (VBMEG public function) 0004 % 0005 % [syntax] 0006 % [VBfilt,Jinfo,bayes_parm] = vb_job_vbfilter(proj_root,filt_parm) 0007 % [VBfilt,Jinfo,bayes_parm] = vb_job_vbfilter(filt_parm) 0008 % 0009 % [input] 0010 % proj_root: <optional> <<string>> VBMEG project root directory. 0011 % filt_parm: <<struct>> Parameters for calculation of inverse filter. 0012 % --- fields of filt_parm 0013 % bayesfile : <<string>> Current variance file (.bayes.mat). 0014 % filterfile: <optional> <<string>> inverse filter file (.vbfilt.mat). If 0015 % this field is not defined, inverse filter file is not 0016 % saved. 0017 % basisfile : <optional> <<string>> If this field is given, leadfield 0018 % file of this field is used for calculation of inverse 0019 % filter. 0020 % area_key : <optional> <<string>> Identifier of interested area. If 0021 % 'area_key' is empty or not given, inverse filter for the 0022 % (focal) active region are calculated. When using 0023 % vb_calc_current.m, you must NOT to set this parameter. 0024 % areafile : <optional> <<string>> Cortical area file (.area.mat). 0025 % --- 0026 % 0027 % [output] 0028 % If input parameter 'filterfile' is given, the following variables are 0029 % saved into the file with filename 'filterfile'. 0030 % 0031 % VBfilt : <<struct>> Inverse filter and related variables. 0032 % --- fileds of VBfilt 0033 % KW : Inverse filter (Njact,Nch,Nwindow,Ntask) 0034 % W : <<matrix>> Spatial smoothing matrix of focal window. 0035 % ix_act : <<vector>> Vertex index of Z-current. 0036 % ix_act_ex: <<vector>> Vertex index of J-current. 0037 % L : <<int>> Number of current direction. 0038 % a : Current variance (Njact,Nwindow,Ntask) 0039 % sx : Observation noise variance (Nwindow,Ntask) 0040 % Cov : Normalized sensor noise covariance matrix {Ntask}(Nch,Nch) 0041 % Hj : Model entropy (Nwindow,Ntask) 0042 % SB_cov : posterior sensor covariance matrix (Nch,Nch,Nwindow,Ntask) 0043 % --- 0044 % 0045 % Jinfo : <<struct>> Information of cortical current. 0046 % --- fileds of Jinfo 0047 % Lact : Number of current direction. 0048 % ix_act : Vertex index corresponding to active current Zact. 0049 % ix_act_ex : Vertex index corresponding to active current Jact. 0050 % Wact : Spatial smoothing matrix of focal window. 0051 % channel_id : Active channel ID for VB-filter calculation. 0052 % channel_name: Active channel name for VB-filter calculation. 0053 % --- 0054 % 0055 % bayes_parm: <<struct>> Parameters for variational Bayes method (same 0056 % with the input variable of vb_job_vb.m). 0057 % 0058 % [history] 0059 % 2008-08-01 M. Sato 0060 % 2009-08-21 M. Sato 0061 % 2010-06-21 Taku Yoshioka 0062 % Minor change (verbose level support) 0063 % 0064 % Copyright (C) 2011, ATR All Rights Reserved. 0065 % License : New BSD License(see VBMEG_LICENSE.txt) 0066 0067 % 0068 % Constants 0069 % 0070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0071 const = vb_define_verbose; 0072 VERBOSE_LEVEL_NOTICE = const.VERBOSE_LEVEL_NOTICE; 0073 0074 % 0075 % Check input arguments 0076 % 0077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0078 if length(varargin) == 1 0079 proj_root = []; 0080 filt_parm = varargin{1}; 0081 elseif length(varargin) == 2 0082 proj_root = varargin{1}; 0083 filt_parm = varargin{2}; 0084 else 0085 error('Error: invalid usage of job_vbfilter.'); 0086 end 0087 0088 proj_root = vb_rm_trailing_slash(proj_root); 0089 0090 % 0091 % Filename of inverse filter file (.vbfilt.mat) 0092 % 0093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0094 if ~isfield(filt_parm,'filterfile') | isempty(filt_parm.filterfile) 0095 if isfield(filt_parm,'currfile') & ~isempty(filt_parm.currfile), 0096 ix_ext = findstr(filt_parm.currfile, '.curr.mat'); 0097 filterfile = [filt_parm.currfile(1:ix_ext-1) '.vbfilt.mat']; 0098 else 0099 filterfile = []; 0100 end 0101 else 0102 filterfile = filt_parm.filterfile; 0103 end 0104 0105 if ~isempty(proj_root) & ~isempty(filterfile), 0106 filterfile = [proj_root filesep filterfile]; 0107 end 0108 0109 % 0110 % Inverse filter calculation 0111 % 0112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0113 [VBfilt, Jinfo, bayes_parm, vb_parm] ... 0114 = vbmeg_current_filter_z(proj_root, filt_parm); 0115 VBfilt.L = Jinfo.Lact; 0116 VBfilt.W = Jinfo.Wact; 0117 VBfilt.ix_act = Jinfo.ix_act; 0118 VBfilt.ix_act_ex = Jinfo.ix_act_ex; 0119 0120 ch_info = vb_load_channel_info([proj_root '/' bayes_parm.megfile{1}]); 0121 0122 Jinfo.channel_id = ch_info.ID ; % channel ID 0123 Jinfo.channel_name = ch_info.Name; % channel name 0124 0125 % 0126 % Save inverse filter file 0127 % 0128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0129 if ~isempty(filterfile), 0130 vb_disp(sprintf('--- Save VB-filter file:\n %s',filterfile), ... 0131 VERBOSE_LEVEL_NOTICE); 0132 vb_fsave(filterfile,'VBfilt','Jinfo','bayes_parm','vb_parm'); 0133 end 0134 0135 % 0136 % VBMEG project file 0137 % 0138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0139 proj_file = get_project_filename; 0140 if ~isempty(proj_file) 0141 project_file_mgr('load', proj_file); 0142 project_file_mgr('add', 'current_parm', parm); 0143 end 0144 0145 return;