forked from MBB-team/VBA-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VBA_getKernels.m
82 lines (74 loc) · 2.14 KB
/
VBA_getKernels.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
function [H1,K1,tgrid] = VBA_getKernels(posterior,out,dcm)
% Dummy derivation of the system's response kernels
% function [H1,K1,tgrid] = VBA_getKernels(posterior,out,dcm)
% IN:
% - posterior,out: the output of the system inversion
% - dcm: flag for dcm (does not compute hemodynamic states kernels)
% OUT:
% - H1: the (pxtxnu) output impulse response function, where p is the
% dimension of the data, t is the number of time samples and nu is the
% number of inputs to the system
% - K1: the (nxtxnu) state impulse response function, where n is the
% number of states. NB: for DCM models, this is the neural impulse
% response function...
% - tgrid: the time grid over which the kernels are estimated
if isequal(out.dim.n_t,1) || out.dim.u < 1 || isempty(out.options.f_fname)
% not a dynamical system
H1 = [];
K1 = [];
tgrid = [];
return
end
if nargin <3
dcm = 0;
else
dcm = ~~dcm;
end
nu = out.dim.u;
n = out.dim.n;
p = out.dim.p;
out.options.microU = 1; % for impulse response functions...
if dcm
% remove confounds,...
out.options.inG.confounds.X0 = [];
% only look at neuronal states,...
n = p; %size(out.options.inF.C,1);
% and get kernels over 16 secs
TR = out.options.inF.deltat*out.options.decim;
out.options.dim.n_t = ceil(16./TR);
end
nt = out.options.dim.n_t*out.options.decim;
% ensure steady state initial conditions and throw away state noise
% estimate
posterior.muX0 = zeros(size(posterior.muX0));
out.suffStat.dx = [];
% pre-allocate response kernels
H1 = zeros(p,nt,nu);
K1 = zeros(n,nt,nu);
% derive kernels by integrating the system
gotit = 0;
for i=1:nu
try
U = zeros(nu,nt);
U(i,1) = 1;
% get output impulse response
[x,gx,tgrid] = VBA_microTime(posterior,U,out);
H1(:,:,i) = gx(:,2:end);
if dcm && isfield(out.options.inF,'n5')
K1(:,:,i) = x(out.options.inF.n5,2:end);
else
K1(:,:,i) = x(:,2:end);
end
gotit = 1;
end
end
% clean up kernels
if ~gotit
H1 = [];
K1 = [];
tgrid = [];
else
tgrid = tgrid(2:end);
K1(abs(K1)<=1e-8) = 0;
H1(abs(H1)<=1e-8) = 0;
end