-
Notifications
You must be signed in to change notification settings - Fork 64
/
spm_ADEM_update.m
57 lines (51 loc) · 1.88 KB
/
spm_ADEM_update.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function [DEM] = spm_ADEM_update(DEM,COV)
% Updates ADEM structure using conditional expectations
% FORMAT [DEM] = spm_ADEM_update(DEM,COV)
%
% DEM - DEM structure
% COV - flag for Bayesian belief updating (with covariance)
%
% this routine updates posterior expectations about states and parameters
% by replacing prior expectations with posterior expectations (and
% similarly updating hidden states and causes to the final iteration). It
% called with an extra argument, the posterior variances of the
% parameters are also updated.
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_ADEM_update.m 6198 2014-09-25 10:38:48Z karl $
% update states and parameters (model)
%--------------------------------------------------------------------------
n = length(DEM.M);
C = DEM.qP.C;
for i = 1:(n - 1)
% expectations
%----------------------------------------------------------------------
DEM.M(i).x = spm_unvec(DEM.qU.x{i}(:,end),DEM.M(i).x);
DEM.M(i).pE = DEM.qP.P{i};
% and covariance if required
%----------------------------------------------------------------------
if nargin > 1
np = length(DEM.M(i).pC);
DEM.M(i).pC = C(1:np,1:np);
np = np + 1;
C = C(np:end,np:end);
end
end
for i = 1:n
if ~isempty(DEM.M(i).v)
DEM.M(i).v = spm_unvec(DEM.qU.v{i}(:,end),DEM.M(i).v);
end
end
% update states and action (process)
%--------------------------------------------------------------------------
n = length(DEM.G);
for i = 1:(n - 1)
DEM.G(i).x = spm_unvec(DEM.pU.x{i}(:,end),DEM.G(i).x);
end
for i = 1:n
if ~isempty(DEM.G(i).v)
DEM.G(i).v = spm_unvec(DEM.pU.v{i}(:,end),DEM.G(i).v);
end
end
DEM.G(n).a = spm_unvec(DEM.qU.a{n}(:,end),DEM.G(n).a);