forked from neurodebian/spm12
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spm_DEM_qH.m
143 lines (125 loc) · 3.97 KB
/
spm_DEM_qH.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
function spm_DEM_qH(qH,pH)
% reports on conditional estimates of hyperparameters
% FORMAT spm_DEM_qH(qH,pH);
%
% qH.h - conditional estimate of log-precision (causes)
% qH.g - conditional of log-precision (state)
% qH.V - conditional variance (causes)
% qH.W - conditional (states)
%
% qH.p - time-dependent estimates from Laplace scheme
% qH.c - time-dependent covariances
%
% pH - option true log-precisions
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_DEM_qH.m 4052 2010-08-27 19:22:44Z karl $
% unpack conditional covariances
%--------------------------------------------------------------------------
try, qH = qH.qH; end
try, pH = pH.pH; end
% [Re]ML estimates - h
%==========================================================================
ci = spm_invNcdf(1 - 0.05);
h = spm_vec(qH.h);
c = spm_vec(qH.V);
c = sqrt(c)*ci;
subplot(2,2,1)
bar(full(h),'Edgecolor',[1 1 1]/2,'Facecolor',[1 1 1]*.8)
title({'log-precision';'noise and causes'},'FontSize',16);
axis square
set(gca,'XLim',[0 length(c) + 1])
hlabel = {};
for i = 1:length(qH.h)
for j = 1:length(qH.h{i})
hlabel{end + 1} = sprintf('h:level %i',i);
end
end
set(gca,'XTickLabel',hlabel)
% conditional covariances
%--------------------------------------------------------------------------
for i = 1:length(c)
line([i i],[-1 1]*c(i) + h(i),'LineWidth',4,'Color','r');
end
% prior or true means
%--------------------------------------------------------------------------
try
p = spm_vec(pH.h);
for i = 1:length(h)
line([-1 1]/2 + i,[0 0] + p(i),'LineWidth',4,'Color','k');
end
end
% [Re]ML estimates - g
%==========================================================================
h = spm_vec(qH.g);
c = spm_vec(qH.W);
c = sqrt(c)*spm_invNcdf(1 - 0.05);
if h
subplot(2,2,2)
bar(full(h),'Edgecolor',[1 1 1]/2,'Facecolor',[1 1 1]*.8)
title({'log-precision';'states'},'FontSize',16);
axis square
set(gca,'XLim',[0 length(c) + 1])
% conditional covariances
%----------------------------------------------------------------------
for i = 1:length(c)
line([i i],[-1 1]*c(i) + h(i),'LineWidth',4,'Color','r');
end
% prior or true means
%----------------------------------------------------------------------
try
p = spm_vec(pH.g);
for i = 1:length(h)
line([-1 1]/2 + i,[0 0] + p(i),'LineWidth',4,'Color','k');
end
end
glabel = {};
for i = 1:length(qH.h)
for j = 1:length(qH.h{i})
glabel{end + 1} = sprintf('g:level %i',i);
end
end
set(gca,'XTickLabel',glabel)
else
glabel = {};
end
% conditional covariance and correlations
%--------------------------------------------------------------------------
subplot(2,2,3)
imagesc(qH.C)
title({'covariances among','hyperparameters'},'FontSize',16)
axis square
set(gca,'YTickLabel',{hlabel{:} glabel{:}},'YTick',[1:length(qH.C)])
% plot evolution of hyperparameters if supplied
%==========================================================================
subplot(2,2,4)
try
% confidence interval and expectations
%----------------------------------------------------------------------
ns = length(qH.p);
t = 1:ns;
for i = 1:ns
v(:,i) = sqrt(diag(qH.c{i}));
end
c = ci*v;
h = spm_cat(qH.p);
% plot
%----------------------------------------------------------------------
hold on
nh = size(h,1);
for i = 1:nh
fill([t fliplr(t)],[(h(i,:) + c(i,:)) fliplr(h(i,:) - c(i,:))],...
[1 1 1]*.8,'EdgeColor',[1 1 1]/2)
plot(t,h(i,:))
end
set(gca,'XLim',[1 ns])
title({'dynamics of','hyperparameters'},'FontSize',16)
xlabel('time')
axis square
hold off
catch
imagesc(spm_cov2corr(qH.C))
title({'correlations among','hyperparameters'},'FontSize',16)
axis square
end