spm_fp_fmin.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function [P] = spm_fp_fmin(M)
  2. % optimises the parameters with respect to an equilibrium density
  3. % FORMAT [P] = spm_fp_fmin(M)
  4. %
  5. % M - model structure with desired density specified by M(1).fq and
  6. % support specified by M(1).X = spm_ndgrid(x)
  7. %
  8. % P - optimised parameters
  9. %
  10. %--------------------------------------------------------------------------
  11. % This routine uses EM (spm_nlsi_NG) and the Fokker Planck formulation to
  12. % minimise the difference between the flow and dispersion terms induced by
  13. % the free parameters of the flow (M(1),f).
  14. %__________________________________________________________________________
  15. % Copyright (C) 2005 Wellcome Trust Centre for Neuroimaging
  16. % Karl Friston
  17. % $Id: spm_fp_fmin.m 4136 2010-12-09 22:22:28Z guillaume $
  18. % specify function returning the flow-dependent part of dp/dt 'spm_fp_fun'
  19. %--------------------------------------------------------------------------
  20. M = M(1);
  21. try, M = rmfield(M,'hE'); end
  22. try, M = rmfield(M,'hC'); end
  23. U = [];
  24. M.IS = 'spm_fp_fun';
  25. % Dispersion
  26. %--------------------------------------------------------------------------
  27. N = size(M.X,1);
  28. D = inv(M.W)/2;
  29. for i = 1:N
  30. Y.y(i,1) = trace(D*spm_cat(spm_diff(M.fq,M.X(i,:),[1 1])')');
  31. end
  32. % Optimise
  33. %--------------------------------------------------------------------------
  34. P = spm_nlsi_GN(M,U,Y);