Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uncommented multisession fixed.X0 #84

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/VBA_multisession_expand.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 41 additions & 2 deletions core/VBA_odeLim.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,10 +39,38 @@
else
xt = options.priors.muX0;
end
else
else
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

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
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);
Expand All @@ -52,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;
Expand Down