Home > vbmeg > functions > estimation > bayes > vb_set_vb_parm.m

vb_set_vb_parm

PURPOSE ^

VB estimation parameteres 'vb_parm' are set based on 'bayes_parm'

SYNOPSIS ^

function vb_parm = vb_set_vb_parm(bayes_parm, B, Njact, Njall, v0, sx0)

DESCRIPTION ^

 VB estimation parameteres 'vb_parm' are set based on 'bayes_parm'

 vb_parm = vb_set_vb_parm(bayes_parm, B, [], Njall)
 vb_parm = vb_set_vb_parm(bayes_parm, B, Njact, Njall)
 vb_parm = vb_set_vb_parm(bayes_parm, B, Njact, Njall, [], sx0)
 vb_parm = vb_set_vb_parm(bayes_parm, B, Njact, Njall, v0, sx0)

 --- input
 B : MEG signal
 Njact : # of focal current
 Njall : # of global current
 v0  : baseline activity
 sx0 : noise variance

 [history]
 2005/08/22 O. Yamashita ver.30b 
 2006/08/04 M. Sato
 2011-11-16 taku-y
  [major] Offset of time index was corrected. 

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_parm = vb_set_vb_parm(bayes_parm, B, Njact, Njall, v0, sx0)
0002 % VB estimation parameteres 'vb_parm' are set based on 'bayes_parm'
0003 %
0004 % vb_parm = vb_set_vb_parm(bayes_parm, B, [], Njall)
0005 % vb_parm = vb_set_vb_parm(bayes_parm, B, Njact, Njall)
0006 % vb_parm = vb_set_vb_parm(bayes_parm, B, Njact, Njall, [], sx0)
0007 % vb_parm = vb_set_vb_parm(bayes_parm, B, Njact, Njall, v0, sx0)
0008 %
0009 % --- input
0010 % B : MEG signal
0011 % Njact : # of focal current
0012 % Njall : # of global current
0013 % v0  : baseline activity
0014 % sx0 : noise variance
0015 %
0016 % [history]
0017 % 2005/08/22 O. Yamashita ver.30b
0018 % 2006/08/04 M. Sato
0019 % 2011-11-16 taku-y
0020 %  [major] Offset of time index was corrected.
0021 %
0022 % Copyright (C) 2011, ATR All Rights Reserved.
0023 % License : New BSD License(see VBMEG_LICENSE.txt)
0024 
0025 switch nargin
0026     case 1
0027         help vb_set_vb_parm;
0028     case 2
0029         Njact = [];
0030         Njall = [];
0031         v0  = 1;
0032         sx0 = 1;
0033     case 3 
0034         Njall = [];
0035         v0  = 1;
0036         sx0 = 1;
0037     case 4
0038         v0  = 1;
0039         sx0 = 1;
0040     case 5
0041         sx0 = 1;
0042 end
0043 
0044 if isempty(v0)
0045     v0  = 1;
0046 end
0047 if isempty(sx0)
0048     sx0 = 1;
0049 end
0050 
0051 if ~isfield(bayes_parm, 'Ta0')
0052     bayes_parm.Ta0 = 0; % No fMRI bias
0053 end
0054 
0055 vb_parm.Ntrain   = bayes_parm.Ntrain;
0056 vb_parm.Nskip     = bayes_parm.skip;
0057 vb_parm.a_min     = bayes_parm.a_min;
0058 vb_parm.a_max     = bayes_parm.a_max;
0059 vb_parm.Fdmin     = bayes_parm.Fdmin;
0060 
0061 vb_parm.update_v  = bayes_parm.update_v;
0062 vb_parm.update_sx = bayes_parm.update_sx;
0063 
0064 if isfield(bayes_parm, 'Npre_train')
0065     % Number of iteration using original VB-update rule
0066     % for stable estimation
0067     vb_parm.Npre_train = bayes_parm.Npre_train;
0068 else
0069     vb_parm.Npre_train = 0;
0070 end
0071 
0072 if isfield(bayes_parm,'cont_pr'), 
0073     vb_parm.cont_pr = bayes_parm.cont_pr;
0074 else 
0075     vb_parm.cont_pr = 0; 
0076 end
0077 
0078 
0079 % fields must be set before estimation
0080 vb_parm.Nvact = [];        % number of vertex points in focal window
0081 vb_parm.Njact = [];        % number of current parameters in focal window
0082 vb_parm.Norient = [];      % number of dipole orientation (1,2,3)
0083 vb_parm.Norient_var = [];  % number of orientation to be estimated
0084 vb_parm.Nsession = [];     % number of session
0085 vb_parm.Njall = [];        % number of currents parameters in global window
0086 vb_parm.Nvall = [];        % number of vertex points in global window
0087 vb_parm.Norient_all = [];  % number of dipole orientation in global window
0088 vb_parm.Ntrials = [];      % number of trials in each session
0089 vb_parm.Nsensors = [];     % number of meg sensors in each session
0090 vb_parm.Tsample = [];      % number of total time points
0091 vb_parm.Twindow = [];      % start and end time index of time windows
0092 vb_parm.Nwindow = [];      % number of time windows
0093 vb_parm.sx0 = [];          % initial value of observation noise variance
0094 vb_parm.v0  = [];          % initial value of global window variance
0095 vb_parm.Tv0 = [];          % confidence parameter of global window variance
0096 vb_parm.a0 = [];           % initial value of focal window variance
0097 vb_parm.Ta0 = [];          % confidence parameter of focal window variance
0098 
0099 vb_parm = set_session(vb_parm, B);
0100 vb_parm = set_twin(bayes_parm, vb_parm);
0101 vb_parm = set_global(bayes_parm, vb_parm, Njall);
0102 vb_parm = set_focal(bayes_parm, vb_parm, Njact);
0103 
0104 vb_parm = set_prior_def(bayes_parm,vb_parm,v0,sx0);
0105 
0106 check_bayes_parm(bayes_parm,vb_parm);
0107 
0108 return
0109 
0110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0111 %%
0112 %% inner functions
0113 %%
0114 
0115 %%%%% session, senosors, trials
0116 function [vb_parm] = set_session(vb_parm,B)
0117 Nsession = length(B);
0118 for n = 1: length(B)
0119    [Nsensors(n),tmp,Ntrials(n)]  = size(B{n});
0120 end
0121 vb_parm.Nsession = Nsession;
0122 vb_parm.Ntrials = Ntrials;
0123 vb_parm.Nsensors = Nsensors;
0124 
0125 return
0126 
0127 %%%%% time window
0128 function [vb_parm] = set_twin(bayes_parm,vb_parm)
0129 Tsample = bayes_parm.twin_meg(2) - bayes_parm.twin_meg(1) + 1;
0130 
0131 % offset
0132 if length(bayes_parm.Tnext) > 1, 
0133     Tnext = bayes_parm.Tnext-bayes_parm.twin_meg(1)+1;
0134 elseif length(bayes_parm.Tnext) == 1
0135     Tnext = bayes_parm.Tnext;
0136 end
0137 
0138 Twindow = vb_calc_timewindow(Tsample,bayes_parm.Tperiod,Tnext);
0139 vb_parm.Tsample = Tsample;
0140 vb_parm.Twindow = Twindow;
0141 vb_parm.Nwindow = size(Twindow,1);
0142 
0143 return
0144 
0145 %%%%% global window parameters
0146 function [vb_parm] = set_global(bayes_parm,vb_parm,Njall)
0147 [basis,L]=vb_load_basis(bayes_parm.basisfile_global{1});
0148 
0149 vb_parm.Norient_all = L;
0150 
0151 if ~isempty(Njall)
0152     vb_parm.Njall = Njall;
0153     vb_parm.Nvall = Njall/L;
0154 else
0155     vb_parm.Njall = 0;
0156     vb_parm.Nvall = 0;
0157 end
0158 
0159 return
0160 
0161 %%%%% focal window parameters (area file)
0162 function [vb_parm] = set_focal(bayes_parm,vb_parm,Njact)
0163 [tmp,L]=vb_load_basis(bayes_parm.basisfile{1});
0164 
0165 vb_parm.Norient = L;
0166 
0167 if ~isempty(Njact)
0168     vb_parm.Njact = Njact;
0169     vb_parm.Nvact = Njact/L;
0170 else
0171     vb_parm.Njact = 0;
0172     vb_parm.Nvact = 0;
0173 end
0174 
0175 return
0176 
0177 %%%%% Default prior parameter
0178 function    vb_parm = set_prior_def(bayes_parm,vb_parm,v0,sx0)
0179 
0180 if ~isfield(bayes_parm,'soft_mode'),
0181     vb_parm.soft_mode = 0;
0182 else
0183     vb_parm.soft_mode = bayes_parm.soft_mode;
0184 end
0185 
0186 if bayes_parm.variance_orientation == ON 
0187     vb_parm.Norient_var = vb_parm.Norient;
0188     
0189     % 接線方向分散 = sin( tan_var * 平均法線方向からの角度平均) <= var_max
0190     % tangential variance coefficient
0191     if isfield(bayes_parm,'tan_var')
0192         vb_parm.tan_var = bayes_parm.tan_var;
0193     else
0194         vb_parm.tan_var = 1;
0195     end
0196     
0197     % tangential variance max
0198     if isfield(bayes_parm,'var_max')
0199         vb_parm.var_max = bayes_parm.var_max;
0200     else
0201         vb_parm.var_max = 1/sqrt(2);
0202     end
0203 else
0204     vb_parm.Norient_var = 1;
0205 end
0206 
0207 vb_parm.sx0 = sx0;
0208 
0209 vb_parm.v0  = v0 ;
0210 vb_parm.a0  = v0;
0211 
0212 vb_parm.Tv0 = bayes_parm.Tv0;
0213 vb_parm.Ta0 = bayes_parm.Ta0;
0214 
0215 return
0216 
0217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0218 %%%%% Check bayes_parm in the case of soft normal constraint %%%%%%
0219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0220 function    result = check_bayes_parm(bayes_parm,vb_parm)
0221 
0222 result = FAILURE;
0223 
0224 % orientation estimate with soft constraint
0225 if isfield(bayes_parm,'soft_mode') & bayes_parm.soft_mode == 1,
0226     
0227     if bayes_parm.variance_orientation == OFF; 
0228         fprintf('In the case of soft constraint mode\n')
0229         error('variance_orientation should be ON');
0230     end
0231     
0232     if vb_parm.Norient ~= 3 | vb_parm.Norient_var ~= 3;
0233         fprintf('In the case of soft constraint mode\n')
0234         error('Norient should be 3 ');
0235     end
0236     
0237 %    if ~isempty(bayes_parm.reduce) & bayes_parm.reduce ~= 1,
0238 %        error('bayes_parm.reduce should be empty ');
0239 %    end
0240     
0241 end
0242 
0243 
0244 result = SUCCESS;
0245 
0246 return

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005