spm_fx_fmri.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. function [f,dfdx,D,dfdu] = spm_fx_fmri(x,u,P,M)
  2. % State equation for a dynamic [bilinear/nonlinear/Balloon] model of fMRI
  3. % responses
  4. % FORMAT [f,dfdx,D,dfdu] = spm_fx_fmri(x,u,P,M)
  5. % x - state vector
  6. % x(:,1) - excitatory neuronal activity ue
  7. % x(:,2) - vascular signal s
  8. % x(:,3) - rCBF ln(f)
  9. % x(:,4) - venous volume ln(v)
  10. % x(:,5) - deoyxHb ln(q)
  11. % [x(:,6) - inhibitory neuronal activity ui
  12. %
  13. % f - dx/dt
  14. % dfdx - df/dx
  15. % dfdu - df/du
  16. % D - delays
  17. %
  18. %__________________________________________________________________________
  19. %
  20. % References for hemodynamic & neuronal state equations:
  21. % 1. Buxton RB, Wong EC & Frank LR. Dynamics of blood flow and oxygenation
  22. % changes during brain activation: The Balloon model. MRM 39:855-864,
  23. % 1998.
  24. % 2. Friston KJ, Mechelli A, Turner R, Price CJ. Nonlinear responses in
  25. % fMRI: the Balloon model, Volterra kernels, and other hemodynamics.
  26. % Neuroimage 12:466-477, 2000.
  27. % 3. Stephan KE, Kasper L, Harrison LM, Daunizeau J, den Ouden HE,
  28. % Breakspear M, Friston KJ. Nonlinear dynamic causal models for fMRI.
  29. % Neuroimage 42:649-662, 2008.
  30. % 4. Marreiros AC, Kiebel SJ, Friston KJ. Dynamic causal modelling for
  31. % fMRI: a two-state model.
  32. % Neuroimage. 2008 Jan 1;39(1):269-78.
  33. %__________________________________________________________________________
  34. % Copyright (C) 2002-2014 Wellcome Trust Centre for Neuroimaging
  35. % Karl Friston & Klaas Enno Stephan
  36. % $Id: spm_fx_fmri.m 7270 2018-03-04 13:08:10Z karl $
  37. % options
  38. %--------------------------------------------------------------------------
  39. if nargin < 4, M = struct([]); end
  40. if isfield(M,'symmetry'), symmetry = M.symmetry; else symmetry = 0; end
  41. % Neuronal motion
  42. %==========================================================================
  43. P.A = full(P.A); % linear parameters
  44. P.B = full(P.B); % bi-linear parameters
  45. P.C = P.C/16; % exogenous parameters
  46. P.D = full(P.D); % nonlinear parameters
  47. % implement differential state equation y = dx/dt (neuronal)
  48. %--------------------------------------------------------------------------
  49. f = x;
  50. % if there are five hidden states per region, only one is neuronal
  51. %==========================================================================
  52. if size(x,2) == 5
  53. % if P.A encodes the eigenvalues of the (average) connectivity matrix
  54. %======================================================================
  55. if isvector(P.A)
  56. % excitatory connections
  57. %------------------------------------------------------------------
  58. EE = spm_dcm_fmri_mode_gen(P.A,M.modes);
  59. % input dependent modulation
  60. %------------------------------------------------------------------
  61. for i = 1:size(P.B,3)
  62. EE = EE + u(i)*P.B(:,:,i);
  63. end
  64. % and nonlinear (state) terms
  65. %------------------------------------------------------------------
  66. for i = 1:size(P.D,3)
  67. EE = EE + x(i,1)*P.D(:,:,i);
  68. end
  69. else % otherwise average connections are encoded explicitly
  70. %==================================================================
  71. % input dependent modulation
  72. %------------------------------------------------------------------
  73. for i = 1:size(P.B,3)
  74. P.A(:,:,1) = P.A(:,:,1) + u(i)*P.B(:,:,i);
  75. end
  76. % and nonlinear (state) terms
  77. %------------------------------------------------------------------
  78. for i = 1:size(P.D,3)
  79. P.A(:,:,1) = P.A(:,:,1) + x(i,1)*P.D(:,:,i);
  80. end
  81. % combine forward and backward connections if necessary
  82. %------------------------------------------------------------------
  83. if size(P.A,3) > 1
  84. P.A = exp(P.A(:,:,1)) - exp(P.A(:,:,2));
  85. end
  86. % one neuronal state per region: diag(A) is a log self-inhibition
  87. %------------------------------------------------------------------
  88. SE = diag(P.A);
  89. EE = P.A - diag(exp(SE)/2 + SE);
  90. % symmetry constraints for demonstration purposes
  91. %------------------------------------------------------------------
  92. if symmetry, EE = (EE + EE')/2; end
  93. end
  94. % flow
  95. %----------------------------------------------------------------------
  96. f(:,1) = EE*x(:,1) + P.C*u(:);
  97. else
  98. % otherwise two neuronal states per region
  99. %======================================================================
  100. % input dependent modulation
  101. %----------------------------------------------------------------------
  102. for i = 1:size(P.B,3)
  103. P.A(:,:,1) = P.A(:,:,1) + u(i)*P.B(:,:,i);
  104. end
  105. % and nonlinear (state) terms
  106. %----------------------------------------------------------------------
  107. for i = 1:size(P.D,3)
  108. P.A(:,:,1) = P.A(:,:,1) + x(i,1)*P.D(:,:,i);
  109. end
  110. % extrinsic (two neuronal states): enforce positivity
  111. %----------------------------------------------------------------------
  112. n = size(P.A,1); % number of regions
  113. EE = exp(P.A(:,:,1))/8;
  114. IE = diag(diag(EE)); % intrinsic inhibitory to excitatory
  115. EE = EE - IE; % extrinsic excitatory to excitatory
  116. EI = eye(n,n); % intrinsic excitatory to inhibitory
  117. SE = eye(n,n)/2; % intrinsic self-inhibition (excitatory)
  118. SI = eye(n,n); % intrinsic self-inhibition (inhibitory)
  119. % excitatory proportion
  120. %----------------------------------------------------------------------
  121. if size(P.A,3) > 1
  122. phi = spm_phi(P.A(:,:,2)*2);
  123. EI = EI + EE.*(1 - phi);
  124. EE = EE.*phi - SE;
  125. else
  126. EE = EE - SE;
  127. end
  128. % motion - excitatory and inhibitory: f = dx/dt
  129. %----------------------------------------------------------------------
  130. f(:,1) = EE*x(:,1) - IE*x(:,6) + P.C*u(:);
  131. f(:,6) = EI*x(:,1) - SI*x(:,6);
  132. end
  133. % Hemodynamic motion
  134. %==========================================================================
  135. % hemodynamic parameters
  136. %--------------------------------------------------------------------------
  137. % H(1) - signal decay d(ds/dt)/ds)
  138. % H(2) - autoregulation d(ds/dt)/df)
  139. % H(3) - transit time (t0)
  140. % H(4) - exponent for Fout(v) (alpha)
  141. % H(5) - resting oxygen extraction (E0)
  142. % H(6) - ratio of intra- to extra-vascular components (epsilon)
  143. % of the gradient echo signal
  144. %--------------------------------------------------------------------------
  145. H = [0.64 0.32 2.00 0.32 0.4];
  146. % exponentiation of hemodynamic state variables
  147. %--------------------------------------------------------------------------
  148. x(:,3:5) = exp(x(:,3:5));
  149. % signal decay
  150. %--------------------------------------------------------------------------
  151. sd = H(1)*exp(P.decay);
  152. % transit time
  153. %--------------------------------------------------------------------------
  154. tt = H(3)*exp(P.transit);
  155. % Fout = f(v) - outflow
  156. %--------------------------------------------------------------------------
  157. fv = x(:,4).^(1/H(4));
  158. % e = f(f) - oxygen extraction
  159. %--------------------------------------------------------------------------
  160. ff = (1 - (1 - H(5)).^(1./x(:,3)))/H(5);
  161. % implement differential state equation f = dx/dt (hemodynamic)
  162. %--------------------------------------------------------------------------
  163. f(:,2) = x(:,1) - sd.*x(:,2) - H(2)*(x(:,3) - 1);
  164. f(:,3) = x(:,2)./x(:,3);
  165. f(:,4) = (x(:,3) - fv)./(tt.*x(:,4));
  166. f(:,5) = (ff.*x(:,3) - fv.*x(:,5)./x(:,4))./(tt.*x(:,5));
  167. f = f(:);
  168. if nargout < 2, return, end
  169. % Neuronal Jacobian
  170. %==========================================================================
  171. [n,m] = size(x);
  172. if m == 5
  173. % one neuronal state per region
  174. %----------------------------------------------------------------------
  175. dfdx{1,1} = EE;
  176. for i = 1:size(P.D,3)
  177. D = P.D(:,:,i) + diag((diag(EE) - 1).*diag(P.D(:,:,i)));
  178. dfdx{1,1}(:,i) = dfdx{1,1}(:,i) + D*x(:,1);
  179. end
  180. else
  181. % two neuronal states: NB nonlinear (D) effects not implemented)
  182. %----------------------------------------------------------------------
  183. dfdx{1,1} = EE;
  184. dfdx{1,6} = - IE;
  185. dfdx{6,1} = EI;
  186. dfdx{6,6} = - SI;
  187. end
  188. % input
  189. %==========================================================================
  190. dfdu{1,1} = P.C;
  191. for i = 1:size(P.B,3)
  192. B = P.B(:,:,i) + diag((diag(EE) - 1).*diag(P.B(:,:,i)));
  193. dfdu{1,1}(:,i) = dfdu{1,1}(:,i) + B*x(:,1);
  194. end
  195. dfdu{2,1} = sparse(n*(m - 1),length(u(:)));
  196. % Hemodynamic Jacobian
  197. %==========================================================================
  198. dfdx{2,1} = speye(n,n);
  199. dfdx{2,2} = speye(n,n)*(-sd);
  200. dfdx{2,3} = diag(-H(2)*x(:,3));
  201. dfdx{3,2} = diag( 1./x(:,3));
  202. dfdx{3,3} = diag(-x(:,2)./x(:,3));
  203. dfdx{4,3} = diag( x(:,3)./(tt.*x(:,4)));
  204. dfdx{4,4} = diag(-x(:,4).^(1/H(4) - 1)./(tt*H(4)) - (1./x(:,4).*(x(:,3) - x(:,4).^(1/H(4))))./tt);
  205. dfdx{5,3} = diag((x(:,3) + log(1 - H(5)).*(1 - H(5)).^(1./x(:,3)) - x(:,3).*(1 - H(5)).^(1./x(:,3)))./(tt.*x(:,5)*H(5)));
  206. dfdx{5,4} = diag((x(:,4).^(1/H(4) - 1)*(H(4) - 1))./(tt*H(4)));
  207. dfdx{5,5} = diag((x(:,3)./x(:,5)).*((1 - H(5)).^(1./x(:,3)) - 1)./(tt*H(5)));
  208. % concatenate
  209. %--------------------------------------------------------------------------
  210. dfdx = spm_cat(dfdx);
  211. dfdu = spm_cat(dfdu);
  212. D = 1;