-
Notifications
You must be signed in to change notification settings - Fork 0
/
spm_Ce.m
101 lines (90 loc) · 2.89 KB
/
spm_Ce.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
function [C] = spm_Ce(t,v,a)
% Error covariance constraints (for serially correlated data)
% FORMAT [C] = spm_Ce(v,a)
% FORMAT [C] = spm_Ce('ar',v,a)
% v - (1 x n) v(i) = number of observations for i-th block
% a - AR coefficient expansion point [Default: a = []]
%
% a = [] (default) - block diagonal identity matrices specified by v:
%
% C{i} = blkdiag( zeros(v(1),v(1)),...,AR(0),...,zeros(v(end),v(end)))
% AR(0) = eye(v(i),v(i))
%
% otherwise:
%
% C{i} = AR(a) - a*dAR(a)/da;
% C{i + 1} = AR(a) + a*dAR(a)/da;
%
% FORMAT [C] = spm_Ce('fast',v,tr)
% v - (1 x n) v(i) = number of observations for i-th block
% tr - repetition time
%
% See also: spm_Q.m
%__________________________________________________________________________
% Copyright (C) 2000-2017 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_Ce.m 7203 2017-11-08 12:49:15Z guillaume $
%-Defaults (and backward compatibility with spm_Ce(v,a) == spm_Ce('ar',v,a))
%--------------------------------------------------------------------------
if ~ischar(t)
if nargin > 1, a = v; else a = []; end
v = t;
t = 'ar';
else
if nargin == 2, a = []; end
end
%-Error covariance constraints
%--------------------------------------------------------------------------
switch lower(t)
case 'ar'
%-Create block diagonal components
%------------------------------------------------------------------
C = {};
l = length(v);
n = sum(v);
k = 0;
if l > 1
for i = 1:l
dCda = spm_Ce(v(i),a);
for j = 1:length(dCda)
[x,y,q] = find(dCda{j});
x = x + k;
y = y + k;
C{end + 1} = sparse(x,y,q,n,n);
end
k = v(i) + k;
end
else
%-dCda
%--------------------------------------------------------------
if ~isempty(a)
Q = spm_Q(a,v);
dQda = spm_diff('spm_Q',a,v,1);
C{1} = Q - dQda{1}*a;
C{2} = Q + dQda{1}*a;
else
C{1} = speye(v,v);
end
end
case 'fast'
dt = a;
C = {};
n = sum(v);
k = 0;
for m=1:length(v)
T = (0:(v(m) - 1))*dt;
d = 2.^(floor(log2(dt/4)):log2(64));
for i = 1:min(6,length(d))
for j = 0:2
QQ = toeplitz((T.^j).*exp(-T/d(i)));
[x,y,q] = find(QQ);
x = x + k;
y = y + k;
C{end + 1} = sparse(x,y,q,n,n);
end
end
k = k + v(m);
end
otherwise
error('Unknown error covariance constraints.');
end