-
Notifications
You must be signed in to change notification settings - Fork 4
/
spm_fp_fun.m
44 lines (37 loc) · 1.2 KB
/
spm_fp_fun.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
function [y] = spm_fp_fun(P,M,U)
% returns the predicted diffusion for Fokker Planck optimisation
% FORMAT [y] = spm_fp_fun(P,M,U)
%
% P = spm_vec(P)
% P.a - 0th order coefficients of force
% P.b - 1st order coefficients of force
% P.c - 2nd order coefficients of force
%
% M - model specifying flow(M(1).f; density M(1).fq and support M(1).X
% U - inputs
%
% y - prediction
%__________________________________________________________________________
% Copyright (C) 2005 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_fp_fun.m 2030 2008-09-02 18:28:40Z karl $
% default: first level of hierarchical model
%--------------------------------------------------------------------------
M = M(1);
% default expansion point for inputs
%--------------------------------------------------------------------------
try
u = U.u;
catch
u = sparse(M.m,1);
end
% predicted dispersion
%--------------------------------------------------------------------------
N = length(M.X);
for i = 1:N
f = feval(M.f,M.X(i,:)',u,P);
p = feval(M.fq,M.X(i,:));
dfdx = spm_diff(M.f,M.X(i,:)',u,P,1);
dpdx = spm_diff(M.fq,M.X(i,:),1);
y(i,1) = trace(p*dfdx) + dpdx*f;
end