OSCR

Joint estimation of source dynamics and interactions from MEG data

Code ↔ Paper

5 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 5 matches · 1 of them tie a paragraph to a whole file, not to given lines: a weak match, whose lines are not tinted
  1. [1] § MATERIALS AND METHODS › Reference Source Estimation With Beamformers and MVAR Fitting ↔ joint_est/saem.m, lines 1–34 · score 0.65 · lead field matrix, covariance matrix, source space, iterative, Ns, MCMV
  2. [2] § MATERIALS AND METHODS › Real MEG Data › Preprocessing. ↔ EcoG_simu/extract_ecog_data.m, lines 24–102 · score 0.63 · pass filtered, preprocessed, Epochs, baseline, fT, 0.3 Hz
  3. [3] § MATERIALS AND METHODS › Simulation Using ECoG Signals ↔ joint_est/saem.m, lines 1–34 · score 0.60 · source space, measurement noise, MVAR Models, vertices, algorithms, Ns
  4. [4] § MATERIALS AND METHODS › Reference Source Estimation With Beamformers and MVAR Fitting ↔ two_step_est/source_localizers/mkfilt_lcmv.m, the whole file · a weak match · score 0.60 · lead field matrix, covariance matrix, LCMV, beamformers, filters, Ns
  5. [5] § MATERIALS AND METHODS › JEDI-MEG ↔ joint_est/saem.m, lines 419–499 · score 0.50 · Kalman filter, source amplitudes, PMCMC, particle, SAEM

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 · 501 lines · 17 KB · MIT · 3 matches

  1. function [state, params, LL_complete]= saem(init, model, opt_params, Y_avg, Y, Y_mcmv, Ns, Np, P, dist_thr, gpu_flag, whiten_flag, mcmv_prior_flag)
  2. %AUTHOR : NARAYAN SUBRAMANIYAM /AALTO/NBE/
  3. % INPUTS
  4. % 1) init : struct containing initial values for parameters and kalman
  5. % mean/cov . init.A0, init.V_q0, init.q0, init.P0
  6. % 2) model : struct containing model params
  7. % model.G : lead-field matrix
  8. %model.XI : measurement noise covariance matrix
  9. %model.V_r : jitter matrix for particles
  10. %model.mesh : mesh details (mesh.p, mesh.e)
  11. %model.incl_vert : list of vertices included in source space. Its dimension
  12. %should be the same as the no. of columns in lead field
  13. %model.anat_parc : anatomical parcels (this will be optional in future.
  14. %Presently this info is used to initialize the particles in different
  15. %anatomical areas
  16. % 3) Y : MEG data (channels X T)
  17. % 4) opt_params : struct containing parameters the algorithm depends on
  18. %opt_params.Ns : no of sources / dipoles
  19. %opt_params.p : MVAR model order
  20. %opt_params.N : number of particles
  21. %opt_params.num_iter : no of iterations
  22. %opt_params.gamma : forgetting factor for SAEM
  23. %opt_params.dist_thr : distance threshold (just to make sure initial particles
  24. %draw are not too close to each other. This can be some value like 2 or 3
  25. %%%%%%%%%%%%%%PULL OUT VALUES FROM STRUCTS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26. % source space, lead-field matrix
  27. G = model.G;
  28. pnts_e = model.pnts_e;
  29. incl_vert = model.incl_verts; % source points used to calculate lead field
  30. pnts = pnts_e(incl_vert, :); %xyz of vertices included in source-space
  31. %initial parameter values
  32. A_tilde = init.A0; %AR matrix
  33. V_tilde = init.V0;
  34. P_tilde = init.P0;
  35. q_tilde = init.q0;
  36. if whiten_flag==0
  37. sigma_m = init.sigma_m0;
  38. sigma_b = init.sigma_b0;
  39. %measurement+bio noise cov matrix
  40. E = sigma_m^2*eye(size(G,1)) + sigma_b^2*(G*G');
  41. else
  42. E = eye(size(G,1));
  43. end
  44. % optimization parameters
  45. Niter = opt_params.Niter;
  46. gamma = opt_params.gamma;
  47. % set few constants
  48. Nq = Ns*P;
  49. Ny = size(Y,1);
  50. T = size(Y,2);
  51. Nj=size(Y,3); %no of trials
  52. Nr=Ns*3;
  53. CONST = -Ny * 0.5 * log(2*pi);
  54. % initialize sufficient statistics matrix
  55. S = zeros(3*Nq+Ny, 3*Nq+Ny);
  56. % parameter and state histories
  57. params.A_hist = zeros(Ns, Ns*P, Niter+1);
  58. params.A_hist(:,:,1) = A_tilde(1:Ns,:);
  59. params.V_hist(:,:,1) = V_tilde(1:Ns, 1:Ns);
  60. if whiten_flag==0
  61. params.sigma_m_hist(1) = sigma_m;
  62. params.sigma_b_hist(1) = sigma_b;
  63. end
  64. state.r_hat_est = zeros(Nr, T);
  65. state.qs_hat_est = zeros(Ns, T+1, Nj);
  66. state.qf_hat_est = zeros(Ns, T, Nj);
  67. state.r_hat_hist = zeros(Nr,Niter+1);
  68. %log-likelihoods
  69. LL_complete = zeros(Niter,1);
  70. %some variables for gpu
  71. if gpu_flag ==1
  72. look_up = zeros(Nj, Np);
  73. for j=1:Nj
  74. look_up(j,:) = (j-1)*Np+1 : Np*j;
  75. end
  76. Y_rep = zeros(Ny, Np, Nj);
  77. end
  78. % Random initialization of conditional trajectory
  79. if mcmv_prior_flag==0
  80. [ind_prime, r_prime, G_prime] = set_part_traj...
  81. (pnts, G, dist_thr, Ns, T); %for bbcb_simu
  82. else
  83. [ind_prime, r_prime, G_prime] = set_part_traj_mcmv_prior(Y_mcmv, eye(size(Y_mcmv,1)), G, pnts_e, incl_vert, Ns, size(Y_mcmv,2));
  84. end
  85. state.r_hat_hist(:,1) = mean(r_prime,2);
  86. m0=mean(r_prime,2);
  87. P0 = 16*eye(3*Ns);
  88. for k=1:1:Niter
  89. sprintf('iteration no %d', k)
  90. tic
  91. %Kalman filter variables. We assume Kalman covariance is same across
  92. %trials to keep things computationally feasible.
  93. q_tilde_kf = single(zeros(Nq,T,Np,Nj));
  94. q_tilde_kp = single(zeros(Nq,T,Np,Nj));
  95. P_tilde_kf = single(zeros(Nq,Nq,T,Np));
  96. P_tilde_kp = single(zeros(Nq,Nq,T,Np));
  97. % PMCMC variables
  98. r_pf = zeros(Nr,T,Np);
  99. ind_pf = zeros(Ns, T, Np);
  100. G_pf=zeros(Ny,Ns,T,Np);
  101. % weights
  102. w = single(zeros(Np,T));
  103. log_weights = single(zeros(Np,T));
  104. % replace Np-th particle with conditional trajectory
  105. r_pf(:,:,end) = r_prime(:,1:T);
  106. G_pf(:,:,:,end) = G_prime(:,:,1:T);
  107. ind_pf(:,:,end) = ind_prime(:,1:T);
  108. % initialize Kalman filter
  109. q_tilde_kp(:,1,:,:) = repmat(q_tilde,[1,1,Np, Nj]);
  110. P_tilde_kp(:,:,1,:) = repmat(P_tilde,[1,1,1, Np]);
  111. %initialize weights
  112. w(:,1) = ones(size(w(:,1)));
  113. w(:,1) = w(:,1)./sum(w(:,1));
  114. % stats for backward smoothing
  115. omega_tr = zeros(Ns, Ns, T-1, Nj);
  116. lambda_tr = zeros(Ns, T-1, Nj);
  117. % Ancestor indices
  118. an_hist = zeros(Np, T);
  119. % Compute lambda, omega for conditional trajectory
  120. for j=1:1:Nj
  121. [omega_tr(:,:,:,j), lambda_tr(:,:,j)] = compute_omega_lambda_fast...
  122. (A_tilde(1:Ns,1:Ns), V_tilde, G_pf, squeeze(Y(:,:,j)), E, Ns, P, Np, T);
  123. end
  124. omega_avg=squeeze(mean(omega_tr,4));
  125. lambda_avg=squeeze(mean(lambda_tr,3));
  126. % draw particles for t=1
  127. [ind_pf(:,1,1:end-1), r_pf(:,1,1:end-1), G_pf(:,:,1,1:end-1)] = ...
  128. set_all_part_traj_v2(pnts, G, dist_thr, Ns, Np-1,m0,P0);
  129. % draw particles for t=1
  130. %[ind_pf(:,1,1:end-1), r_pf(:,1,1:end-1), G_pf(:,:,1,1:end-1)] = ...
  131. %set_all_part_traj(pnts, G, dist_thr, Ns, Np-1);
  132. % stochastic E-STEP
  133. disp('entering time loop')
  134. for t=1:T
  135. if t >=2
  136. [a,~] = find(mnrnd(1,repmat(w(:,t-1)',Np-1,1))');
  137. [ind_pf(:,t,1:end-1), XI] = LW_model(squeeze(r_pf(:,t-1,a)), 0.95, pnts);
  138. log_det = 2*sum(log(diag(chol(XI))));
  139. for i=1:1:Ns
  140. r_pf(3*(i-1)+1:3*i,t,1:end-1) = pnts(ind_pf(i,t,1:end-1),:)';
  141. end
  142. for i=1:1:Np-1
  143. G_pf(:,:,t,i) = G(:,squeeze(ind_pf(:,t,i)));
  144. end
  145. q_tilde_kf_mean = squeeze(mean(q_tilde_kf(1:Ns,t-1,:,:),4));
  146. P_tilde_kf_mean = squeeze(P_tilde_kf(1:Ns,1:Ns,t-1,:))./Nj;
  147. if gpu_flag == 1
  148. parallel.gpu.enableCUDAForwardCompatibility(1)
  149. [aN] = compute_aN_gpu(repmat(r_pf(:,t,end), [1 1 Np]), r_pf(:,t-1,:), q_tilde_kf_mean, P_tilde_kf_mean, XI, omega_avg(1:Ns,1:Ns,t-1), lambda_avg(1:Ns,t-1),...
  150. w(:,t-1), Np, CONST, log_det);
  151. else
  152. [aN] = compute_aN_fast(repmat(r_pf(:,t,end), [1 1 Np]), r_pf(:,t-1,:), q_tilde_kf_mean, P_tilde_kf_mean, XI, omega_avg(:,:,t-1), lambda_avg(:,t-1),...
  153. Ns, w(:,t-1), Np, CONST, log_det);
  154. end
  155. an_hist(:,t) = [a;aN];
  156. end
  157. if gpu_flag == 1 % perform kalman predict, update and log-likelihood computation on GPU
  158. G_tilde = squeeze(G_pf(:,:,t,:));
  159. for j=1:Nj
  160. Y_rep(:,:,j) = repmat(squeeze(Y(:,t,j)), [1, 1, Np]);
  161. end
  162. Y_reshape = reshape(Y_rep, Ny, Np*Nj);
  163. %kalman predict(GPU)
  164. if t >= 2
  165. % tic
  166. q_tilde_kf_ = reshape(squeeze(q_tilde_kf (:,t-1,:,:)), Nq, Np*Nj);
  167. [q_tilde_kp_, P_tilde_kp(:,:,t,:)] = gpu_kalman_predict(q_tilde_kf_, squeeze(P_tilde_kf(:,:,t-1,:)), A_tilde, V_tilde);
  168. q_tilde_kp (:,t,:,:) = reshape(q_tilde_kp_, Nq, Np, Nj);
  169. % toc
  170. end
  171. % kalman update(GPU)
  172. %tic
  173. q_tilde_kp_ = reshape(squeeze(q_tilde_kp(:,t,:,:)), Nq, Np*Nj);
  174. q_tilde_kp_gpu = gpuArray(q_tilde_kp_);
  175. P_tilde_kp_gpu = gpuArray(squeeze(P_tilde_kp(:,:,t,:)));
  176. Y_gpu = gpuArray(Y_reshape);
  177. G_tilde_ = repmat(G_tilde, [1 1 1 Nj]);
  178. G_tilde_=reshape(G_tilde_, Ny,Ns,Np*Nj);
  179. G_tilde_gpu = gpuArray(G_tilde);
  180. G_tilde_gpu_ = gpuArray(G_tilde_);
  181. E_gpu = gpuArray(E);
  182. [q_tilde_kf_, P_tilde_kf(:,:,t,:), Kf_] = gpu_kalman_update(q_tilde_kp_gpu, P_tilde_kp_gpu, Y_gpu, G_tilde_gpu, G_tilde_gpu_, E_gpu, Np, Nj);
  183. q_tilde_kf(:,t,:,:) = reshape(q_tilde_kf_, Nq, Np, Nj);
  184. %toc
  185. for i=1:Np
  186. tmp_G_tilde = squeeze(G_tilde(:,:,i));
  187. ypred(:,i) = tmp_G_tilde*mean(q_tilde_kp_(1:Ns, look_up(:,i)),2);
  188. sigma(:,:,i) = (tmp_G_tilde*squeeze(P_tilde_kp (1:Ns,1:Ns,t,i))*tmp_G_tilde' + E )./Nj;
  189. log_det_sigma(i) = 2*sum(log(diag(chol(squeeze(sigma(:,:,i))))));
  190. end
  191. %tic
  192. log_weights(:,t) = gpu_logpdf(Y_avg(:,t),ypred,sigma, log_det_sigma,Np,Ny);
  193. %toc
  194. else
  195. for i = 1:Np
  196. for j=1:1:Nj
  197. % Prediction
  198. if t >= 2
  199. [q_tilde_kp(:,t,i,j), P_tilde_kp(:,:,t,i)] = kalman_predict(q_tilde_kf(:,t-1,i,j), P_tilde_kf(:,:,t-1,i), A_tilde, V_tilde );
  200. end
  201. % Update
  202. tmp_G_tilde = [G_pf(:,:,t,i) repmat(zeros(size(G_pf(:,:,t,i))), 1, P-1)];
  203. [q_tilde_kf(:,t,i,j), P_tilde_kf(:,:,t,i), Kf(:,:,i)] = kalman_update(q_tilde_kp(:,t,i,j), P_tilde_kp(:,:,t,i), squeeze(Y(:,t,j)),tmp_G_tilde, E);
  204. end
  205. % log-likelihood
  206. ypred(:,i) = tmp_G_tilde*squeeze(mean(q_tilde_kp(:,t,i,:),4));
  207. sigma(:,:,i) = (tmp_G_tilde*P_tilde_kp(:,:,t,i)*tmp_G_tilde' + E )./Nj;
  208. log_weights(i,t)=logpdf(Y_avg(:,t), ypred(:,i), sigma(:,:,i));
  209. end
  210. end
  211. % PF weight update
  212. maxlog = max(log_weights(:,t));
  213. log_weights(:,t) = log_weights(:,t) - maxlog;
  214. w(:,t) = exp(log_weights(:,t));
  215. w(:,t) = w(:,t) / sum(w(:,t));
  216. end
  217. % set trajectories based on ancestral history
  218. ind_an = an_hist(:,T);
  219. for t = T-1:-1:1
  220. r_pf(:,t,:) = r_pf(:,t,ind_an);
  221. q_tilde_kp(:,t,:,:) = q_tilde_kp(:,t,ind_an,:);
  222. P_tilde_kp(:,:,t,:) = P_tilde_kp(:,:,t,ind_an);
  223. q_tilde_kf(:,t,:,:) = q_tilde_kf(:,t,ind_an,:);
  224. P_tilde_kf(:,:,t,:) = P_tilde_kf(:,:,t,ind_an);
  225. G_pf(:,:,t,:) = G_pf(:,:,t,ind_an);
  226. ind_an = an_hist(ind_an,t);
  227. end
  228. if gpu_flag==1
  229. q_tilde_ks = zeros(Nq,T+1,Np*Nj); P_tilde_ks = zeros(Nq,Nq,T+1,Np);
  230. M = zeros(Nq,Nq,T,Np);
  231. q_tilde_kp = reshape(q_tilde_kp, Nq, T, Np*Nj);
  232. q_tilde_kf = reshape(q_tilde_kf, Nq, T, Np*Nj);
  233. P_tilde_ks(:,:,end,:) = squeeze(P_tilde_kp(:,:,end,:)); P_tilde_ks(:,:,end-1,:) = squeeze(P_tilde_kf(:,:,end,:));
  234. q_tilde_ks(:,end,:) = squeeze(q_tilde_kp(:,end,:)); q_tilde_ks(:,end-1,:) = squeeze(q_tilde_kf(:,end,:));
  235. P_tilde_ks_t1 = squeeze(P_tilde_ks(:,:,end-1,:));
  236. q_tilde_ks_t1 = squeeze( q_tilde_ks(:,end-1,:));
  237. for t = T-1:-1:1
  238. P_tilde_kf_t = squeeze(P_tilde_kf(:,:,t,:));
  239. P_tilde_kp_t1 = squeeze(P_tilde_kp(:,:,t+1,:));
  240. q_tilde_kf_t = squeeze(q_tilde_kf(:,t,:));
  241. q_tilde_kp_t1 = squeeze(q_tilde_kp(:,t+1,:));
  242. [J(:,:,t,:), q_tilde_ks(:,t,:), P_tilde_ks(:,:,t,:)] ...
  243. = gpu_kalman_smoother(P_tilde_kf_t, P_tilde_kp_t1, q_tilde_kf_t,q_tilde_kp_t1, ...
  244. q_tilde_ks_t1, P_tilde_ks_t1, A_tilde, Np, Nj);
  245. P_tilde_ks_t1 = squeeze(P_tilde_ks(:,:,t,:));
  246. q_tilde_ks_t1 = squeeze( q_tilde_ks(:,t,:));
  247. end
  248. % Computing of P_{t-1,t|T}
  249. G_T = [G_pf(:,:,T,:) repmat(zeros(size(G_pf(:,:,T,:))), 1, P-1)];
  250. G_T=squeeze(G_T);
  251. I=eye(Nq);
  252. M(:,:,end,:) = gpu_init_M(I, squeeze(Kf_(:,:,:)), G_T, squeeze(P_tilde_kf(:,:,T-1,:)), A_tilde);
  253. for t=T-1:-1:2
  254. P_tilde_kf_t = squeeze(P_tilde_kf(:,:,t,:));
  255. M_tp1 = squeeze(M(:,:,t+1,:));
  256. J_tm1 = squeeze(J(:,:,t-1,:));
  257. J_t = squeeze(J(:,:,t,:));
  258. M(:,:,t,:) = gpu_one_lag(A_tilde, P_tilde_kf_t, J_tm1, M_tp1, J_t);
  259. end
  260. q_tilde_ks = reshape(q_tilde_ks, Nq, T+1, Np, Nj);
  261. q_tilde_kf = reshape(q_tilde_kf, Nq, T, Np, Nj);
  262. else
  263. q_tilde_ks = zeros(Nq,T+1,Np,Nj); P_tilde_ks = zeros(Nq,Nq,T+1,Np);
  264. M = zeros(Nq,Nq,T,Np);
  265. for i = 1:Np
  266. % Inititalizing
  267. P_tilde_ks(:,:,end,i) = P_tilde_kp(:,:,end,i); P_tilde_ks(:,:,end-1,i) = P_tilde_kf(:,:,end,i);
  268. for t = T-1:-1:1
  269. J(:,:,t,i) = P_tilde_kf(:,:,t,i)*A_tilde'/P_tilde_kp(:,:,t+1,i);
  270. P_tilde_ks(:,:,t,i) = P_tilde_kf(:,:,t,i) + J(:,:,t,i)*(P_tilde_ks(:,:,t+1,i)-P_tilde_kp(:,:,t+1,i))*J(:,:,t,i)';
  271. end
  272. for j=1:Nj
  273. q_tilde_ks(:,end,i,j) = q_tilde_kp(:,end,i,j); q_tilde_ks(:,end-1,i,j) = q_tilde_kf(:,end,i,j);
  274. for t = T-1:-1:1
  275. q_tilde_ks(:,t,i,j) = q_tilde_kf(:,t,i,j)+J(:,:,t,i)*(q_tilde_ks(:,t+1,i,j)-q_tilde_kp(:,t+1,i,j));
  276. end
  277. end
  278. % Computing of M = P_{t-1,t|T}
  279. tmp_ = [G_pf(:,:,T,i) repmat(zeros(size(G_pf(:,:,T,i))), 1, P-1)];
  280. M(:,:,end,i) = (eye(Nq)-Kf(:,:,i)*tmp_)*A_tilde*P_tilde_kf(:,:,T-1,i);
  281. for t = T-1:-1:2
  282. M(:,:,t,i) = P_tilde_kf(:,:,t,i)*J(:,:,t-1,i)' + J(:,:,t,i)*(M(:,:,t+1,i)-A_tilde*P_tilde_kf(:,:,t,i))*J(:,:,t-1,i)';
  283. end
  284. end
  285. end
  286. star = logical(mnrnd(1,w(:,end)));
  287. r_prime = squeeze(r_pf(:,:,star));
  288. ind_prime = squeeze(ind_pf(:,:,star));
  289. G_prime = squeeze(G_pf(:,:,:,star));
  290. % M-STEP
  291. %Bt_s = zeros(3*Nq+Ny,3*Nq+Ny, T-1);
  292. % compute sufficient stats
  293. S3T = zeros(3*Nq+Ny,3*Nq+Ny);
  294. % compute sufficient stats
  295. Y_tmp = repmat(Y,[1 1 1 Np]);
  296. for t=2:T
  297. w_ = permute(repmat(w(:,t), [1 3*Nq+Ny 3*Nq+Ny 1]), [2 3 1]);
  298. w_1= squeeze(w_(:,1,:));
  299. Bt = compute_Bt(P_tilde_ks(:,:,t,:), P_tilde_ks(:,:,t-1,:), M(:,:,t,:), Nq, Ny, Np);
  300. Bt_s = sum(w_.*Bt, 3);
  301. for j=1:1:Nj
  302. S3T = suff_stats_fast(S3T, q_tilde_ks(:,t,:,j), q_tilde_ks(:,t-1,:,j), squeeze(Y_tmp(:,t,j,:)), Bt_s, Np, Nq, Ny, w_1);
  303. end
  304. end
  305. S = (1-gamma(k)).*S + gamma(k).*S3T;
  306. S=double(S);
  307. Phi = S(1:Nq,1:Nq);
  308. Psi = S(1:Nq,Nq+(1:Nq));
  309. Sigma = S(Nq+(1:Nq),Nq+(1:Nq));
  310. Xi_1 = S(2*Nq+Ny+(1:Nq),2*Nq+Ny+(1:Nq));
  311. Lambda_1 = S(2*Nq+(1:Ny),2*Nq+Ny+(1:Nq));
  312. Omega_1 = S(2*Nq+(1:Ny),2*Nq+(1:Ny));
  313. G_s = mean(squeeze(mean(G_pf, 4)),3);
  314. stats.Phi = Phi(1:Ns, 1:Ns);
  315. stats.Psi = Psi(1:Ns, 1:Nq);
  316. stats.Sigma = Sigma;
  317. stats.Xi = Xi_1(1:Ns,1:Ns);
  318. stats.Lambda = Lambda_1(:,1:Ns);
  319. stats.Omega = Omega_1;
  320. %compute complete likelihood before optimization
  321. LLT = compute_complete_ll(Nj*T, stats, V_tilde(1:Ns, 1:Ns), A_tilde(1:Ns,1:Nq), E, G_s(:,1:Ns));
  322. %estimate V_q
  323. V_tilde = (Phi - (Psi/Sigma)*Psi')/(Nj*T);
  324. V_tilde(Ns+1:Ns*P, 1:Ns)=0;
  325. V_tilde(1:Ns*P, Ns+1:end)=0;
  326. V_tilde(1:Ns, 1:Ns)=V_tilde(1:Ns, 1:Ns).*eye(Ns);
  327. % check if V_q is SPD
  328. V_tilde(1:Ns, 1:Ns) = max(V_tilde(1:Ns, 1:Ns),1e-4);
  329. if min(eig(V_tilde(1:Ns, 1:Ns)))< 0
  330. V_tilde(1:Ns, 1:Ns) = V_tilde(1:Ns, 1:Ns) + 0.001*eye(Ns);
  331. end
  332. V_tilde(1:Ns, 1:Ns);
  333. %estimate source amplitudes
  334. % q_ks_hat = mean(squeeze(mean(q_tilde_ks,4)),3);
  335. % q_kf_hat = mean(squeeze(mean(q_tilde_kf,4)),3);
  336. % estimate A
  337. tmp = Psi/Sigma;
  338. A_tilde = tmp(:,1:Nq);
  339. A_tilde(Ns+1:Ns*P, 1:Ns*(P-1)) = eye(Ns*(P-1));
  340. A_tilde(Ns+1:Ns*P, 1+Ns*(P-1):end) = zeros(Ns*(P-1), Ns);
  341. %estimate E
  342. if whiten_flag == 0
  343. S_R = Omega_1 - Lambda_1(:,1:Ns)*G_s' - G_s*Lambda_1(:,1:Ns)' + G_s*Xi_1(1:Ns,1:Ns)*G_s';
  344. sigma_m = grad_descent_sigmam(S_R, G, Nj*T, sigma_b, sigma_m)
  345. sigma_b = grad_descent_sigmab(S_R, G, Nj*T, sigma_b, sigma_m)
  346. E = sigma_m^2*eye(size(G,1)) + sigma_b^2*(G*G');
  347. % check if E is SPD
  348. [V_,D_] = eig(E);
  349. [I_,J_] = find(D_<0);
  350. if (~isempty(I_))
  351. for ii = 1:length(I_)
  352. D_(I_(ii),J_(ii)) = 1e-11;
  353. end
  354. E = V_*D_*V_';
  355. end
  356. end
  357. %compute complete likelihood after optimization
  358. LLTopt = compute_complete_ll(Nj*T, stats, V_tilde(1:Ns, 1:Ns), A_tilde(1:Ns,1:Nq), E, G_s(:,1:Ns));
  359. %store the histories of estimated parameters
  360. params.A_hist(:,:,k+1) = A_tilde(1:Ns,:);
  361. params.V_hist(:,:,k+1) = V_tilde(1:Ns, 1:Ns);
  362. if whiten_flag==0
  363. params.sigma_b_hist(1,k+1) = sigma_b;
  364. params.sigma_m_hist(1,k+1) = sigma_m;
  365. end
  366. display(['Iteration ',num2str(k),'. Increase in LL: ', num2str(LLTopt - LLT)])
  367. LL_complete(k,1) = LLTopt;
  368. % compute posterior means from PMCMC and Kalman filter
  369. r_pf_hat = zeros(Nr, T);
  370. for t=1:1:T
  371. r_pf_hat(:,t) = sum(repmat(w(:,t),...
  372. 1,3*Ns) .* ...
  373. squeeze(r_pf(:,t,:))');
  374. end
  375. state.r_hat_est = r_pf_hat;
  376. state.r_hat_hist(:,k) = mean(r_pf_hat,2);
  377. state.qf_hat_est = squeeze(mean(q_tilde_kf(1:Ns,:,:,:),3));
  378. state.qs_hat_est = squeeze(mean(q_tilde_ks(1:Ns,:,:,:),3));
  379. state.r_particles = r_pf;
  380. %state.qs_hist(:,:) = q_ks_hat(1:Ns,:);
  381. %state.qs_trials = squeeze(mean(q_tilde_ks(1:Ns,:,:,:),3));
  382. %state.qf_hist(:,:) = q_kf_hat(1:Ns,:);
  383. toc
  384. end
  385. end

saem.m at commit 3e0189c, under MIT · at the source

Overview

Authors: Narayan Puthanmadam Subramaniyam1, Filip Tronarp2, Simo Särkkä2, Lauri Parkkonen1
ORCID iDs: Lauri Parkkonen
  1. Department of Neuroscience and Biomedical Engineering, Aalto University, Espoo, Finland
  2. Department of Electrical Engineering and Automation, Aalto University, Espoo, Finland
Institutions: Aalto University (Finland)
Journal: n/a, volume 9, issue 3, pages 842-868
Dates: received 5 September 2024; accepted 4 March 2025; published online 17 July 2025
Type: Research article · Language: English
License: none stated
Identifiers: DOI 10.1162/netn_a_00453 · PMCID PMC12283153 · OpenAlex W4408559139
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: MEG (modality)
Methods: Spectral & time-frequency, Smoothing, state filtering, decompositions, Preprocessing, Statistics, Physiology & signal measures
Keywords: MEG, Bayesian filtering, Functional connectivity, Source localization
Topic: Underwater Acoustics Research (Oceanography, Earth and Planetary Sciences), according to OpenAlex
Funding: Research Council of Finland (289108)
Citations: not cited yet (Europe PMC); 45 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (none stated) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

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

narayanps/jediMEG

License: MIT
State: the link answers, verified on 26 September 2026
Evidence: files inventoried
Commit: 3e0189cc3eb18a4613c875bfdcf872fe644f12dd, 26 January 2025
Languages: MATLAB (102)
Size: 127 files, 102 scripts
Software Heritage: not archived
Found in: “SUPPORTING INFORMATION”
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 26 September 2026: the link answers
  • 26 September 2026: the link answers
104 files

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;
  • 102 scripts, each with its path and the digest of its content;
  • 5 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

Datasets cited

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, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 4 keywords, 1 funder, 43 references.

Cite

This paper

Puthanmadam Subramaniyam, N., Tronarp, F., Särkkä, S., & Parkkonen, L. (2025). Joint estimation of source dynamics and interactions from MEG data. Network Neuroscience, 9(3), 842-868. https://doi.org/10.1162/netn_a_00453

BibTeX

@article{puthanmadamsubramaniyam2025joint,
author = {Puthanmadam Subramaniyam, Narayan and Tronarp, Filip and Särkkä, Simo and Parkkonen, Lauri},
title = {{Joint estimation of source dynamics and interactions from MEG data}},
journal = {Network Neuroscience},
year = {2025},
volume = {9},
number = {3},
pages = {842--868},
publisher = {MIT Press},
issn = {2472-1751},
doi = {10.1162/netn_a_00453},
url = {https://doi.org/10.1162/netn_a_00453},
pmcid = {PMC12283153}
}

RIS

TY - JOUR
AU - Puthanmadam Subramaniyam, Narayan
AU - Tronarp, Filip
AU - Särkkä, Simo
AU - Parkkonen, Lauri
TI - Joint estimation of source dynamics and interactions from MEG data
T2 - Network Neuroscience
J2 - Netw Neurosci
PY - 2025
DA - 2025
VL - 9
IS - 3
SP - 842
EP - 868
SN - 2472-1751
PB - MIT Press
DO - 10.1162/netn_a_00453
UR - https://doi.org/10.1162/netn_a_00453
LA - en
ER -

CSL-JSON

{
"id": "10.1162/netn_a_00453",
"type": "article-journal",
"title": "Joint estimation of source dynamics and interactions from MEG data",
"container-title": "Network Neuroscience",
"author": [
{
"family": "Puthanmadam Subramaniyam",
"given": "Narayan"
},
{
"family": "Tronarp",
"given": "Filip"
},
{
"family": "Särkkä",
"given": "Simo"
},
{
"family": "Parkkonen",
"given": "Lauri"
}
],
"container-title-short": "Netw Neurosci",
"volume": "9",
"issue": "3",
"page": "842-868",
"DOI": "10.1162/netn_a_00453",
"PMCID": "PMC12283153",
"ISSN": "2472-1751",
"publisher": "MIT Press",
"URL": "https://doi.org/10.1162/netn_a_00453",
"language": "en",
"issued": {
"date-parts": [
[
2025
]
]
}
}

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.1002/hbm.70484 [code]
Frequency-Resolved Cortical Functional Connectivity Across the Adult Lifespan.
Journal: Human brain mapping
In common: MEG, 3 references, author Lauri Parkkonen
[2] doi:10.1038/s41597-025-06397-4 [code]
MEG-SCANS - A comprehensive magnetoencephalography speech dataset with Stories, Chirps and Noisy Sentences
Journal: n/a
In common: FieldTrip, Parallel Computing Toolbox, Signal Processing Toolbox, 1 other tool, MEG, 1 reference
[3] doi:10.1038/s41467-026-71604-8 [code]
Respiration as a dynamic modulator of sensory sampling.
Journal: Nature communications
In common: FieldTrip, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, MEG, 2 references
[4] doi:10.1007/s12021-025-09759-w [code]
Limitations of Variational Laplace-Based Dynamic Causal Modelling for Multistable Cortical Circuits.
Journal: Neuroinformatics
In common: Parallel Computing Toolbox, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, 2 references
[5] doi:10.1002/advs.77857 [code]
Brain Network Dynamics of Local and Global Predictive Processing in Aging.
Journal: Advanced science (Weinheim, Baden-Wurttemberg, Germany)
In common: FieldTrip, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, 2 references
[6] doi:10.1111/nyas.70349 [code]
FREQ-NESS Reveals Age-Related Differences in Frequency-Resolved Brain Networks During Auditory Recognition and Resting State.
Journal: Annals of the New York Academy of Sciences
In common: FieldTrip, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, MEG, 1 reference
[7] doi:10.1002/hbm.70624 [code]
Exploring the Sensitivity Limits of Neuronal Current Imaging With MRI and MEG in the Human Brain.
Journal: Human brain mapping
In common: FieldTrip, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, MEG, 1 reference
[8] doi:10.1162/imag.a.1219 [code]
Causal mechanisms of individual differences in hemispheric lateralization of the face perception network: A DCM-PEB approach.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: 4 references
[9] doi:10.1371/journal.pone.0353371 [code]
Inter-brain functional connectivity: Are we measuring the right thing?
Journal: PloS one
In common: MEG, author Lauri Parkkonen
[10] doi:10.1038/s41593-026-02205-3 [code]
Competitive interactions shape mammalian brain network dynamics and computation.
Journal: Nature neuroscience
In common: Parallel Computing Toolbox, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, 1 reference

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.