Skip to content

Commit

Permalink
allow group options for MFX (DisplayWin, verbose, TolFun, MaxInter) (M…
Browse files Browse the repository at this point in the history
  • Loading branch information
awiehler authored and lionel-rigoux committed Jan 25, 2018
1 parent 77876b5 commit c32ac71
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
47 changes: 35 additions & 12 deletions VBA_MFX.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [p_sub,o_sub,p_group,o_group] = VBA_MFX(y,u,f_fname,g_fname,dim,options,priors_group)
function [p_sub,o_sub,p_group,o_group] = VBA_MFX(y,u,f_fname,g_fname,dim,options,priors_group, options_group)
% VB treatment of mixed-effects analysis
% function [posterior,out] = VBA_MFX(y,u,f_fname,g_fname,dim,options)
% This function approaches model inversion from an empirical Bayes
Expand All @@ -22,6 +22,12 @@
% the moments of the parent population distributions (for observation and
% evolution parameters, as well as for initial conditions, if
% applicable). See p_group subfields below.
% - options_group: Structure containing options for MFX. Fields:
% .TolFun - Minimum change in the free energy, default is 2e-2
% .MaxIter - Maximum number of iterations, default is 16
% .DisplayWin - Do we want a graphical output?
% .verbose - Do we want verbose text output?
%
% OUT:
% - p_sub/o_sub: nsx1 cell arrays containng the VBA outputs of the
% within-subject model inversions.
Expand Down Expand Up @@ -51,16 +57,33 @@
% (initialization).



ns = length(y); % # subjects
dim.ns = ns;

if exist('options_group', 'var')
opt = options_group;
else
opt = [];
end

opt.dim = dim;
opt.g_fname = g_fname;
opt.f_fname = f_fname;
opt.verbose = 1;
opt.TolFun = 1e-2;
opt.MaxIter = 16;
o_group.tStart = tic;


% set default options
opt = VBA_check_struct(opt, ...
'TolFun' , 2e-2 , ... % Minimum change in the free energy
'MaxIter' , 16 , ... % Maximum number of iterations
'DisplayWin' , 1 , ... % VB display window
'verbose' , 1 ... % matlab window messages
) ;

o_group.options = opt;
o_group.tStart = tic; % start time


[o_group.options] = VBA_displayMFX([],[],[],o_group,1,'off');


Expand All @@ -76,23 +99,23 @@
'SigmaPhi' , eye(dim.n_phi) , ... % prior variance on population average
'a_vPhi' , ones(dim.n_phi,1) , ... % prior shape param on population variance
'b_vPhi' , ones(dim.n_phi,1) ... % prior rate param on population variance
) ;
) ;
end
if dim.n_theta > 0
priors_group = VBA_check_struct(priors_group, ...
'muTheta' , zeros(dim.n_theta,1) , ...
'SigmaTheta' , eye(dim.n_theta) , ...
'a_vTheta' , ones(dim.n_theta,1) , ...
'b_vTheta' , ones(dim.n_theta,1) ...
) ;
) ;
end
if dim.n >0
priors_group = VBA_check_struct(priors_group, ...
priors_group = VBA_check_struct(priors_group, ...
'muX0' , zeros(dim.n,1) , ...
'SigmaX0' , eye(dim.n) , ...
'a_vX0' , ones(dim.n,1) , ...
'b_vX0' , ones(dim.n,1) ...
) ;
) ;
end
opt.priors_group = priors_group;

Expand Down Expand Up @@ -144,7 +167,7 @@
if opt.verbose
fprintf(1,'%6.2f %%',0)
end
kernelSize0 = 0; % max lag of volterra kernel
kernelSize0 = 0; % max lag of volterra kernel
for i=1:ns
if opt.verbose
fprintf(1,repmat('\b',1,8))
Expand Down Expand Up @@ -321,7 +344,7 @@

o_group.F = F;
o_group.it = it;

if it == 1
% store initial within-subject VBA model inversion
o_group.initVBA.p_sub = p_sub;
Expand All @@ -330,7 +353,7 @@
else
[o_group.options] = VBA_displayMFX(p_sub,o_sub,p_group,o_group);
end

dF = F(it+1) - F(it);
if abs(dF) <= opt.TolFun || it >= opt.MaxIter
stop = 1;
Expand Down
6 changes: 6 additions & 0 deletions VBA_displayMFX.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

options = o_group.options;
try;init;catch;init=0;end

if ~options.DisplayWin
return
end

try;within;catch;within='on';end


if init
pos0 = get(0,'screenSize');
pos = [0.51*pos0(3),0.05*pos0(4),0.45*pos0(3),0.9*pos0(4)];
Expand Down

0 comments on commit c32ac71

Please sign in to comment.