-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspm_backwards.m
More file actions
34 lines (27 loc) · 1.03 KB
/
Copy pathspm_backwards.m
File metadata and controls
34 lines (27 loc) · 1.03 KB
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
function [L] = spm_backwards(O,Q,A,B,u,t,T)
% Backwards smoothing to evaluate posterior over initial states
%--------------------------------------------------------------------------
L = Q{t,2};
p = 1;
for timestep = (t + 1):T
% belief propagation over hidden states
%------------------------------------------------------------------
p = B{2}(:,:,1)*p;
for state = 1:numel(L)
% and accumulate likelihood
%------------------------------------------------------------------
for g = 3:3
% possible_states = O{g,timestep}*A{g}(:,:);
obs = find(cumsum(O{g,timestep})>= rand,1);
temp = A{g}(obs,:,:);
temp = permute(temp,[3,2,1]);
temp = temp*Q{timestep,1}';
aaa = temp'*p(:,state);
L(state) = L(state).*aaa;
end
end
end
% marginal distribution over states
%--------------------------------------------------------------------------
L = spm_norm(L(:));
end