-
Notifications
You must be signed in to change notification settings - Fork 54
/
spm_DFP_plot.m
116 lines (104 loc) · 2.74 KB
/
spm_DFP_plot.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
function spm_DFP_plot(QU,pU)
% plots particles for spm_DFP
% FORMAT spm_DFP_plot(QU,Nt)
% FORMAT spm_DFP_plot(QU,pU)
%--------------------------------------------------------------------------
% QU{t}(p).x{d} - ensemble of hidden states
% QU{t}(p).v{d} - ensemble of causal states
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_DFP_plot.m 6540 2015-09-05 10:06:42Z karl $
% defaults for plotting
%--------------------------------------------------------------------------
clf
try
pX = pU.x{1};
pV = pU.v{2};
Nt = length(pX);
catch
try Nt = pU; catch, Nt = length(QU); end
end
% time-series specification
%--------------------------------------------------------------------------
nx = size(QU{1}(1).x{1},1);
nv = size(QU{1}(1).v{1},1);
np = length(QU{1});
nt = length(QU);
% unpack states
%--------------------------------------------------------------------------
for t = 1:nt
for j = 1:np
for i = 1:nx
X{i}(t,j) = QU{t}(j).x{1}(i);
end
for i = 1:nv
V{i}(t,j) = QU{t}(j).v{1}(i);
end
end
end
% causes
%--------------------------------------------------------------------------
if nt < 2, return, end
subplot(2,1,1)
for i = 1:nv
plot(1:nt,V{i},':','Color',[1 1 1]/(2 + i - 1))
hold on
if np < 16
plot(nt,V{i}(nt,:),'.','Color',[1 1 1]/(2 + i - 1),'MarkerSize',32)
plot(nt,V{i}(nt,:),'.','Color',[1 1 1],'MarkerSize',4)
else
plot(nt,V{i}(nt,:),'.','Color',[1 0 0],'MarkerSize',8)
end
plot(1:nt,mean(V{i},2),'--b','LineWidth',2)
hold on
end
try
hold on
plot((1:nt) - 1,pV,'r')
end
hold off
title('causes','FontSize',16);
xlabel('time (steps)','FontSize',14)
grid on
axis square
set(gca,'XLim',[1 Nt])
% hidden states
%--------------------------------------------------------------------------
if ~nx, drawnow, return, end
subplot(2,1,2)
for i = 1:nx
plot(1:nt,X{i},':','Color',[1 1 1]/(2 + i - 1))
hold on
if np < 16
plot(nt,X{i}(nt,:),'.','Color',[1 1 1]/(2 + i - 1),'MarkerSize',32)
plot(nt,X{i}(nt,:),'.','Color',[1 1 1],'MarkerSize',4)
else
plot(nt,X{i}(nt,:),'.','Color',[1 0 0],'MarkerSize',8)
end
plot(1:nt,mean(X{i},2),'--b','LineWidth',2)
hold on
end
try
hold on
plot((1:nt) - 1,pX,'r')
end
hold off
title('hidden states','FontSize',16);
xlabel('time (steps)','FontSize',14)
grid on
axis square
set(gca,'XLim',[1 Nt])
drawnow
return
% movie
%--------------------------------------------------------------------------
spm_figure('GetWin','DFP');
subplot(2,1,2)
try
load DFP_movie
M(end + 1) = getframe;
catch
M = getframe;
end
save DFP_movie M