OSCR

Multiscale parcellation of dynamic causal models of the brain.

Code ↔ Paper

9 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 9 matches · 2 of them tie a paragraph to a whole file, not to given lines: weak matches, whose lines are not tinted
  1. [1] § Results › Empirical network › Conditional independence and Markov blanket ↔ Code/DEMO2_MB.m, lines 37–58 · score 0.76 · stretched beta prior, Bayes factor, posterior distribution, partial correlation, hyperparameter, analytic
  2. [2] § Materials and Methods › Empirical network ↔ Code/spm_dcm_J_mod.m, lines 1–72 · score 0.68 · Bayesian model reduction, local connectivity, redundant, linearized, effective connectivity, voxels
  3. [3] § Results › Empirical network › Conditional independence and Markov blanket ↔ Code/DEMO2_MB.m, lines 37–58 · score 0.64 · stretched beta prior, Bayes factors, partial correlation, hypothesis, log
  4. [4] § Results › Empirical network › Conditional independence and Markov blanket ↔ Code/spm_mb_ui_mod.m, lines 1–60 · score 0.59 · Markov blanket states, neuronal states, internal states, Sparsity, MB, partitioned
  5. [5] § Results › Empirical network › Conditional independence and Markov blanket ↔ Code/spm_mb_ui_mod.m, lines 1–60 · score 0.58 · Identifying Markov blanket, internal states, blanket states, blocks, couplings, causal
  6. [6] § Results › Empirical network › Conditional independence and Markov blanket ↔ Code/plot_HJ.m, the whole file · a weak match · score 0.57 · Cross PT, MB inducing, B1, B2, PT1, INT1
  7. [7] § Materials and Methods › Empirical network ↔ Code/spm_mb_ui_mod.m, lines 324–374 · score 0.57 · maximum intensity projection, variance explained, eigenmode, coupling, matrix, partitioned
  8. [8] § Materials and Methods › Empirical network ↔ Code/compute_J.m, the whole file · a weak match · score 0.57 · fMRI, visual motion, effective connectivity, variance, matrix
  9. [9] § Materials and Methods › Simulated networks ↔ Code/spm_dcm_J_mod.m, lines 1–72 · score 0.53 · Bayesian model reduction, log evidence, bmr, posterior, causal, spm

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 1,268 lines · 57 KB · AGPL-3.0 · 3 matches

  1. function [MB] = spm_mb_ui_mod(action,varargin)
  2. % This is a minimally MODIFIED version of spm_mb_ui.m in SPM12
  3. % Modified by Tahereh Zarghami, 2025
  4. % VOI extraction of adjusted data and Markov Blanket decomposition
  5. % FORMAT [MB] = spm_mb_ui('specify',SPM)
  6. % FORMAT [MB] = spm_mb_ui('blocking',MB)
  7. % FORMAT [MB] = spm_mb_ui('results' ,MB)
  8. %
  9. % SPM - structure containing generic analysis details
  10. %
  11. % MB.contrast - contrast name
  12. % MB.name - MB name
  13. % MB.c - contrast weights
  14. % MB.X - contrast subspace
  15. % MB.Y - whitened and adjusted data
  16. % MB.X0 - null space of contrast
  17. %
  18. % MB.XYZ - locations of voxels (mm)
  19. % MB.xyz - seed voxel location (mm)
  20. % MB.VOX - dimension of voxels (mm)
  21. %
  22. % MB.V - canonical vectors (data)
  23. % MB.v - canonical variates (data)
  24. % MB.W - canonical vectors (design)
  25. % MB.w - canonical variates (design)
  26. % MB.C - canonical contrast (design)
  27. %
  28. % MB.chi - Chi-squared statistics testing D >= i
  29. % MB.df - d.f.
  30. % MB.p - p-values
  31. %
  32. % also saved in MB_*.mat in the SPM working directory
  33. %
  34. % FORMAT [MB] = spm_cva_ui('results',MB)
  35. % Display the results of a MB analysis
  36. %__________________________________________________________________________
  37. %
  38. % This routine uses the notion of Markov blankets and the renormalisation
  39. % group to evaluate the coupling among neuronal systems at increasing
  40. % spatial scales. The underlying generative model is based upon the
  41. % renormalisation group: a working definition of renormalization involves
  42. % three elements: vectors of random variables, a course-graining operation
  43. % and a requirement that the operation does not change the functional form
  44. % of the Lagrangian. In our case, the random variables are neuronal states;
  45. % the course graining operation corresponds to the grouping (G) into a
  46. % particular partition and adiabatic reduction (R) - that leaves the
  47. % functional form of the dynamics unchanged.
  48. %
  49. % Here, the grouping operator (G) is based upon coupling among states as
  50. % measured by the Jacobian. In brief, the sparsity structure of the
  51. % Jacobian is used to recursively identify Markov blankets around internal
  52. % states to create a partition of states - at any level - into particles;
  53. % where each particle comprises external and blanket states. The ensuing
  54. % reduction operator (R) eliminates the internal states and retains the slow
  55. % eigenmodes of the blanket states. These then constitute the (vector)
  56. % states at the next level and the process begins again.
  57. %
  58. % This routine starts using a simple form of dynamic causal modelling
  59. % applied to the principal eigenvariate of local parcels (i.e., particles)
  60. % of voxels with compact support. The Jacobian is estimated using a
  61. % linearised dynamic causal (state space) model, where observations are
  62. % generated by applying a (e.g., haemodynamic) convolution operator to
  63. % hidden (e.g., neuronal) states. This estimation uses parametric empirical
  64. % Bayes (PEB: spm_PEB). The ensuing estimates of the Jacobian (i.e.,
  65. % effective connectivity) are reduced using Bayesian model reduction (BMR:
  66. % spm_dcm_BMR_all) within a bespoke routine (spm_dcm_J).
  67. %
  68. % The Jacobian is then partitioned using the course graining operator into
  69. % particles or parcels (using spm_markov blanket). The resulting partition
  70. % is then reduced by eliminating internal states and retaining slow
  71. % eigenmodes with the largest (real) eigenvalues (spm_A_reduce). The
  72. % Jacobian of the reduced states is then used to repeat the process -
  73. % recording the locations of recursively coarse-grained particles - until
  74. % there is a single particle.
  75. %
  76. % The result of this recursive decomposition (i.e., renormalisation)
  77. % affords a characterisation of directed coupling, as characterised by a
  78. % complex Jacobian; namely, a multivariate coupling matrix, describing the
  79. % coupling between eigenmodes of Markov blankets at successive scales. This
  80. % can be regarded as a recursive parcellation scheme based upon effective
  81. % connectivity and a generative (dynamic causal) model of multivariate
  82. % (neuronal) timeseries.
  83. %
  84. % The following lists the various results options. please see main body of
  85. % this script for a description of the (graphical) output
  86. %
  87. % display the results in terms of particular partitions and eigenmodes
  88. %--------------------------------------------------------------------------
  89. % spm_mb_ui('results',MB,'anatomy');
  90. %
  91. % characterise connectivity at the smallest scale
  92. %--------------------------------------------------------------------------
  93. % spm_mb_ui('results',MB,'distance');
  94. %
  95. % characterise scaling behaviour in terms of scaling exponent
  96. %--------------------------------------------------------------------------
  97. % spm_mb_ui('results',MB,'scaling');
  98. %
  99. % characterise intrinsic coupling in terms of transfer functions
  100. %--------------------------------------------------------------------------
  101. % spm_mb_ui('results',MB,'kernels');
  102. %
  103. % display the results in terms of particular partitions and eigenmodes
  104. %--------------------------------------------------------------------------
  105. % spm_mb_ui('results',MB,'dynamics');
  106. %
  107. % characterise extrinsic coupling with a connectogram
  108. %--------------------------------------------------------------------------
  109. % spm_mb_ui('results',MB,'connectogram');
  110. %
  111. % characterise extrinsic coupling in terms of cross covariance functions
  112. %--------------------------------------------------------------------------
  113. % spm_mb_ui('results',MB,'connectivity');
  114. %
  115. % characterise intrinsic coupling in terms of dissipative flow
  116. %--------------------------------------------------------------------------
  117. % spm_mb_ui('results',MB,'eigenmodes');
  118. %
  119. % characterise eigenmodes in terms of design or inputs
  120. %--------------------------------------------------------------------------
  121. % spm_mb_ui('results',MB,'responses');
  122. %
  123. % input effects as active states at base level
  124. %--------------------------------------------------------------------------
  125. % spm_mb_ui('results',MB,'inputs');
  126. %__________________________________________________________________________
  127. % Copyright (C) 2008-2014 Wellcome Trust Centre for Neuroimaging
  128. % Karl Friston
  129. % $Id: spm_mb_ui.m 7808 2020-03-31 11:18:26Z karl $
  130. OPT.d = 32; % maximum connection length (mm)
  131. OPT.np = 1024; % number of parcels (particles)
  132. OPT.xyz = [0;0;0]; % centre of (spherical) VOI (mm)
  133. OPT.spec = 128; % radius of (spherical) VOI (mm)
  134. OPT.Ic = 1; % contrast (for adjusted data)
  135. OPT.T = 1; % threshold for adiabatic reduction
  136. OPT.N = 8; % max modes for adiabatic reduction
  137. switch lower(action)
  138. case 'specify'
  139. %==================================================================
  140. % M B : S P E C I F Y
  141. %==================================================================
  142. if isempty(varargin)
  143. [SPM,sts] = spm_select(1,'mat','Select SPM',[],[],'^SPM.*\.mat$');
  144. if ~sts, return; end
  145. else
  146. SPM = varargin{1};
  147. end
  148. if ischar(SPM)
  149. SPM = load(SPM);
  150. SPM = SPM.SPM;
  151. end
  152. %-Contrast specification
  153. %------------------------------------------------------------------
  154. con = SPM.xCon(OPT.Ic).name;
  155. c = SPM.xCon(OPT.Ic).c;
  156. c = full(c);
  157. %-Extract required data from results files
  158. %==================================================================
  159. %-Get (normalised) explanatory variables (data)
  160. %------------------------------------------------------------------
  161. cd(SPM.swd)
  162. XYZ = SPM.xVol.XYZ;
  163. F = spm_get_data(SPM.xCon(1).Vspm,XYZ);
  164. XYZ = XYZ(:,logical(F > 1));
  165. R = spm_get_data(SPM.VResMS,XYZ); % computation order swapped with Y
  166. cd("..\attention\functional") % I added
  167. Y = spm_get_data(SPM.xY.VY, XYZ);
  168. Y = bsxfun(@times,Y,1./sqrt(R));
  169. XYZmm = SPM.xVol.M(1:3,1:3)*XYZ;
  170. XYZmm = bsxfun(@plus,XYZmm,SPM.xVol.M(1:3,4));
  171. %-Remove serial correlations and get design (note X := W*X)
  172. %------------------------------------------------------------------
  173. Y = SPM.xX.W*Y;
  174. X = SPM.xX.xKXs.X;
  175. M = SPM.xVol.M(1:3,1:3); %-voxels to mm
  176. VOX = diag(sqrt(diag(M'*M))'); %-voxel size
  177. %-Null-space
  178. %------------------------------------------------------------------
  179. X0 = [];
  180. try, X0 = [X0 blkdiag(SPM.xX.K.X0(:,1:min(16,end)))]; end %-drift terms
  181. try, X0 = [X0 spm_detrend(SPM.xGX.gSF)]; end %-global estimate
  182. X0 = full(spm_svd([X0, (X - X*c*pinv(c))])); %-null space of c
  183. Y = Y - X0*(pinv(X0)*Y);
  184. % exogenous inputs (decimated)
  185. %------------------------------------------------------------------
  186. for i = 1:numel(SPM.Sess.U)
  187. U(:,i) = SPM.Sess.U(i).u(33:end,:);
  188. name{i} = SPM.Sess.U(i).name{1};
  189. end
  190. Dy = spm_dctmtx(size(Y,1),size(Y,1));
  191. Du = spm_dctmtx(size(U,1),size(Y,1));
  192. Dy = Dy*sqrt(size(Y,1)/size(U,1));
  193. U = Dy*(Du'*U);
  194. %-First level partition: compact support
  195. %==================================================================
  196. spm_figure('GetWin','Markov blanket');clf
  197. subplot(2,2,1), spm_mip(std(Y),XYZmm,VOX);
  198. axis image, axis off, title('Variance of voxels','FontSize',16)
  199. % local SVD
  200. %------------------------------------------------------------------
  201. V = spm_mvb_U(Y,'compact',X0,XYZ,[],OPT.np);
  202. Y = Y*V;
  203. nv = size(Y,2);
  204. x = cell(3,nv);
  205. x(2,:) = num2cell(1:nv); % indices of partition
  206. z = num2cell(1:nv); % indices of states
  207. % distance matrix (mm)
  208. %------------------------------------------------------------------
  209. [R,S] = spm_mb_distance(V,XYZmm);
  210. subplot(2,2,2), spm_mip(abs(V)*std(Y)',XYZmm,VOX);
  211. axis image, axis off, title('Variance of modes','FontSize',16)
  212. subplot(2,2,4), spm_mip(logical(V)*std(Y)',XYZmm,VOX);
  213. axis image, axis off, title('Variance of particles','FontSize',16)
  214. subplot(2,2,3), imagesc(R), axis image, axis off
  215. title('Disttance between particles','FontSize',16), drawnow
  216. % self inhibition based on spatial scale
  217. %------------------------------------------------------------------
  218. I = -S^(-3/2)*16;
  219. % first order Jacobian
  220. %==================================================================
  221. [J,K,VAR] = spm_dcm_J_mod(Y,U,X0,SPM.xY.RT,R,I,OPT.d); % VAR added
  222. % Populate first level of market blanket structure
  223. %==================================================================
  224. clear MB
  225. %-Assemble results
  226. %------------------------------------------------------------------
  227. MB{1}.swd = SPM.swd; % results directory
  228. MB{1}.dt = SPM.xY.RT; % sampling interval
  229. MB{1}.con = con; % contrast name
  230. MB{1}.name = name; % input name
  231. MB{1}.XYZ = XYZmm; % locations of voxels (mm)
  232. MB{1}.VOX = VOX; % dimension of voxels (mm)
  233. MB{1}.J = J; % Jacobian (states)
  234. MB{1}.K = K; % Jacobian (inputs)
  235. MB{1}.VAR = VAR; % Variance %%% I added
  236. MB{1}.z = z; % indices of states
  237. MB{1}.x = x; % indices of states
  238. MB{1}.s = num2cell(-abs(diag(J))); % Lyapunov exponents
  239. MB{1}.U = U; % exogenous inputs
  240. MB{1}.V = V; % support in voxel space
  241. MB{1}.W = sparse(logical(abs(V))); % support in voxel space
  242. MB{1}.Y = Y; % time-series
  243. case 'blocking'
  244. %==================================================================
  245. % M B : B L O C K I N G
  246. %==================================================================
  247. MB = varargin{1};
  248. N = 4; % maximum number of scales
  249. m = ones(N,1); % # internal states
  250. % preclude long range coupling
  251. %------------------------------------------------------------------
  252. % R = cell(N,1);
  253. % R{1} = spm_mb_distance(MB{1}.V,MB{1}.XYZ);
  254. % R{1}(R{1} > 48) = 0;
  255. %% group renormalization (course graining or blocking)
  256. %------------------------------------------------------------------
  257. for i = 1:N
  258. % Markov blanket (particular) partition
  259. %--------------------------------------------------------------
  260. x = spm_Markov_blanket(MB{i}.J,MB{i}.z,m(i));
  261. % break if no states
  262. %--------------------------------------------------------------
  263. if size(x,2) < 1, break, end
  264. % dimension reduction (eliminating internal states)
  265. %--------------------------------------------------------------
  266. [J,z,v,s] = spm_A_reduce(MB{i}.J,x,OPT.T,OPT.N);
  267. MB{i + 1}.J = J;
  268. MB{i + 1}.z = z;
  269. MB{i + 1}.s = s;
  270. MB{i + 1}.x = x;
  271. MB{i + 1}.W = sparse(logical(abs(MB{i}.V)));
  272. % eigenmodes and variates (V and Y)
  273. %--------------------------------------------------------------
  274. for j = 1:numel(z)
  275. u = [MB{i + 1}.x{1:2,j}]; % blanket states
  276. w = MB{i + 1}.z{j}; % new states
  277. MB{i + 1}.V(:,w) = MB{i}.V(:,u)*v{j};
  278. MB{i + 1}.Y(:,w) = MB{i}.Y(:,u)*v{j};
  279. end
  280. % functional anatomy of states
  281. %--------------------------------------------------------------
  282. spm_figure('getwin',sprintf('Markov level %i',i)); clf;
  283. spm_mb_anatomy(MB{i},MB{1}.XYZ,MB{1}.VOX);
  284. % break if a single particle or parcel
  285. %--------------------------------------------------------------
  286. if size(MB{i}.x,2) < 2, break, end
  287. end
  288. %% Save results
  289. %==================================================================
  290. %-Save
  291. %------------------------------------------------------------------
  292. save(fullfile(MB{1}.swd,['MB_' MB{1}.con]),'MB');
  293. case 'results'
  294. %==================================================================
  295. % M B : R E S U L T S
  296. %==================================================================
  297. %-Get MB and ananlysis
  298. %------------------------------------------------------------------
  299. MB = varargin{1};
  300. analysis = varargin{2};
  301. if ischar(MB)
  302. MB = load(MB);
  303. MB = MB.MB;
  304. end
  305. switch analysis
  306. case('anatomy')
  307. % This figure illustrates the partition of states at the
  308. % first and subsequent scales. The upper right panel shows
  309. % all the constituent particles as a maximum intensity
  310. % projection, where the spatial support of each particle has
  311. % been colour-coded according to the variance explained by
  312. % its eigenmode. The upper middle panel shows the
  313. % corresponding adjacency matrix or coupling among particles.
  314. % The coloured circles encode the identity of each particle.
  315. % In this instance, the particles have been arranged in order
  316. % of descending dissipation (i.e., the principal eigenvalue
  317. % of each particles Jacobian). The upper right panel shows
  318. % these eigenvalues above the corresponding particle (encoded
  319. % by coloured dots) in terms of rate constants (i.e., the
  320. % negative inverse of the eigenvalue of each particle). The
  321. % remaining panels show the first 12 particles as maximum
  322. % intensity projections. The colour of the background
  323. % corresponds to the colour that designates each particle. In
  324. % this first level, each particle has a single eigenstate.
  325. % The numbers in brackets above each maximum intensity
  326. % projection correspond to the number of internal, active and
  327. % sensory states, respectively, where the active and sensory
  328. % states comprise blanket states. At this lowest level, every
  329. % eigenstate is a sensory state because it can influence, and
  330. % be influenced by,the eigenstates of other particles.
  331. % functional anatomy (space)
  332. %----------------------------------------------------------
  333. VOX = MB{1}.VOX;
  334. XYZ = MB{1}.XYZ;
  335. for i = 1:numel(MB)
  336. spm_figure('getwin',sprintf('Markov level %i',i)); clf;
  337. spm_mb_anatomy(MB{i},XYZ,VOX)
  338. end
  339. case('dynamics')
  340. % Intrinsic timescales in the brain: This figure reports
  341. % intrinsic timescales at intermediate scales. The left
  342. % column shows the eigenmodes in terms of their principal
  343. % frequency, i.e., the largest complex eigenvalue (divided by
  344. % 2*pi). The right column shows the corresponding eigenmodes
  345. % in terms of their principal time constants, i.e., the
  346. % reciprocal of the largest negative real part. These two
  347. % characterisations (principal frequency and time constant)
  348. % speak to different aspects of intrinsic timescales; both of
  349. % which contribute to the shape of an eigenstate’s
  350. % correlation function of time. The first quantifies the
  351. % frequency of solenoidal flow, while the second reflects the
  352. % rate of decay associated with the dissipative flow.
  353. % functional anatomy (time)
  354. %----------------------------------------------------------
  355. VOX = MB{1}.VOX;
  356. XYZ = MB{1}.XYZ;
  357. spm_figure('getwin','Timing'); clf;
  358. N = numel(MB) - 1;
  359. for i = 1:N
  360. % largest real and imaginary parts of each particle
  361. %------------------------------------------------------
  362. sr = zeros(size(MB{i}.V,2),1);
  363. si = zeros(size(MB{i}.V,2),1);
  364. for j = 1:numel(MB{i}.s)
  365. try
  366. z = MB{i}.z{j};
  367. sr(z) = max(real(MB{i}.s{j}));
  368. si(z) = max(imag(MB{i}.s{j}));
  369. end
  370. end
  371. % imaginary part (frequency)
  372. %------------------------------------------------------
  373. si = si/(2*pi);
  374. subplot(N,2,2*(i - 1) + 1),cla,hold off
  375. spm_mip(logical(abs(MB{i}.V))*si,XYZ,VOX);
  376. axis image, axis off
  377. str{1} = sprintf('Frequency - imaginary');
  378. str{2} = sprintf('%2.1f to %1.3f Hz',min(si),max(si));
  379. title(str,'FontSize',14,'FontWeight','bold')
  380. % real part (time constants)
  381. %------------------------------------------------------
  382. sr = (-1./sr);
  383. subplot(N,2,2*(i - 1) + 2),cla,hold off
  384. spm_mip(logical(abs(MB{i}.V))*sr,XYZ,VOX);
  385. axis image, axis off
  386. str{1} = sprintf('Dissipation - real (scale %i)',i);
  387. str{2} = sprintf('%2.1f to %2.1f sec',min(sr),max(sr));
  388. title(str,'FontSize',14,'FontWeight','bold')
  389. end
  390. case('distance')
  391. % Local connectivity: This figure reports some of the
  392. % statistical characteristics of dynamical coupling among
  393. % particles at the first level. The upper left panel plots
  394. % each connection in terms of the real part of the
  395. % corresponding Jacobian in Hz, against the distance spanned
  396. % by the connection (i.e., Euclidean distance between the
  397. % centres of the two particles). The upper left panel plots
  398. % the log-coupling (real part) against log-distance. The
  399. % lower panel plots the strength of reciprocal connections
  400. % against each other, to illustrate the relative proportions
  401. % of recurrent excitatory and inhibitory coupling. The
  402. % rarefied region in the centre of this scatterplot reflects
  403. % the fact that connections wIf youith small coupling strengths
  404. % have been eliminated during Bayesian model reduction.
  405. % spatial distance and (first-level) coupling
  406. %----------------------------------------------------------
  407. spm_figure('getwin','Distance rules'); clf;
  408. col = {'r','b'};
  409. % get distance (from averge location, xyz)
  410. %----------------------------------------------------------
  411. J = MB{1}.J;
  412. nv = length(J);
  413. D = abs(MB{1}.V);
  414. D = bsxfun(@rdivide,D,sum(D));
  415. xyz = MB{1}.XYZ*D;
  416. xyz(1,:) = abs(xyz(1,:));
  417. % characterise excitation and inhibitory coupling separately
  418. %----------------------------------------------------------
  419. u = 1/1024;
  420. for e = 1:2
  421. D = [];
  422. E = [];
  423. for i = 1:nv
  424. for j = 1:nv
  425. d = xyz(:,i) - xyz(:,j);
  426. d = sqrt(d'*d);
  427. if e > 1
  428. if J(i,j) < -u && d
  429. D(end + 1,1) = sqrt(d'*d);
  430. E(end + 1,1) = abs(J(i,j));
  431. end
  432. else
  433. if J(i,j) > +u && d
  434. D(end + 1,1) = sqrt(d'*d);
  435. E(end + 1,1) = abs(J(i,j));
  436. end
  437. end
  438. end
  439. end
  440. % coupling (cumulative)
  441. %----------------------------------------------------------
  442. n = 16;
  443. c = zeros(n,1);
  444. k = zeros(n,1);
  445. d = linspace(8,max(D),n + 1);
  446. for i = 1:n
  447. j = D > d(i) & D < d(i + 1);
  448. c(i,1) = mean(E(j)); % mean coupling
  449. k(i,1) = sum(j); % numer of edges
  450. end
  451. d = spm_vec(d(1:n));
  452. j = k > mean(k)/4;
  453. d = d(j);
  454. c = c(j);
  455. k = k(j);
  456. % regression
  457. %----------------------------------------------------------
  458. [F,df,B] = spm_ancova([ones(size(d)) log(d)],[],log(c));
  459. subplot(2,2,1)
  460. plot(D,E,['.' col{e}],'MarkerSize',1), hold on
  461. plot(d,c,['o' col{e}],'MarkerSize',8)
  462. plot(d,exp(B(1))*d.^B(2),col{e},'LineWidth',2)
  463. title('Distance scaling rule','FontSize',16)
  464. xlabel('Distance (mm)'), ylabel('coupling strength (Hz}')
  465. axis square, box off, set(gca,'YLim',[0, 1])
  466. subplot(2,2,2)
  467. plot(log(d),log(c),['o' col{e}],'MarkerSize',8), hold on
  468. plot(log(d),B(1) + B(2)*log(d),col{e},'LineWidth',1)
  469. if e == 1
  470. str = sprintf('Log scaling (%2.2f',B(2));
  471. else
  472. str = [str sprintf(', %2.2f)',B(2))];
  473. end
  474. title(str,'FontSize',16)
  475. xlabel('log distance'), ylabel('log coupling')
  476. axis square, box off
  477. legend('excitatory',' ','inhibitory',' '),legend(gca,'boxoff')
  478. % subplot(2,2,3)
  479. % p = k./(d.^2);
  480. % p = p/sum(p);
  481. % plot(d,p,col{e}), hold on
  482. % title('Density','FontSize',16)
  483. % xlabel('distance (mm)'), ylabel('Density')
  484. % axis square, box off
  485. end
  486. % assymetry
  487. %----------------------------------------------------------
  488. D = [];
  489. E = [];
  490. for i = 1:nv
  491. for j = 1:nv
  492. if abs(J(i,j)) > exp(-8) && j ~= i
  493. D(end + 1,1) = J(j,i);
  494. E(end + 1,1) = J(i,j);
  495. end
  496. end
  497. end
  498. subplot(2,1,2)
  499. hold off, plot(E,D,'.r','MarkerSize',1)
  500. title('Reciprocal coupling','FontSize',16)
  501. xlabel('coupling (Hz)'), ylabel('coupling (Hz)')
  502. axis square, box off, axis([-1 1 -1 1])
  503. % percentages of different recurrent connections
  504. %----------------------------------------------------------
  505. R(1) = sum(D > 0 & E > 0);
  506. R(2) = sum(D < 0 & E > 0);
  507. R(3) = sum(D > 0 & E < 0);
  508. R(4) = sum(D < 0 & E < 0);
  509. R = 100*R/sum(R);
  510. text( 1/4, 1/4,sprintf('%2.0f p.c.',R(1)),'FontWeight','bold');
  511. text( 1/4,-1/4,sprintf('%2.0f p.c.',R(2)),'FontWeight','bold');
  512. text(-1/4, 1/4,sprintf('%2.0f p.c.',R(3)),'FontWeight','bold');
  513. text(-1/4,-1/4,sprintf('%2.0f p.c.',R(4)),'FontWeight','bold');
  514. case('scaling')
  515. % Scale invariance: This figure illustrates scaling behaviour
  516. % across the scales of the particular decomposition. The
  517. % upper panel plots the real part of the eigenvalues of each
  518. % particle against its spatial scale; namely the Calliper
  519. % width of the particle’s eigenmode. This is replicated for
  520. % each of the four scales, denoted by the different colours
  521. % (green, pink, cyan and puce, respectively). The expected
  522. % values are shown as encircled large dots. The lower left
  523. % panel plots the logarithms of these temporal and spatial
  524. % expectations against each other. The resulting regression
  525. % slope corresponds to the scaling exponent. The light grey
  526. % circles correspond to what would have been seen at higher
  527. % and lower scales. The lower right plot shows the same
  528. % regression in terms of the implicit time constant, as a
  529. % function of spatial scale expressed in millimetres.
  530. % time constants over scales
  531. %----------------------------------------------------------
  532. spm_figure('getwin','Scaling'); clf;
  533. N = numel(MB);
  534. SS = cell(N,1);
  535. SR = cell(N,1);
  536. for i = 1:N
  537. for j = 1:numel(MB{i}.s)
  538. % get spatial scale (standard deviation)
  539. %--------------------------------------------------
  540. S = sum(logical(abs(MB{i}.V(:,MB{i}.z{j})))).^(1/3);
  541. SS{i} = [SS{i}; mean(S)];
  542. % get temporal scale (eigenvalue)
  543. %--------------------------------------------------
  544. S = real(MB{i}.s{j});
  545. SR{i} = [SR{i}; mean(S)];
  546. end
  547. end
  548. % Expectations and graphics
  549. %----------------------------------------------------------
  550. for i = 1:N
  551. j = isfinite(SS{i});
  552. SS{i} = SS{i}(j);
  553. ss(i,1) = mean(SS{i});
  554. j = isfinite(SR{i});
  555. SR{i} = SR{i}(j);
  556. sr(i,1) = mean(SR{i});
  557. end
  558. subplot(2,1,1), hold off
  559. col = spm_MB_col(N);
  560. for i = 1:N
  561. plot(SS{i},SR{i},'.','MarkerSize', 8,'Color',col{i}), hold on
  562. plot(ss(i),sr(i),'.','MarkerSize',32,'Color',col{i})
  563. plot(ss(i),sr(i),'o','MarkerSize',32,'Color',col{i})
  564. end
  565. title('Scale invariance','FontSize',16)
  566. xlabel('spatial scale (mm)'), ylabel('eigenvalue (Hz)')
  567. axis square, box off, hold off
  568. % regression (Time)
  569. %----------------------------------------------------------
  570. ii = (1:N)'; % scale
  571. [F,df,Br] = spm_ancova([ones(N,1) ii], [],-log(-sr));
  572. [F,df,Bs] = spm_ancova([ones(N,1) ii], [], log( ss));
  573. [F,df,A ] = spm_ancova([ones(N,1) log(ss)],[],-log(-sr));
  574. A = [A(1), Br(2)/Bs(2)];
  575. fprintf('Beta (exp) time: %2.2f (%2.2f)\n',Br(2),exp(Br(2)));
  576. fprintf('Beta (exp) space: %2.2f (%2.2f)\n',Bs(2),exp(Bs(2)));
  577. fprintf('Alpha: %2.2f\n',A(2));
  578. % extrapolate
  579. %----------------------------------------------------------
  580. bs = exp(Bs(2)*(-4:4:8) + Bs(1))';
  581. br = exp(A(1) + A(2)*log(bs));
  582. S = linspace(min(bs),max(bs),64);
  583. subplot(2,2,3), cla, hold on
  584. plot(log(bs),log(br),'.','MarkerSize',32,'Color',[1,1,1]*.8)
  585. plot(log(bs),log(br),'o','MarkerSize',32,'Color',[1,1,1]*.8)
  586. for i = 1:N
  587. plot(log(SS{i}),-log(-SR{i}),'.','MarkerSize',4,'Color',col{i})
  588. plot(log(ss(i)),-log(-sr(i)),'.','MarkerSize',32,'Color',col{i})
  589. plot(log(ss(i)),-log(-sr(i)),'o','MarkerSize',32,'Color',col{i})
  590. hold on
  591. end
  592. plot(log(S),A(1) + A(2)*log(S))
  593. title(sprintf('Log scaling - %2.2f',A(2)),'FontSize',16)
  594. xlabel('log distance (mm)'), ylabel('log time constant')
  595. axis square, box off, hold off
  596. subplot(2,2,4), hold off
  597. plot(S,exp(A(1) + A(2)*log(S))), hold on
  598. plot(bs,br,'.','MarkerSize',32,'Color',[1,1,1]*.8)
  599. plot(bs,br,'o','MarkerSize',32,'Color',[1,1,1]*.8)
  600. title('Scaling behaviour','FontSize',16)
  601. xlabel('distance (mm)'), ylabel('time constant (sec)')
  602. axis square, box off
  603. % some canonical scales
  604. %----------------------------------------------------------
  605. disp('mm')
  606. disp(num2str(bs,'%2.2e'))
  607. disp('Seconds')
  608. disp(num2str(br,'%2.2e'))
  609. for i = 1:numel(bs)
  610. hold on, plot([bs(i),bs(i)],[0 br(i)],'r-.')
  611. end
  612. case('kernels')
  613. % Transfer functions: This figure characterises the dynamics
  614. % at successive scales in terms of transfer functions, as
  615. % quantified by the complex eigenvalues (c.f., a pole-zero
  616. % map). The left column shows the transfer functions over
  617. % frequency for all particles with a complex eigenvalue (at
  618. % successive scales). These eigenvalues are shown in the
  619. % right column in the complex number plane. As we ascend from
  620. % one scale to the next, the real part of the eigenvalue
  621. % approaches zero from the left and the number of eigenvalues
  622. % falls with the coarse-graining, i.e., number of particles.
  623. % The complex part of the eigenvalues corresponds to the peak
  624. % frequency of the associated transfer functions, while the
  625. % dispersion around this peak decreases as the real part
  626. % approaches zero. The emergence of spectral peaks in the
  627. % transfer functions inherit from the complex part of the
  628. % eigenvalues that emerge under asymmetric coupling with
  629. % solenoidal flow.
  630. % frequencies (Hz)
  631. %----------------------------------------------------------
  632. w = linspace(0,1/8,128);
  633. % transfer functions over scales
  634. %----------------------------------------------------------
  635. spm_figure('getwin','Transfer functions'); clf;
  636. for i = 2:min(4,numel(MB))
  637. % loop over particles
  638. %------------------------------------------------------
  639. nz = numel(MB{i}.z);
  640. col = spm_MB_col(nz);
  641. for p = 1:nz
  642. % loop over eigenmodes
  643. %--------------------------------------------------
  644. for j = 1:numel(MB{i}.s{p})
  645. % condition unstable eigenmodes
  646. %----------------------------------------------
  647. s = MB{i}.s{p}(j);
  648. if real(s) > 0
  649. s = 1j*imag(s) - 1/64;
  650. end
  651. % Transfer functions (if imaginary)
  652. %----------------------------------------------
  653. if imag(s) ~= 0
  654. % Transfer function
  655. %------------------------------------------
  656. S = 1./(1j*2*pi*w - s);
  657. subplot(3,2,(i - 2)*2 + 1), hold on
  658. plot(w,abs(S),'color',col{p})
  659. % Pole-zero map
  660. %------------------------------------------
  661. subplot(3,2,(i - 2)*2 + 2), hold on
  662. plot(MB{i}.s{p}(j),'.','MarkerSize',32,'color',col{p})
  663. end
  664. end
  665. end
  666. subplot(3,2,(i - 2)*2 + 1)
  667. title(sprintf('Scale %i',i - 1),'fontsize',16)
  668. xlabel('frequency (Hz)'), ylabel('transfer tunctions')
  669. axis square, box off, spm_axis tight, hold off
  670. subplot(3,2,(i - 2)*2 + 2)
  671. plot([0,0],[-1,1],':')
  672. title('Eigenvalues','fontsize',16)
  673. xlabel('real (Hz)'), ylabel('imaginary (Hz)')
  674. axis square, box off, axis([-1 1 -1/8 1/8]), hold off
  675. end
  676. case('connectivity')
  677. % Dynamic coupling: This figure characterises the coupling
  678. % between the two eigenstates, which (unless specified)
  679. % correspond to the strongest coupling at this highest scale.
  680. % This coupling is mediated by the corresponding element of
  681. % the (complex) Jacobian, circled in red in the upper middle
  682. % panel. The flanking panels on the left and right show the
  683. % corresponding eigenmodes in voxel space. The middle row
  684. % shows the auto-covariance functions of the two eigenstates,
  685. % illustrating serial correlations that can last for many
  686. % seconds. The lower panels report the cross-covariance
  687. % function between the two eigenstates, over 256 seconds
  688. % (lower left panel) and focusing on cross-covariances over
  689. % 32 seconds (lower right panel). Asymmetrical
  690. % cross-covariance (and implicitly cross-correlation)
  691. % function reflects the solenoidal coupling and the implicit
  692. % breaking of detailed balance the particular decomposition
  693. % accommodates.
  694. % functional anatomy
  695. %----------------------------------------------------------
  696. VOX = MB{1}.VOX;
  697. XYZ = MB{1}.XYZ;
  698. spm_figure('getwin',' extrinsic connectivity'); clf;
  699. spm_mb_anatomy(MB{end},XYZ,VOX)
  700. % Jacobian and cross covariance function
  701. %----------------------------------------------------------
  702. dfdx = full(MB{end}.J);
  703. [ccf,pst] = spm_ssm2ccf(dfdx);
  704. % get pair of eigenvariates
  705. %----------------------------------------------------------
  706. try
  707. i = varargin{3};
  708. j = varargin{4};
  709. catch
  710. A = dfdx;
  711. A = A - diag(diag(A));
  712. [d,i] = max(real(A(:)));
  713. [i,j] = ind2sub(size(A),i);
  714. end
  715. cf = ccf(:,i,j);
  716. lim = [min(cf) max(cf)];
  717. % if no correlations than plot conjugate modes
  718. %----------------------------------------------------------
  719. if max(abs(lim)) < 1e-6
  720. [i,j] = sort(imag(spm_vec(MB{end}.s)),'descend');
  721. i = j(1);
  722. j = j(end);
  723. end
  724. % graphics
  725. %----------------------------------------------------------
  726. subplot(3,2,3), plot(pst,ccf(:,i,i))
  727. title(sprintf('covariance: state %i',i),'FontSize',16)
  728. xlabel('lag (sec)'),ylabel('covariance')
  729. axis square, box off, spm_axis tight
  730. subplot(3,2,4), plot(pst,ccf(:,j,j))
  731. title(sprintf('covariance: state %i',j),'FontSize',16)
  732. xlabel('lag (sec)'),ylabel('covariance')
  733. axis square, box off, spm_axis tight
  734. subplot(3,2,5), plot(pst,ccf(:,i,j),[0,0],lim,':b')
  735. title(sprintf('cross-covariance: states %i,%i',i,j),'FontSize',16)
  736. xlabel('lag (sec)'),ylabel('covariance')
  737. if max(abs(lim)) < 1e-6, set(gca,'YLim',[-1,1]), end
  738. axis square, box off, spm_axis tight
  739. % blow-up around zero lag
  740. %----------------------------------------------------------
  741. [d,m] = max(abs(ccf(:,i,j)));
  742. m = pst(m);
  743. subplot(3,2,6), plot(pst,ccf(:,i,j),[0,0],lim,':b',[m,m],lim,'-.r')
  744. title(sprintf('cross-covariance: states %i,%i',i,j),'FontSize',16)
  745. xlabel('lag (sec)'),ylabel('covariance')
  746. if max(abs(lim)) < 1e-6, set(gca,'YLim',[-1,1]), end
  747. axis square, box off, spm_axis tight, set(gca,'XLim',[-1,1]*32)
  748. % modes
  749. %----------------------------------------------------------
  750. subplot(3,3,1),cla,hold off
  751. spm_mip(abs(MB{end}.V(:,i)),XYZ,VOX);
  752. axis image, axis off
  753. title(sprintf('Eigenmode %i',i),'FontSize',16)
  754. subplot(3,3,3),cla,hold off
  755. spm_mip(abs(MB{end}.V(:,j)),XYZ,VOX);
  756. axis image, axis off
  757. title(sprintf('Eigenmode %i',j),'FontSize',16)
  758. subplot(3,3,2), hold on, plot(j,i,'or','MarkerSize',16)
  759. case('eigenmodes')
  760. % Dissipative and solenoidal dynamics: This figure unpacks
  761. % the intrinsic coupling at the final (usually, single
  762. % particle) level. At this level, there are can be no
  763. % coupling between particles and (by construction) the
  764. % dynamics is completely characterised in terms of the
  765. % eigenstates that comprise the particle. In turn, these are
  766. % completely characterised by their complex eigenvalues;
  767. % namely, the intrinsic complex coupling. The upper panels
  768. % show the dissipative and solenoidal (kinetic) energy of the
  769. % eigenstates that comprise the particle. The corresponding
  770. % eigenmodes are shown in the subsequent panels as maximum
  771. % intensity projections (of their absolute values).
  772. % functional anatomy
  773. %----------------------------------------------------------
  774. spm_figure('getwin',' extrinsic coupling'); clf;
  775. VOX = MB{1}.VOX;
  776. XYZ = MB{1}.XYZ;
  777. % Jacobian
  778. %----------------------------------------------------------
  779. J = full(MB{end}.J);
  780. Y = full(MB{end}.Y);
  781. % complex form
  782. %----------------------------------------------------------
  783. J = diag(J);
  784. D = -real(J); % dissipative
  785. Q = (imag(J).^2)./D; % solenoidal
  786. % show dynamics
  787. %==========================================================
  788. try, dt = MB{1}.dt; catch, dt = 1; end
  789. try, i = varargin{3}; catch, [d,i] = max(Q); end
  790. subplot(4,2,1), bar(D)
  791. xlabel('eigenmode'),ylabel('kinetic energy'), axis square, box off
  792. title('Dissipative energy','FontSize',16)
  793. subplot(4,2,2), bar(Q)
  794. xlabel('eigenmode'),ylabel('kinetic energy'), axis square, box off
  795. title('Solenoidal energy','FontSize',16)
  796. % pst = (1:size(Y,1))*dt;
  797. % subplot(3,2,4), plot(pst,abs(Y(:,i)),'-',pst,angle(Y(:,i)),':')
  798. % xlabel('time'),ylabel('state'), axis square, box off
  799. % legend({'amplitude','angle'}), legend(gca,'boxoff')
  800. % title('Dissipative dynamics','FontSize',16)
  801. % mode
  802. %----------------------------------------------------------
  803. for i = 1:min(9,numel(D))
  804. subplot(4,3,i + 3),cla,hold off
  805. spm_mip(abs(MB{end}.V(:,i)),XYZ,VOX);
  806. axis image, axis off
  807. title(sprintf('Eigenmode %i',i),'FontSize',12,'FontWeight','bold')
  808. end
  809. case('responses')
  810. % Induced responses: This figure illustrates the expression
  811. % of experimental or condition-specific effects at different
  812. % scales of the particular decomposition. The top panel is an
  813. % unusual form of statistical parametric mapping; namely, and
  814. % image of the F statistic, testing for the significance of
  815. % an effect of any of any exogenous inputs. Each row of the F
  816. % statistic map corresponds to a scale and comprises the F
  817. % statistic for each successive particle at that scale. This
  818. % map shows that the effect of (some linear mixture of)
  819. % exogenous inputs can be detected at several scales, as
  820. % evidenced by the dark bars. unless specified, the most
  821. % significant eigenmode is shown on the lower left in voxel
  822. % space. It's expression over time (in terms of its real
  823. % value) is depicted in the middle panel (blue line), with
  824. % the best fitting prediction based upon exogenous input
  825. % (green line). This prediction is a contrast (i.e., linear
  826. % mixture) of the input functions shown in the design matrix
  827. % on the lower right. The coefficients of this contrast are
  828. % shown below the design matrix. The last column of the
  829. % design matrix is simply a column of ones.
  830. % functional anatomy
  831. %----------------------------------------------------------
  832. VOX = MB{1}.VOX;
  833. XYZ = MB{1}.XYZ;
  834. spm_figure('getwin','responses'); clf;
  835. % ANOVA
  836. %----------------------------------------------------------
  837. U = MB{1}.U;
  838. n = size(U,2);
  839. U(:,n + 1) = 1;
  840. c = spm_speye(n + 1,n);
  841. % search over scles and eigenmodes
  842. %----------------------------------------------------------
  843. for j = 1:numel(MB)
  844. for i = 1:size(MB{j}.Y,2)
  845. Y = real(MB{j}.Y(:,i));
  846. F(j,i) = spm_ancova(U,[],Y,c);
  847. end
  848. end
  849. % most significant mode
  850. %----------------------------------------------------------
  851. [Fj,j] = max(F,[],2);
  852. [Fi,i] = max(Fj);
  853. try, i = varargin{3}; end
  854. j = j(i);
  855. Y = real(MB{i}.Y(:,j));
  856. [Fi,df,beta] = spm_ancova(U,[],Y,c);
  857. p = 1 - spm_Fcdf(Fi,df);
  858. df = round(df);
  859. % show dynamics
  860. %==========================================================
  861. try, dt = MB{1}.dt; catch, dt = 1; end
  862. pst = (1:size(Y,1))*dt;
  863. str = 'Eigenvariate and prediction';
  864. str = sprintf('%s: F(%d,%d) = %2.1f, p = %2.3f',str,df(1),df(2),Fi,p);
  865. subplot(3,1,1), imagesc(1 - F)
  866. xlabel('eigenmode'),ylabel('scale'), spm_axis tight, box off
  867. title('F-statistic','FontSize',16), hold on
  868. plot(j,i,'or','MarkerSize',8)
  869. subplot(3,1,2), plot(pst,Y,':',pst,U*beta)
  870. xlabel('time'),ylabel('real part'), spm_axis tight, box off
  871. title(str,'FontSize',16)
  872. % mode
  873. %----------------------------------------------------------
  874. subplot(3,2,5),cla,hold off
  875. spm_mip(abs(MB{i}.V(:,j)),XYZ,VOX);
  876. axis image, axis off
  877. title(sprintf('Eigenmode %i',j),'FontSize',16)
  878. % inputs and contribution
  879. %----------------------------------------------------------
  880. subplot(6,2,10), imagesc(U)
  881. xlabel('input'),ylabel('time'), axis square, box off
  882. title('Inputs','FontSize',16)
  883. subplot(6,2,12), bar(beta)
  884. xlabel('input'),ylabel('contribution'), axis square, box off
  885. spm_axis tight
  886. case('connectogram')
  887. % Extrinsic connectivity: This figure illustrates asymmetric
  888. % extrinsic (between particle) coupling at the final scale
  889. % supplied in MB. The upper panels reproduce the results in
  890. % 'anatomy', while the lower panel is a connectogram
  891. % illustrating the coupling among eigenstates that constitute
  892. % the particles at this scale. The width of each connector
  893. % reflects the strength of the coupling; after dividing the
  894. % strength into five bins and eliminating the lowest bin. The
  895. % colour of the dots corresponds to the colour of the
  896. % particle in the upper right panel. The colour of the
  897. % connectors corresponds to the source of the strongest
  898. % (reciprocal) connection. The coupling strength corresponds
  899. % to the real part of the Jacobian, in Hz.
  900. % functional anatomy of penultimate levels
  901. %----------------------------------------------------------
  902. VOX = MB{1}.VOX;
  903. XYZ = MB{1}.XYZ;
  904. i = numel(MB);
  905. spm_figure('getwin',sprintf('connectogram level %i',i)); clf;
  906. spm_mb_anatomy(MB{i},XYZ,VOX,0)
  907. % assign colours to connections (afferent
  908. %----------------------------------------------------------
  909. MB = MB{i};
  910. nz = numel(MB.z); % number of vector states
  911. col = spm_MB_col(nz); % colours
  912. COL = [];
  913. for i = 1:nz
  914. for j = 1:numel(MB.s{i})
  915. COL(end + 1,:) = col{i}';
  916. end
  917. end
  918. % connectivity of undirected connectivity
  919. %----------------------------------------------------------
  920. subplot(2,1,2)
  921. spm_circularGraph(MB.J,'colormap',COL)
  922. axis square off
  923. title('Connectogram','FontSize',16)
  924. case('inputs')
  925. % Induced responses over space and time: this figure
  926. % characterises induced responses in terms of first order
  927. % Volterra kernels (i.e., impulse response functions) of
  928. % particles at the first (finest) scale of course graining.
  929. % Each row corresponds to the inputs specified. The left
  930. % column shows the expression of these inputs over particles
  931. % (weighted by the absolute value of their eigenmodes). This
  932. % effect is the variance attributable to each input (i.e.,
  933. % square of the corresponding kernel, summed over time), shown
  934. % in the left row. These kernels are shown for the 32
  935. % particles with the greatest (absolute) magnitude.
  936. % functional anatomy (1st order kernels)
  937. %----------------------------------------------------------
  938. spm_figure('getwin','input effects'); clf;
  939. VOX = MB{1}.VOX;
  940. XYZ = MB{1}.XYZ;
  941. nu = size(MB{1}.U,2);
  942. dfdx = MB{1}.J;
  943. dfdu = MB{1}.K;
  944. pst = (1:64)*4;
  945. ker = spm_ssm2ker(dfdx,dfdu,[],pst);
  946. for i = 1:nu
  947. % spatial expression
  948. %-------------------------------------------------------
  949. subplot(nu,2,2*(i - 1) + 1)
  950. K = sum(ker(:,:,i).^2,1);
  951. spm_mip(abs(MB{1}.V*K(:)),XYZ,VOX);
  952. axis image, axis off
  953. title(MB{1}.name{i},'FontSize',16)
  954. % temporal expression
  955. %-------------------------------------------------------
  956. [d,j] = sort(abs(ker(1,:,i)),'descend');
  957. subplot(nu,2,2*(i - 1) + 2)
  958. plot(pst,ker(:,j(1:64),i))
  959. xlabel('time (secs)'),ylabel('response'), axis square, box off
  960. title('Neuronal responses','FontSize',16)
  961. end
  962. otherwise
  963. error('Unknown action.');
  964. end
  965. otherwise
  966. error('Unknown action.');
  967. end
  968. %% subroutines
  969. %==========================================================================
  970. % functional anatomy - distance (R)
  971. %==========================================================================
  972. function [R,S] = spm_mb_distance(V,XYZ)
  973. % FORMAT [R,S] = spm_mb_distance(V,XYZ)
  974. % V - pattern vectors
  975. % XYZ - locations
  976. %
  977. % R - distance between patterns
  978. % S - spatial dispersion of patterns (sd; mm)
  979. %__________________________________________________________________________
  980. % distance matrix (mm)
  981. %--------------------------------------------------------------------------
  982. nv = size(V,2);
  983. R = zeros(nv,nv);
  984. D = abs(V);
  985. D = bsxfun(@rdivide,D,sum(D));
  986. xyz = XYZ*D;
  987. S = (XYZ.^2)*D - (XYZ*D).^2;
  988. S = sqrt(mean(S(:)));
  989. % interhemispheric coupling
  990. %--------------------------------------------------------------------------
  991. xyz(1,:) = abs(xyz(1,:));
  992. for i = 1:nv
  993. for j = i:nv
  994. d = xyz(:,i) - xyz(:,j);
  995. d = sqrt(d'*d);
  996. R(i,j) = d;
  997. R(j,i) = d;
  998. end
  999. end
  1000. % functional anatomy
  1001. %==========================================================================
  1002. function spm_mb_anatomy(MB,XYZ,VOX,N)
  1003. %__________________________________________________________________________
  1004. % set-up
  1005. %--------------------------------------------------------------------------
  1006. if nargin < 4, N = 12; end
  1007. nz = numel(MB.z); % number of particles
  1008. ns = size(MB.W,2); % number of states (n - 1)
  1009. nx = size(MB.J,2); % number of states (n)
  1010. col = spm_MB_col(nz); % colours
  1011. % functional anatomy of states
  1012. %--------------------------------------------------------------------------
  1013. subplot(3,3,1),cla,hold off
  1014. c = var(abs(MB.Y));
  1015. spm_mip(logical(abs(MB.V))*c',XYZ,VOX);
  1016. axis image, axis off
  1017. str{1} = sprintf('%d states, %d particles',ns,nz);
  1018. str{2} = sprintf('(%d eigenstates)',nx);
  1019. title(str,'FontSize',16)
  1020. subplot(3,3,2),cla,hold off
  1021. if nx > 128
  1022. imagesc(~abs(MB.J))
  1023. else
  1024. J = real(MB.J);
  1025. imagesc(max(J,-1/8))
  1026. end
  1027. axis square
  1028. title({'Jacobian';''},'FontSize',16)
  1029. xlabel('States'), hold on
  1030. subplot(3,3,3),cla,hold off
  1031. bar(-1./real(spm_vec(MB.s)))
  1032. axis square, set(gca,'XLim',[0,nx + 1])
  1033. title('Time constants','FontSize',16)
  1034. xlabel('states'),ylabel('seconds')
  1035. % label vector states (states of particles previous level)
  1036. %--------------------------------------------------------------------------
  1037. xi = 1;
  1038. for i = 1:nz
  1039. for j = 1:numel(MB.s{i})
  1040. hold on, subplot(3,3,2), plot(xi,0,'.','Color',col{i},'MarkerSize',24)
  1041. hold on, subplot(3,3,3), plot(xi,0,'.','Color',col{i},'MarkerSize',24)
  1042. xi = xi + 1;
  1043. end
  1044. end
  1045. % functional anatomy of particles
  1046. %--------------------------------------------------------------------------
  1047. nn = min(nz,N);
  1048. for j = 1:nn
  1049. Z = any(MB.W(:,MB.x{1,j}),2)*2; % active states
  1050. Z = any(MB.W(:,MB.x{2,j}),2)*1 + Z; % sensory states
  1051. Z = any(MB.W(:,MB.x{3,j}),2)*3 + Z; % internal states
  1052. % get subplot layout
  1053. %----------------------------------------------------------------------
  1054. if nn == 1
  1055. ni = 3; nj = 1;
  1056. elseif nn == 2
  1057. ni = 3; nj = 2;
  1058. elseif nn == 3
  1059. ni = 3; nj = 3;
  1060. elseif nn == 4
  1061. ni = 3; nj = 2;
  1062. elseif nn == 5
  1063. ni = 4; nj = 2;
  1064. elseif nn == 6
  1065. ni = 4; nj = 3;
  1066. else
  1067. ni = 4; nj = 4;
  1068. end
  1069. subplot(ni,nj,j + nj)
  1070. [z,i] = max(Z);
  1071. if z < 3, Z(i) = 3; end
  1072. mip = spm_mip(Z,XYZ,VOX);
  1073. for k = 1:3
  1074. c = col{j}(k)/2;
  1075. MIP(:,:,k) = (1 - mip/64)*(1 - c) + c;
  1076. end
  1077. image(MIP), axis image, axis off
  1078. str{1} = sprintf('Particle %d of %d (%d,%d,%d)',j,nz,...
  1079. numel(MB.x{3,j}),numel(MB.x{1,j}),numel(MB.x{2,j}));
  1080. str{2} = sprintf('%d eigenmodes',numel(MB.z{j}));
  1081. title(str,'FontWeight','Bold')
  1082. end

spm_mb_ui_mod.m at commit cdab728, under AGPL-3.0 · at the source

Overview

  1. Bio-Electric Department, School of Electrical and Computer Engineering, University of Tehran, Tehran, Iran
Institutions: University of Tehran (Iran)
Journal: Imaging neuroscience (Cambridge, Mass.), volume 4, article IMAG.a.1234
Dates: received 26 June 2025; accepted 8 April 2026; published online 22 May 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1162/imag.a.1234 · PMID 42206220 · PMCID PMC13206500 · OpenAlex W4411325862
Open access: diamond, a free copy (OpenAlex)
Status: code verified
Categories: computational modeling (no new data) (modality), computational (subfield)
Methods: Statistics, Machine learning
Keywords: dynamic causal modeling, multiscale analysis, Bayesian model reduction, structure learning, minimum cut, graph theory, Markov blanket, scale invariance
Topic: Functional Brain Connectivity Studies (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Citations: not cited yet (Europe PMC); 196 references in the paper

Abstract

The hierarchical organization of the brain’s distributed network has received growing interest from the neuroscientific community, largely because of its potential to enhance our understanding of human cognition and behavior, in health and disease. This interest is motivated by the hypothesis that near-critical brain dynamics enable multiscale integration and segregation of neural dynamics. While most multiscale connectivity analyses focus on structural and functional networks, characterizing the effective connectome across multiple scales has been somewhat overlooked—primarily for computational reasons. The difficulty of estimating large cyclic causal models, together with the scarcity of theoretical frameworks for systematically moving between scales, has hindered progress in this direction. This technical note introduces a top–down multiscale parcellation scheme for dynamic causal models, with application to neuroimaging data. The method is based on Bayesian model comparison, as a generalization of the well-known ΔBIC method. To facilitate computation, recent developments in linear dynamic causal modeling (DCM) and Bayesian model reduction (BMR) are deployed. Specifically, a naïve version of BMR is introduced, enabling the parcellation scheme to scale to hundreds or thousands of regions. Notably, the derivations reveal an analytical relationship between reduced model evidence and minimum cut problem in graph theory. This duality puts the tools of graph theory at the service of model evidence optimization and significance testing. The proposed method was applied to simulated and empirical causal models to establish face and construct validity. Consequently, the large empirical causal network, inferred from a neuroimaging dataset, exhibited log–log scaling trends, suggestive of scale invariance in multiple dynamical measures. Future generalizations of this technique and its potential applications in systems and clinical neuroscience are discussed.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repository

Its files are read in the Code ↔ Paper reader above, with 9 matches between paragraphs and lines of code.

tszarghami/Parcellation

License: AGPL-3.0
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Commit: cdab728b3b1cf4541279f2d1165fdc0e171c780c, 14 May 2026
Languages: MATLAB (22)
Size: 46 files, 22 scripts
Software Heritage: not archived
Found in: “Data and Code Availability”
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: SPM (8 files), Statistics and Machine Learning Toolbox (3 files)
Availability: 1 check, the latest on 28 September 2026: the link answers
  • 28 September 2026: the link answers
24 files

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 22 scripts, each with its path and the digest of its content;
  • 9 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data and Code Availability

MATLAB code to reproduce the results presented in this paper is available at: https://github.com/tszarghami/Parcellation. Linearized DCM, PEB, and BMR procedures are implemented using MATLAB routines (spm_dcm_J.m, spm_dcm_peb.m, spm_dcm_bmr.m) in SPM12 software package (https://www.fil.ion.ucl.ac.uk/spm/). Spectral clustering is implemented using the Compressive Spectral Clustering Toolbox (http://cscbox.gforge.inria.fr/), and graph randomization is performed using functions from the Brain Connectivity Toolbox (https://sites.google.com/site/bctnet/). The attention-to-visual-motion fMRI dataset analyzed in this study is publicly available at: https://www.fil.ion.ucl.ac.uk/spm/data/attention/. Appendices are provided as Supplementary Material (https://doi.org/10.1162/IMAG.a.1234#supplementary-data).

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 28 September 2026: the first record

Recorded: type, language, journal, volume, pages, dates, 1 author, 8 keywords, 182 references.

Cite

This paper

Zarghami, T. S. (2026). Multiscale parcellation of dynamic causal models of the brain. Imaging neuroscience (Cambridge, Mass.), 4, IMAG.a.1234. https://doi.org/10.1162/imag.a.1234

BibTeX

@article{zarghami2026multiscale,
author = {Zarghami, Tahereh S},
title = {{Multiscale parcellation of dynamic causal models of the brain}},
journal = {Imaging neuroscience (Cambridge, Mass.)},
year = {2026},
month = may,
volume = {4},
pages = {IMAG.a.1234},
publisher = {MIT Press},
issn = {2837-6056},
doi = {10.1162/imag.a.1234},
url = {https://doi.org/10.1162/imag.a.1234},
pmid = {42206220},
pmcid = {PMC13206500}
}

RIS

TY - JOUR
AU - Zarghami, Tahereh S
TI - Multiscale parcellation of dynamic causal models of the brain
T2 - Imaging neuroscience (Cambridge, Mass.)
J2 - Imaging Neurosci (Camb)
PY - 2026
DA - 2026/05/22
VL - 4
SP - IMAG.a.1234
SN - 2837-6056
PB - MIT Press
DO - 10.1162/imag.a.1234
UR - https://doi.org/10.1162/imag.a.1234
LA - en
ER -

CSL-JSON

{
"id": "10.1162/imag.a.1234",
"type": "article-journal",
"title": "Multiscale parcellation of dynamic causal models of the brain",
"container-title": "Imaging neuroscience (Cambridge, Mass.)",
"author": [
{
"family": "Zarghami",
"given": "Tahereh S"
}
],
"container-title-short": "Imaging Neurosci (Camb)",
"volume": "4",
"page": "IMAG.a.1234",
"DOI": "10.1162/imag.a.1234",
"PMID": "42206220",
"PMCID": "PMC13206500",
"ISSN": "2837-6056",
"publisher": "MIT Press",
"URL": "https://doi.org/10.1162/imag.a.1234",
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
22
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-74466-2 [code]
Neuromorphic hierarchical modular reservoirs.
Journal: Nature communications
In common: computational, 8 references
[2] doi:10.1007/s12021-025-09759-w [code]
Limitations of Variational Laplace-Based Dynamic Causal Modelling for Multistable Cortical Circuits.
Journal: Neuroinformatics
In common: SPM, Statistics and Machine Learning Toolbox, computational, 6 references
[3] doi:10.7554/elife.103097 [code]
Canonical neurodevelopmental trajectories of structural and functional manifolds.
Journal: eLife
In common: Statistics and Machine Learning Toolbox, 6 references
[4] doi:10.1038/s42003-026-10132-z [code]
Hippocampal criticality tracks cognitive demand and shifts with memory impairment.
Journal: Communications biology
In common: 6 references
[5] doi:10.1038/s41467-026-73347-y [code]
A week in the life of the human brain reveals stable states punctuated by chaotic-like transitions.
Journal: Nature communications
In common: Statistics and Machine Learning Toolbox, computational, computational modeling (no new data), 4 references
[6] doi:10.1038/s41593-026-02205-3 [code]
Competitive interactions shape mammalian brain network dynamics and computation.
Journal: Nature neuroscience
In common: SPM, Statistics and Machine Learning Toolbox, computational modeling (no new data), 3 references
[7] doi:10.1162/imag.a.1250 [code]
Dynamics-informed priors (DIP) for neural mass modelling.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: SPM, Statistics and Machine Learning Toolbox, 3 references
[8] doi:10.1002/advs.202523009 [code]
Personalized Network-Guided Neuromodulation Enhances Human Working Memory.
Journal: Advanced science (Weinheim, Baden-Wurttemberg, Germany)
In common: SPM, Statistics and Machine Learning Toolbox, 3 references
[9] doi:10.1371/journal.pbio.3003916 [code]
Arousal-driven critical roaming reproduces human functional connectivity dynamics.
Journal: PLoS biology
In common: Statistics and Machine Learning Toolbox, 4 references
[10] doi:10.1038/s43856-026-01707-2 [code]
Decreased amyloid-related structure-function coupling in preclinical Alzheimer's disease.
Journal: Communications medicine
In common: SPM, Statistics and Machine Learning Toolbox, 3 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.