Joint estimation of source dynamics and interactions from MEG data
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] § 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] § 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] § 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] § 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] § 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
- 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)
- %AUTHOR : NARAYAN SUBRAMANIYAM /AALTO/NBE/
- % INPUTS
- % 1) init : struct containing initial values for parameters and kalman
- % mean/cov . init.A0, init.V_q0, init.q0, init.P0
- % 2) model : struct containing model params
- % model.G : lead-field matrix
- %model.XI : measurement noise covariance matrix
- %model.V_r : jitter matrix for particles
- %model.mesh : mesh details (mesh.p, mesh.e)
- %model.incl_vert : list of vertices included in source space. Its dimension
- %should be the same as the no. of columns in lead field
- %model.anat_parc : anatomical parcels (this will be optional in future.
- %Presently this info is used to initialize the particles in different
- %anatomical areas
- % 3) Y : MEG data (channels X T)
- % 4) opt_params : struct containing parameters the algorithm depends on
- %opt_params.Ns : no of sources / dipoles
- %opt_params.p : MVAR model order
- %opt_params.N : number of particles
- %opt_params.num_iter : no of iterations
- %opt_params.gamma : forgetting factor for SAEM
- %opt_params.dist_thr : distance threshold (just to make sure initial particles
- %draw are not too close to each other. This can be some value like 2 or 3
- %%%%%%%%%%%%%%PULL OUT VALUES FROM STRUCTS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % source space, lead-field matrix
- G = model.G;
- pnts_e = model.pnts_e;
- incl_vert = model.incl_verts; % source points used to calculate lead field
- pnts = pnts_e(incl_vert, :); %xyz of vertices included in source-space
- %initial parameter values
- A_tilde = init.A0; %AR matrix
- V_tilde = init.V0;
- P_tilde = init.P0;
- q_tilde = init.q0;
- if whiten_flag==0
- sigma_m = init.sigma_m0;
- sigma_b = init.sigma_b0;
- %measurement+bio noise cov matrix
- E = sigma_m^2*eye(size(G,1)) + sigma_b^2*(G*G');
- else
- E = eye(size(G,1));
- end
- % optimization parameters
- Niter = opt_params.Niter;
- gamma = opt_params.gamma;
- % set few constants
- Nq = Ns*P;
- Ny = size(Y,1);
- T = size(Y,2);
- Nj=size(Y,3); %no of trials
- Nr=Ns*3;
- CONST = -Ny * 0.5 * log(2*pi);
- % initialize sufficient statistics matrix
- S = zeros(3*Nq+Ny, 3*Nq+Ny);
- % parameter and state histories
- params.A_hist = zeros(Ns, Ns*P, Niter+1);
- params.A_hist(:,:,1) = A_tilde(1:Ns,:);
- params.V_hist(:,:,1) = V_tilde(1:Ns, 1:Ns);
- if whiten_flag==0
- params.sigma_m_hist(1) = sigma_m;
- params.sigma_b_hist(1) = sigma_b;
- end
- state.r_hat_est = zeros(Nr, T);
- state.qs_hat_est = zeros(Ns, T+1, Nj);
- state.qf_hat_est = zeros(Ns, T, Nj);
- state.r_hat_hist = zeros(Nr,Niter+1);
- %log-likelihoods
- LL_complete = zeros(Niter,1);
- %some variables for gpu
- if gpu_flag ==1
- look_up = zeros(Nj, Np);
- for j=1:Nj
- look_up(j,:) = (j-1)*Np+1 : Np*j;
- end
- Y_rep = zeros(Ny, Np, Nj);
- end
- % Random initialization of conditional trajectory
- if mcmv_prior_flag==0
- [ind_prime, r_prime, G_prime] = set_part_traj...
- (pnts, G, dist_thr, Ns, T); %for bbcb_simu
- else
- [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));
- end
- state.r_hat_hist(:,1) = mean(r_prime,2);
- m0=mean(r_prime,2);
- P0 = 16*eye(3*Ns);
- for k=1:1:Niter
- sprintf('iteration no %d', k)
- tic
- %Kalman filter variables. We assume Kalman covariance is same across
- %trials to keep things computationally feasible.
- q_tilde_kf = single(zeros(Nq,T,Np,Nj));
- q_tilde_kp = single(zeros(Nq,T,Np,Nj));
- P_tilde_kf = single(zeros(Nq,Nq,T,Np));
- P_tilde_kp = single(zeros(Nq,Nq,T,Np));
- % PMCMC variables
- r_pf = zeros(Nr,T,Np);
- ind_pf = zeros(Ns, T, Np);
- G_pf=zeros(Ny,Ns,T,Np);
- % weights
- w = single(zeros(Np,T));
- log_weights = single(zeros(Np,T));
- % replace Np-th particle with conditional trajectory
- r_pf(:,:,end) = r_prime(:,1:T);
- G_pf(:,:,:,end) = G_prime(:,:,1:T);
- ind_pf(:,:,end) = ind_prime(:,1:T);
- % initialize Kalman filter
- q_tilde_kp(:,1,:,:) = repmat(q_tilde,[1,1,Np, Nj]);
- P_tilde_kp(:,:,1,:) = repmat(P_tilde,[1,1,1, Np]);
- %initialize weights
- w(:,1) = ones(size(w(:,1)));
- w(:,1) = w(:,1)./sum(w(:,1));
- % stats for backward smoothing
- omega_tr = zeros(Ns, Ns, T-1, Nj);
- lambda_tr = zeros(Ns, T-1, Nj);
- % Ancestor indices
- an_hist = zeros(Np, T);
- % Compute lambda, omega for conditional trajectory
- for j=1:1:Nj
- [omega_tr(:,:,:,j), lambda_tr(:,:,j)] = compute_omega_lambda_fast...
- (A_tilde(1:Ns,1:Ns), V_tilde, G_pf, squeeze(Y(:,:,j)), E, Ns, P, Np, T);
- end
- omega_avg=squeeze(mean(omega_tr,4));
- lambda_avg=squeeze(mean(lambda_tr,3));
- % draw particles for t=1
- [ind_pf(:,1,1:end-1), r_pf(:,1,1:end-1), G_pf(:,:,1,1:end-1)] = ...
- set_all_part_traj_v2(pnts, G, dist_thr, Ns, Np-1,m0,P0);
- % draw particles for t=1
- %[ind_pf(:,1,1:end-1), r_pf(:,1,1:end-1), G_pf(:,:,1,1:end-1)] = ...
- %set_all_part_traj(pnts, G, dist_thr, Ns, Np-1);
- % stochastic E-STEP
- disp('entering time loop')
- for t=1:T
- if t >=2
- [a,~] = find(mnrnd(1,repmat(w(:,t-1)',Np-1,1))');
- [ind_pf(:,t,1:end-1), XI] = LW_model(squeeze(r_pf(:,t-1,a)), 0.95, pnts);
- log_det = 2*sum(log(diag(chol(XI))));
- for i=1:1:Ns
- r_pf(3*(i-1)+1:3*i,t,1:end-1) = pnts(ind_pf(i,t,1:end-1),:)';
- end
- for i=1:1:Np-1
- G_pf(:,:,t,i) = G(:,squeeze(ind_pf(:,t,i)));
- end
- q_tilde_kf_mean = squeeze(mean(q_tilde_kf(1:Ns,t-1,:,:),4));
- P_tilde_kf_mean = squeeze(P_tilde_kf(1:Ns,1:Ns,t-1,:))./Nj;
- if gpu_flag == 1
- parallel.gpu.enableCUDAForwardCompatibility(1)
- [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),...
- w(:,t-1), Np, CONST, log_det);
- else
- [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),...
- Ns, w(:,t-1), Np, CONST, log_det);
- end
- an_hist(:,t) = [a;aN];
- end
- if gpu_flag == 1 % perform kalman predict, update and log-likelihood computation on GPU
- G_tilde = squeeze(G_pf(:,:,t,:));
- for j=1:Nj
- Y_rep(:,:,j) = repmat(squeeze(Y(:,t,j)), [1, 1, Np]);
- end
- Y_reshape = reshape(Y_rep, Ny, Np*Nj);
- %kalman predict(GPU)
- if t >= 2
- % tic
- q_tilde_kf_ = reshape(squeeze(q_tilde_kf (:,t-1,:,:)), Nq, Np*Nj);
- [q_tilde_kp_, P_tilde_kp(:,:,t,:)] = gpu_kalman_predict(q_tilde_kf_, squeeze(P_tilde_kf(:,:,t-1,:)), A_tilde, V_tilde);
- q_tilde_kp (:,t,:,:) = reshape(q_tilde_kp_, Nq, Np, Nj);
- % toc
- end
- % kalman update(GPU)
- %tic
- q_tilde_kp_ = reshape(squeeze(q_tilde_kp(:,t,:,:)), Nq, Np*Nj);
- q_tilde_kp_gpu = gpuArray(q_tilde_kp_);
- P_tilde_kp_gpu = gpuArray(squeeze(P_tilde_kp(:,:,t,:)));
- Y_gpu = gpuArray(Y_reshape);
- G_tilde_ = repmat(G_tilde, [1 1 1 Nj]);
- G_tilde_=reshape(G_tilde_, Ny,Ns,Np*Nj);
- G_tilde_gpu = gpuArray(G_tilde);
- G_tilde_gpu_ = gpuArray(G_tilde_);
- E_gpu = gpuArray(E);
- [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);
- q_tilde_kf(:,t,:,:) = reshape(q_tilde_kf_, Nq, Np, Nj);
- %toc
- for i=1:Np
- tmp_G_tilde = squeeze(G_tilde(:,:,i));
- ypred(:,i) = tmp_G_tilde*mean(q_tilde_kp_(1:Ns, look_up(:,i)),2);
- sigma(:,:,i) = (tmp_G_tilde*squeeze(P_tilde_kp (1:Ns,1:Ns,t,i))*tmp_G_tilde' + E )./Nj;
- log_det_sigma(i) = 2*sum(log(diag(chol(squeeze(sigma(:,:,i))))));
- end
- %tic
- log_weights(:,t) = gpu_logpdf(Y_avg(:,t),ypred,sigma, log_det_sigma,Np,Ny);
- %toc
- else
- for i = 1:Np
- for j=1:1:Nj
- % Prediction
- if t >= 2
- [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 );
- end
- % Update
- tmp_G_tilde = [G_pf(:,:,t,i) repmat(zeros(size(G_pf(:,:,t,i))), 1, P-1)];
- [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);
- end
- % log-likelihood
- ypred(:,i) = tmp_G_tilde*squeeze(mean(q_tilde_kp(:,t,i,:),4));
- sigma(:,:,i) = (tmp_G_tilde*P_tilde_kp(:,:,t,i)*tmp_G_tilde' + E )./Nj;
- log_weights(i,t)=logpdf(Y_avg(:,t), ypred(:,i), sigma(:,:,i));
- end
- end
- % PF weight update
- maxlog = max(log_weights(:,t));
- log_weights(:,t) = log_weights(:,t) - maxlog;
- w(:,t) = exp(log_weights(:,t));
- w(:,t) = w(:,t) / sum(w(:,t));
- end
- % set trajectories based on ancestral history
- ind_an = an_hist(:,T);
- for t = T-1:-1:1
- r_pf(:,t,:) = r_pf(:,t,ind_an);
- q_tilde_kp(:,t,:,:) = q_tilde_kp(:,t,ind_an,:);
- P_tilde_kp(:,:,t,:) = P_tilde_kp(:,:,t,ind_an);
- q_tilde_kf(:,t,:,:) = q_tilde_kf(:,t,ind_an,:);
- P_tilde_kf(:,:,t,:) = P_tilde_kf(:,:,t,ind_an);
- G_pf(:,:,t,:) = G_pf(:,:,t,ind_an);
- ind_an = an_hist(ind_an,t);
- end
- if gpu_flag==1
- q_tilde_ks = zeros(Nq,T+1,Np*Nj); P_tilde_ks = zeros(Nq,Nq,T+1,Np);
- M = zeros(Nq,Nq,T,Np);
- q_tilde_kp = reshape(q_tilde_kp, Nq, T, Np*Nj);
- q_tilde_kf = reshape(q_tilde_kf, Nq, T, Np*Nj);
- P_tilde_ks(:,:,end,:) = squeeze(P_tilde_kp(:,:,end,:)); P_tilde_ks(:,:,end-1,:) = squeeze(P_tilde_kf(:,:,end,:));
- q_tilde_ks(:,end,:) = squeeze(q_tilde_kp(:,end,:)); q_tilde_ks(:,end-1,:) = squeeze(q_tilde_kf(:,end,:));
- P_tilde_ks_t1 = squeeze(P_tilde_ks(:,:,end-1,:));
- q_tilde_ks_t1 = squeeze( q_tilde_ks(:,end-1,:));
- for t = T-1:-1:1
- P_tilde_kf_t = squeeze(P_tilde_kf(:,:,t,:));
- P_tilde_kp_t1 = squeeze(P_tilde_kp(:,:,t+1,:));
- q_tilde_kf_t = squeeze(q_tilde_kf(:,t,:));
- q_tilde_kp_t1 = squeeze(q_tilde_kp(:,t+1,:));
- [J(:,:,t,:), q_tilde_ks(:,t,:), P_tilde_ks(:,:,t,:)] ...
- = gpu_kalman_smoother(P_tilde_kf_t, P_tilde_kp_t1, q_tilde_kf_t,q_tilde_kp_t1, ...
- q_tilde_ks_t1, P_tilde_ks_t1, A_tilde, Np, Nj);
- P_tilde_ks_t1 = squeeze(P_tilde_ks(:,:,t,:));
- q_tilde_ks_t1 = squeeze( q_tilde_ks(:,t,:));
- end
- % Computing of P_{t-1,t|T}
- G_T = [G_pf(:,:,T,:) repmat(zeros(size(G_pf(:,:,T,:))), 1, P-1)];
- G_T=squeeze(G_T);
- I=eye(Nq);
- M(:,:,end,:) = gpu_init_M(I, squeeze(Kf_(:,:,:)), G_T, squeeze(P_tilde_kf(:,:,T-1,:)), A_tilde);
- for t=T-1:-1:2
- P_tilde_kf_t = squeeze(P_tilde_kf(:,:,t,:));
- M_tp1 = squeeze(M(:,:,t+1,:));
- J_tm1 = squeeze(J(:,:,t-1,:));
- J_t = squeeze(J(:,:,t,:));
- M(:,:,t,:) = gpu_one_lag(A_tilde, P_tilde_kf_t, J_tm1, M_tp1, J_t);
- end
- q_tilde_ks = reshape(q_tilde_ks, Nq, T+1, Np, Nj);
- q_tilde_kf = reshape(q_tilde_kf, Nq, T, Np, Nj);
- else
- q_tilde_ks = zeros(Nq,T+1,Np,Nj); P_tilde_ks = zeros(Nq,Nq,T+1,Np);
- M = zeros(Nq,Nq,T,Np);
- for i = 1:Np
- % Inititalizing
- P_tilde_ks(:,:,end,i) = P_tilde_kp(:,:,end,i); P_tilde_ks(:,:,end-1,i) = P_tilde_kf(:,:,end,i);
- for t = T-1:-1:1
- J(:,:,t,i) = P_tilde_kf(:,:,t,i)*A_tilde'/P_tilde_kp(:,:,t+1,i);
- 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)';
- end
- for j=1:Nj
- 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);
- for t = T-1:-1:1
- 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));
- end
- end
- % Computing of M = P_{t-1,t|T}
- tmp_ = [G_pf(:,:,T,i) repmat(zeros(size(G_pf(:,:,T,i))), 1, P-1)];
- M(:,:,end,i) = (eye(Nq)-Kf(:,:,i)*tmp_)*A_tilde*P_tilde_kf(:,:,T-1,i);
- for t = T-1:-1:2
- 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)';
- end
- end
- end
- star = logical(mnrnd(1,w(:,end)));
- r_prime = squeeze(r_pf(:,:,star));
- ind_prime = squeeze(ind_pf(:,:,star));
- G_prime = squeeze(G_pf(:,:,:,star));
- % M-STEP
- %Bt_s = zeros(3*Nq+Ny,3*Nq+Ny, T-1);
- % compute sufficient stats
- S3T = zeros(3*Nq+Ny,3*Nq+Ny);
- % compute sufficient stats
- Y_tmp = repmat(Y,[1 1 1 Np]);
- for t=2:T
- w_ = permute(repmat(w(:,t), [1 3*Nq+Ny 3*Nq+Ny 1]), [2 3 1]);
- w_1= squeeze(w_(:,1,:));
- Bt = compute_Bt(P_tilde_ks(:,:,t,:), P_tilde_ks(:,:,t-1,:), M(:,:,t,:), Nq, Ny, Np);
- Bt_s = sum(w_.*Bt, 3);
- for j=1:1:Nj
- 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);
- end
- end
- S = (1-gamma(k)).*S + gamma(k).*S3T;
- S=double(S);
- Phi = S(1:Nq,1:Nq);
- Psi = S(1:Nq,Nq+(1:Nq));
- Sigma = S(Nq+(1:Nq),Nq+(1:Nq));
- Xi_1 = S(2*Nq+Ny+(1:Nq),2*Nq+Ny+(1:Nq));
- Lambda_1 = S(2*Nq+(1:Ny),2*Nq+Ny+(1:Nq));
- Omega_1 = S(2*Nq+(1:Ny),2*Nq+(1:Ny));
- G_s = mean(squeeze(mean(G_pf, 4)),3);
- stats.Phi = Phi(1:Ns, 1:Ns);
- stats.Psi = Psi(1:Ns, 1:Nq);
- stats.Sigma = Sigma;
- stats.Xi = Xi_1(1:Ns,1:Ns);
- stats.Lambda = Lambda_1(:,1:Ns);
- stats.Omega = Omega_1;
- %compute complete likelihood before optimization
- LLT = compute_complete_ll(Nj*T, stats, V_tilde(1:Ns, 1:Ns), A_tilde(1:Ns,1:Nq), E, G_s(:,1:Ns));
- %estimate V_q
- V_tilde = (Phi - (Psi/Sigma)*Psi')/(Nj*T);
- V_tilde(Ns+1:Ns*P, 1:Ns)=0;
- V_tilde(1:Ns*P, Ns+1:end)=0;
- V_tilde(1:Ns, 1:Ns)=V_tilde(1:Ns, 1:Ns).*eye(Ns);
- % check if V_q is SPD
- V_tilde(1:Ns, 1:Ns) = max(V_tilde(1:Ns, 1:Ns),1e-4);
- if min(eig(V_tilde(1:Ns, 1:Ns)))< 0
- V_tilde(1:Ns, 1:Ns) = V_tilde(1:Ns, 1:Ns) + 0.001*eye(Ns);
- end
- V_tilde(1:Ns, 1:Ns);
- %estimate source amplitudes
- % q_ks_hat = mean(squeeze(mean(q_tilde_ks,4)),3);
- % q_kf_hat = mean(squeeze(mean(q_tilde_kf,4)),3);
- % estimate A
- tmp = Psi/Sigma;
- A_tilde = tmp(:,1:Nq);
- A_tilde(Ns+1:Ns*P, 1:Ns*(P-1)) = eye(Ns*(P-1));
- A_tilde(Ns+1:Ns*P, 1+Ns*(P-1):end) = zeros(Ns*(P-1), Ns);
- %estimate E
- if whiten_flag == 0
- 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';
- sigma_m = grad_descent_sigmam(S_R, G, Nj*T, sigma_b, sigma_m)
- sigma_b = grad_descent_sigmab(S_R, G, Nj*T, sigma_b, sigma_m)
- E = sigma_m^2*eye(size(G,1)) + sigma_b^2*(G*G');
- % check if E is SPD
- [V_,D_] = eig(E);
- [I_,J_] = find(D_<0);
- if (~isempty(I_))
- for ii = 1:length(I_)
- D_(I_(ii),J_(ii)) = 1e-11;
- end
- E = V_*D_*V_';
- end
- end
- %compute complete likelihood after optimization
- LLTopt = compute_complete_ll(Nj*T, stats, V_tilde(1:Ns, 1:Ns), A_tilde(1:Ns,1:Nq), E, G_s(:,1:Ns));
- %store the histories of estimated parameters
- params.A_hist(:,:,k+1) = A_tilde(1:Ns,:);
- params.V_hist(:,:,k+1) = V_tilde(1:Ns, 1:Ns);
- if whiten_flag==0
- params.sigma_b_hist(1,k+1) = sigma_b;
- params.sigma_m_hist(1,k+1) = sigma_m;
- end
- display(['Iteration ',num2str(k),'. Increase in LL: ', num2str(LLTopt - LLT)])
- LL_complete(k,1) = LLTopt;
- % compute posterior means from PMCMC and Kalman filter
- r_pf_hat = zeros(Nr, T);
- for t=1:1:T
- r_pf_hat(:,t) = sum(repmat(w(:,t),...
- 1,3*Ns) .* ...
- squeeze(r_pf(:,t,:))');
- end
- state.r_hat_est = r_pf_hat;
- state.r_hat_hist(:,k) = mean(r_pf_hat,2);
- state.qf_hat_est = squeeze(mean(q_tilde_kf(1:Ns,:,:,:),3));
- state.qs_hat_est = squeeze(mean(q_tilde_ks(1:Ns,:,:,:),3));
- state.r_particles = r_pf;
- %state.qs_hist(:,:) = q_ks_hat(1:Ns,:);
- %state.qs_trials = squeeze(mean(q_tilde_ks(1:Ns,:,:,:),3));
- %state.qf_hist(:,:) = q_kf_hat(1:Ns,:);
- toc
- end
- end
saem.m at commit 3e0189c, under MIT · at the source
Overview
- Department of Neuroscience and Biomedical Engineering, Aalto University, Espoo, Finland
- Department of Electrical Engineering and Automation, Aalto University, Espoo, Finland
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
3e0189cc3eb18a4613c875bfdcf872fe644f12dd, 26 January 2025Availability: 1 check, the latest on 26 September 2026: the link answers
- 26 September 2026: the link answers
104 files
- EcoG_simu/
change_erp.m , MATLAB, 28 lines - EcoG_simu/
extract_ecog_data.m , MATLAB, 103 lines, 1 match - EcoG_simu/
simu_meg_from_ecog.m , MATLAB, 83 lines - MVAR_simu/
add_brain_noise.m , MATLAB, 13 lines - MVAR_simu/
add_meas_noise.m , MATLAB, 27 lines - MVAR_simu/
five_source_model.m , MATLAB, 29 lines - MVAR_simu/
gen_MEG_simu.m , MATLAB, 16 lines - MVAR_simu/
gen_mvar_data.m , MATLAB, 12 lines - MVAR_simu/
mkpinknoise.m , MATLAB, 40 lines - MVAR_simu/
select_source_inds.m , MATLAB, 22 lines - MVAR_simu/
three_source_model.m , MATLAB, 66 lines - MVAR_simu/
two_source_model.m , MATLAB, 41 lines - demo_lcmv.m, MATLAB, 64 lines
- demo_mcmv.m, MATLAB, 48 lines
- demo_saem.m, MATLAB, 110 lines
- demo_saem_meg.m, MATLAB, 78 lines
- external/
mvar_functions/ , MATLAB, 66 linesInstModelfilter.m - external/
mvar_functions/ , MATLAB, 24 linesMVARfilter.m - external/
mvar_functions/ , MATLAB, 44 linescholdiag.m - external/
mvar_functions/ , MATLAB, 28 linesdiag_coeff_rev.m - external/
mvar_functions/ , MATLAB, 86 linesexternal/ arfit/ acf.m - external/
mvar_functions/ , MATLAB, 39 linesexternal/ arfit/ adjph.m - external/
mvar_functions/ , MATLAB, 66 linesexternal/ arfit/ arconf.m - external/
mvar_functions/ , MATLAB, 322 linesexternal/ arfit/ ardem.m - external/
mvar_functions/ , MATLAB, 165 linesexternal/ arfit/ arfit.m - external/
mvar_functions/ , MATLAB, 191 linesexternal/ arfit/ armode.m - external/
mvar_functions/ , MATLAB, 85 linesexternal/ arfit/ arord.m - external/
mvar_functions/ , MATLAB, 80 linesexternal/ arfit/ arqr.m - external/
mvar_functions/ , MATLAB, 109 linesexternal/ arfit/ arres.m - external/
mvar_functions/ , MATLAB, 129 linesexternal/ arfit/ arsim.m - external/
mvar_functions/ , MATLAB, 53 linesexternal/ arfit/ tquant.m - external/
mvar_functions/ , MATLAB, 153 linesexternal/ covm.m - external/
mvar_functions/ , MATLAB, 523 linesexternal/ fastica.m - external/
mvar_functions/ , MATLAB, 907 linesexternal/ fpica.m - external/
mvar_functions/ , MATLAB, 470 linesexternal/ hungarian.m - external/
mvar_functions/ , MATLAB, 11 linesexternal/ iperm.m - external/
mvar_functions/ , MATLAB, 847 linesexternal/ mvar.m - external/
mvar_functions/ , MATLAB, 362 linesexternal/ pcamat.m - external/
mvar_functions/ , MATLAB, 36 linesexternal/ permnozeribrutal.m - external/
mvar_functions/ , MATLAB, 25 linesexternal/ permnozerihungarian.m - external/
mvar_functions/ , MATLAB, 43 linesexternal/ permslowertriagbrutal.m - external/
mvar_functions/ , MATLAB, 19 linesexternal/ remmean.m - external/
mvar_functions/ , MATLAB, 46 linesexternal/ sltprune.m - external/
mvar_functions/ , MATLAB, 54 linesexternal/ slttestperm.m - external/
mvar_functions/ , MATLAB, 86 linesexternal/ whitenv.m - external/
mvar_functions/ , MATLAB, 130 linesfdMVAR.m - external/
mvar_functions/ , MATLAB, 120 linesfdMVAR0.m - external/
mvar_functions/ , MATLAB, 50 linesidMVAR.m - external/
mvar_functions/ , MATLAB, 69 linesidMVAR0ng.m - external/
mvar_functions/ , MATLAB, 61 linesidMVAR0prior.m - external/
mvar_functions/ , MATLAB, 36 linesmos_idMVAR.m - external/
mvar_functions/ , MATLAB, 187 linessimuMVARcoeff.m - external/
mvar_functions/ , MATLAB, 56 linessurrVCFTd.m - external/
mvar_functions/ , MATLAB, 58 linessurrVCFTd0.m - external/
mvar_functions/ , MATLAB, 65 linessurrVCFTf.m - external/
mvar_functions/ , MATLAB, 70 linessurrVCFTf0.m - external/
mvar_functions/ , MATLAB, 52 linessurrVFT.m - external/
mvar_functions/ , MATLAB, 76 linestest_gaussianity.m - external/
mvar_functions/ , MATLAB, 32 linestest_independence.m - external/
mvar_functions/ , MATLAB, 59 linestest_whiteness.m - joint_est/
LW_model.m , MATLAB, 29 lines - joint_est/
_gpu/ , MATLAB, 19 linescompute_Bt_gpu.m - joint_est/
_gpu/ , MATLAB, 30 linescompute_aN_gpu.m - joint_est/
_gpu/ , MATLAB, 13 linesgpu_init_M.m - joint_est/
_gpu/ , MATLAB, 14 linesgpu_kalman_predict.m - joint_est/
_gpu/ , MATLAB, 23 linesgpu_kalman_smoother.m - joint_est/
_gpu/ , MATLAB, 21 linesgpu_kalman_update.m - joint_est/
_gpu/ , MATLAB, 14 linesgpu_logpdf.m - joint_est/
_gpu/ , MATLAB, 12 linesgpu_one_lag.m - joint_est/
_gpu/ , MATLAB, 29 linessuff_stats_gpu.m - joint_est/
calc_obj.m , MATLAB, 6 lines - joint_est/
compute_Bt.m , MATLAB, 10 lines - joint_est/
compute_aN_fast.m , MATLAB, 21 lines - joint_est/
compute_complete_ll.m , MATLAB, 7 lines - joint_est/
compute_omega_lambda_fas , MATLAB, 26 linest.m - joint_est/
grad_descent_sigmab.m , MATLAB, 36 lines - joint_est/
grad_descent_sigmam.m , MATLAB, 36 lines - joint_est/
kalman_predict.m , MATLAB, 4 lines - joint_est/
kalman_update.m , MATLAB, 6 lines - joint_est/
logpdf.m , MATLAB, 11 lines - joint_est/
resampling.m , MATLAB, 73 lines - joint_est/
saem.m , MATLAB, 501 lines, 3 matches - joint_est/
set_all_part_traj.m , MATLAB, 38 lines - joint_est/
set_all_part_traj_v2.m , MATLAB, 15 lines - joint_est/
set_part_traj.m , MATLAB, 33 lines - joint_est/
set_part_traj_mcmv_prior , MATLAB, 11 lines.m - joint_est/
suff_stats_fast.m , MATLAB, 10 lines - misc/
check_loc_error.m , MATLAB, 14 lines - misc/
compute_cov.m , MATLAB, 9 lines - misc/
find_nearest_id.m , MATLAB, 6 lines - misc/
get_significant_pdc.m , MATLAB, 27 lines - misc/
get_significant_pdc_mr.m , MATLAB, 55 lines - misc/
get_true_pdc.m , MATLAB, 5 lines - misc/
map_locs_to_mne.m , MATLAB, 24 lines - misc/
re_arrange_A.m , MATLAB, 13 lines - two_step_est/
source_localizers/ , MATLAB, 29 linesMCMV_beamformer_localize r.m - two_step_est/
source_localizers/ , MATLAB, 42 linesMCMV_beamformer_localize r_reg.m - two_step_est/
source_localizers/ , MATLAB, 14 linescheck_loc_error.m - two_step_est/
source_localizers/ , MATLAB, 12 linescompute_LCMV_reg.m - two_step_est/
source_localizers/ , MATLAB, 4 linescompute_ai.m - two_step_est/
source_localizers/ , MATLAB, 6 linescompute_mai.m - two_step_est/
source_localizers/ , MATLAB, 65 lines, 1 matchmkfilt_lcmv.m - LICENSE, License, 21 lines
- README.md, Text, 1 line
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
- legacy.openfmri.org/
dataset/ , at legacy.openfmri.org; found in the text, “Real MEG Data”ds000117
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://
BibTeX
@article{puthanmadamsubr
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/
url = {https://
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/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1162/
"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":
"volume": "9",
"issue": "3",
"page": "842-868",
"DOI": "10.1162/
"PMCID": "PMC12283153",
"ISSN": "2472-1751",
"publisher": "MIT Press",
"URL": "https://
"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 mappingIn 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 SentencesJournal: n/aIn 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 communicationsIn 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: NeuroinformaticsIn 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 SciencesIn 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 mappingIn 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 oneIn 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 neuroscienceIn 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.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 102 scripts, and 5 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:4c859a79effb43b4…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
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.
