0001 function vb_parm = vb_set_vb_parm(bayes_parm, B, Njact, Njall, v0, sx0)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
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;
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
0066
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
0080 vb_parm.Nvact = [];
0081 vb_parm.Njact = [];
0082 vb_parm.Norient = [];
0083 vb_parm.Norient_var = [];
0084 vb_parm.Nsession = [];
0085 vb_parm.Njall = [];
0086 vb_parm.Nvall = [];
0087 vb_parm.Norient_all = [];
0088 vb_parm.Ntrials = [];
0089 vb_parm.Nsensors = [];
0090 vb_parm.Tsample = [];
0091 vb_parm.Twindow = [];
0092 vb_parm.Nwindow = [];
0093 vb_parm.sx0 = [];
0094 vb_parm.v0 = [];
0095 vb_parm.Tv0 = [];
0096 vb_parm.a0 = [];
0097 vb_parm.Ta0 = [];
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
0113
0114
0115
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
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
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
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
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
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
0190
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
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
0219
0220 function result = check_bayes_parm(bayes_parm,vb_parm)
0221
0222 result = FAILURE;
0223
0224
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
0238
0239
0240
0241 end
0242
0243
0244 result = SUCCESS;
0245
0246 return