From 76c11747826efe7f603d3ba187a3b8f1a9888ee0 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 26 May 2020 13:08:53 +0100 Subject: [PATCH 1/3] uncommented multisession fixed.X0 --- core/VBA_multisession_expand.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/VBA_multisession_expand.m b/core/VBA_multisession_expand.m index ac397d5c..18f694f5 100644 --- a/core/VBA_multisession_expand.m +++ b/core/VBA_multisession_expand.m @@ -69,11 +69,11 @@ % syntactic sugar handling if isequal(fixed.theta ,'all'), fixed.theta = 1:dim.n_theta; end if isequal(fixed.phi ,'all'), fixed.phi = 1:dim.n_phi; end -%if isequal(fixed.X0 ,'all'), fixed.X0 = 1:dim.n; end +if isequal(fixed.X0 ,'all'), fixed.X0 = 1:dim.n; end theta_multi = setdiff(theta_multi,fixed.theta); phi_multi = setdiff(phi_multi ,fixed.phi ); -%X0_multi = setdiff(X0_multi ,fixed.X0 ); +X0_multi = setdiff(X0_multi ,fixed.X0 ); % = expand (duplicate) priors and dimensions to cover all sessions priors = options.priors; From 16c81ec1741d8ed39d5b11aafcb3eedbc02389a3 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 5 Jun 2020 14:38:34 +0100 Subject: [PATCH 2/3] further X0 multisession fix --- core/VBA_odeLim.m | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/core/VBA_odeLim.m b/core/VBA_odeLim.m index 0f0fdc5a..7002bfaa 100644 --- a/core/VBA_odeLim.m +++ b/core/VBA_odeLim.m @@ -29,6 +29,7 @@ options = in.old.options; dim = in.old.dim; + % Check whether the system is at initial state if isempty(t) t = 1; @@ -38,10 +39,34 @@ else xt = options.priors.muX0; end -else +else t = t+1; end + +multiSess = zeros(sum(options.multisession.split),1); +idx = cumsum(options.multisession.split)+1; +idx = [1, idx(1:end-1)]; +multiSess(idx) = 1; + +if multiSess(t) + if t ~=1 + for ii = 1:size(options.inG{2}.indices.X0,1) + dxdTheta(:,ii) = 0; + if options.inG{2}.indices.X0(ii,find(idx==t)) == ii + if options.updateX0 + temp = P(dim.n_phi+dim.n_theta+1:end); + xt(ii) = temp(ii); + else + xt(ii) = options.priors.muX0(ii); + end + end + end + end +end + + + % apply ODE forward step: [xt,dF_dX,dF_dP] = VBA_evalFun('f',xt,Theta,ut,options,dim,t); [gx,dG_dX,dG_dP] = VBA_evalFun('g',xt,Phi,ut,options,dim,t); From 601567cd493cd7b268b5b04cf9dadd85ad28dfcc Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 9 Jun 2020 21:18:21 +0100 Subject: [PATCH 3/3] clean up code --- core/VBA_odeLim.m | 48 ++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/core/VBA_odeLim.m b/core/VBA_odeLim.m index 7002bfaa..2ad80f1b 100644 --- a/core/VBA_odeLim.m +++ b/core/VBA_odeLim.m @@ -43,23 +43,27 @@ t = t+1; end +% do we fit multiple sessions at once? +if isfield(options.multisession,'split') ... + && numel(options.multisession.split) > 1 + % if yes then find out if a new sessions begins right now + [newSess, idx] = ismember(t,cumsum(options.multisession.split)+1); +else + newSess = 0; +end -multiSess = zeros(sum(options.multisession.split),1); -idx = cumsum(options.multisession.split)+1; -idx = [1, idx(1:end-1)]; -multiSess(idx) = 1; - -if multiSess(t) - if t ~=1 - for ii = 1:size(options.inG{2}.indices.X0,1) - dxdTheta(:,ii) = 0; - if options.inG{2}.indices.X0(ii,find(idx==t)) == ii - if options.updateX0 - temp = P(dim.n_phi+dim.n_theta+1:end); - xt(ii) = temp(ii); - else - xt(ii) = options.priors.muX0(ii); - end +if newSess + % we treat the beginning of a new session just like the inital state + % for each X0 check ... + for ii = 1:size(options.inG{2}.indices.X0,1) + % ... if it is fixed across sessions ... + if options.inG{2}.indices.X0(ii,idx+1) == ii + % ... and set it to the value of the prior. + if options.updateX0 + temp = P(dim.n_phi+dim.n_theta+1:end); + xt(ii) = temp(ii); + else + xt(ii) = options.priors.muX0(ii); end end end @@ -77,7 +81,17 @@ end % ... and initial conditions if options.updateX0 - if ~isempty(dxdx0) + if newSess % reset derivatives if a new session begins + dxdx0 = dxdx0*dF_dX; % first update normally + % but then for the X0 that are fixed across sessions ... + for ii = 1:size(options.inG{2}.indices.X0,1) + if options.inG{2}.indices.X0(ii,idx+1) == ii + % ... reset their rows and columns + dxdx0(ii,:) = dF_dX(ii,:); + dxdx0(:,ii) = dF_dX(:,ii); + end + end + elseif ~isempty(dxdx0) dxdx0 = dxdx0*dF_dX; else % initial condition (t=0) dxdx0 = dF_dX;