Towards Real-Time Bayesian Inference for Magnetoencephalography Alberto Sorrentino, Adam M. Johansen, John A. D. Aston, Tom Nichols, Wilfrid S. Kendall University of Warwick a.m.johansen@warwick.ac.uk JSM: August 12th, 2015 1 Outline I Background I I I Magnetoencephalography Hidden Markov Models / State Space Models Particle Filters / Sequential Monte Carlo I Models for Filtering of MEG Data I Examples I Computational Considerations I Conclusions 2 Magnetoencephalography I Noninvasive imaging technique which measures magnetic fields induced by neural currents. I Sampling rate ∼ 100Hz. I Ill-posed inverse problem: turn measurements into estimates of brain activity. I Problem addressed: estimation of current brain activity given observations received. 3 Hidden Markov Models x1 x2 x3 x4 x5 x6 y1 y2 y3 y4 y5 y6 I Unobserved Markov chain {Xn } transition f . I Observed process {Yn } conditional density g. I Density: p(x1:n , y1:n ) = f1 (x1 )g(y1 |x1 ) n Y f (xi |xi−1 )g(yi |xi ). i=2 4 Formal Solutions I Filtering and Prediction Recursions: p(xn |y1:n−1 )g(yn |xn ) p(xn |y1:n ) = R p(x0n |y1:n−1 )g(yn |x0n )dx0n Z p(xn+1 |y1:n ) = p(xn |y1:n )f (xn+1 |xn )dxn I Smoothing: p(x1:n |y1:n ) = R p(x1:n−1 |y1:n−1 )f (xn |xn−1 )g(yn |xn ) g(yn |x0n )f (x0n |xn−1 )p(x0n−1 |y1:n−1 )dx0n−1:n 5 Importance Sampling in This Setting I Given p(x1:n |y1:n ) for n = 1, 2, . . . . I Could sample from a sequence q1 (x1 ), . . . , qn (x1:n ) I If qn (x1:n ) = qn (xn |x1:n−1 )qn−1 (x1:n−1 ) we can re-use samples. I Weight: p(x1:n |y1:n ) qn (xn |x1:n−1 )qn−1 (x1:n−1 ) p(x1:n |y1:n ) = wn−1 (x1:n−1 ) qn (xn |x1:n−1 )p(x1:n−1 |y1:n−1 ) f (xn |xn−1 )g(yn |xn ) wn−1 (x1:n−1 ) = qn (xn |xn−1 )p(yn |y1:n−1 ) wn (x1:n ) ∝ 6 SIR Particle Filters [GSS93] Can be viewed as an extension of importance sampling I Algorithmically, at iteration n: I I I i i } for i = 1, . . . , N : , X1:n−1 Given {Wn−1 ei Resample, obtaining {1/N, X 1:n−1 }. I i en−1 Sample Xni ∼ qn (·|X ) I Weight Wni ∝ i ei i f (Xn |Xn−1 )g(yn |Xn ) ei qn (X i |X ) n n−1 Actually: I I Resample efficiently. Only resample when necessary. 7 Iteration 2 8 7 6 5 4 3 2 1 0 −1 −2 1 2 3 4 5 6 7 8 9 10 8 Iteration 3 8 7 6 5 4 3 2 1 0 −1 −2 1 2 3 4 5 6 7 8 9 10 9 Iteration 4 8 7 6 5 4 3 2 1 0 −1 −2 1 2 3 4 5 6 7 8 9 10 10 Iteration 5 8 7 6 5 4 3 2 1 0 −1 −2 1 2 3 4 5 6 7 8 9 10 11 Iteration 6 8 7 6 5 4 3 2 1 0 −1 −2 1 2 3 4 5 6 7 8 9 10 12 Iteration 7 8 7 6 5 4 3 2 1 0 −1 −2 1 2 3 4 5 6 7 8 9 10 13 Iteration 8 8 7 6 5 4 3 2 1 0 −1 −2 1 2 3 4 5 6 7 8 9 10 14 Iteration 9 8 7 6 5 4 3 2 1 0 −1 −2 1 2 3 4 5 6 7 8 9 10 15 Iteration 10 8 7 6 5 4 3 2 1 0 −1 −2 1 2 3 4 5 6 7 8 9 10 16 Resample-Move Particle Filters [GB01] I Originally, incorporate p(xt |y1:t )-invariant MCMC kernels. I Here we consider p(x1:t |y1:t )-invariant kernels. I Actually, go back only to the birth of the oldest surviving dipole. 17 Measurement Model I Work with discretized brain (Ngrid ≈ 10000 elements). I Precompute ( Nsensors × 3Ngrid .) leadfield/gain matrix, G. p(bt |jt ) = N bt ; Nt X G (i) rt ! (i) qt , Σnoise i=1 where jt = (1) (1) rt , qt (N ) (N ) , . . . , rt t , qt t and G(r) is a Nsensors × 3 matrix for each r. 18 A Random Walk with Births and Deaths Mixture of 3 components: p(jt |jt−1 ) =Pbirth (jt−1 )Tbirth (jt |jt−1 ))+ Pdeath (jt−1 )Tdeath (jt |jt−1 ))+ Prw (jt−1 )Trw (jt |jt−1 )) Where: (1:Nt−1 ) Tbirth (jt |jt ) =Trw (jt Tdeath (jt |jt ) = (Nt−1 +1) |jt−1 )Ugrid (rt (Nt−1 +1) )N (qt ; 0, σq I) Nt−1 1 X Nt−1 (i) (i) Trw (jt |jt−1 \ (rt−1 , qt−1 )) i=1 Nt−1 Trw (jt |jt ) = Y (i) (i) (i) (i) N |grid (rt ; rt−1 )N (qt ; qt−1 , ∆) i=1 19 A Static Dipole Model [SJA+ 13] Mixture of 3 components: p(jt |jt−1 ) =Pbirth (jt−1 )Tbirth (jt |jt−1 ))+ Pdeath (jt−1 )Tdeath (jt |jt−1 ))+ Psd (jt−1 )Tsd (jt |jt−1 )) Where: (1:Nt−1 ) Tbirth (jt |jt ) =Tsd (jt Tdeath (jt |jt ) = (Nt−1 +1) |jt−1 )Ugrid (rt (Nt−1 +1) )N (qt ; 0, σq I) Nt−1 1 X Nt−1 (i) (i) Tsd (jt |jt−1 \ (rt−1 , qt−1 )) i=1 Nt−1 Tsd (jt |jt ) = Y i=1 (i) (i) (i) δr(i) (rt )N (qt ; qt−1 , ∆) t−1 20 Simulation Experiment 30 S1 S2 S3 S4 25 Strength 20 15 10 5 0 0 50 100 150 100 150 Time [ms] −11 1 x 10 Amplitudes 0.5 0 −0.5 −1 −1.5 0 50 Time Source locations (top row S1 and S2, bottom row S3 and S4), source time courses and generated noisy field. 21 Static RandomWalk dSPM Music L1L2 22 Application to Real Data I Somatosensory Evoked Fields mapping experiment I Acquired with 306-channel MEG device [204 planar gradiometers; 102 magnetometers] I The left median nerve at wrist was electrically stimulated at the motor threshold (interstimulus interval randomly varying between 7.0 s and 9.0 s). I Signals filtered to 0.1-200 Hz and sampled at 1000 Hz. I Electrooculogram (EOG) used to monitor eye movements. I Trials with EOG or MEG exceeding 150 mV or 3 pT/cm were excluded. I 84 clean trials were averaged. I To reduce external interference, signal space separation method was applied to the average. I A 3D digitizer and four head position indicator coils were employed to determine the position of the subject’s head. 23 Static RandomWalk dSPM Music L1L2 24 Computational Considerations: A Related PET Algorithm [ZJA15] Runtime of algorithms ● Variance of estimates 0.32 ● ● ● ● 0.16 Implementation ● ● ● ● ● 0.08 ● MCMC−CPU1 ● SMC−CPU1 ● SMC−CPU4 ● SMC−GPU ● ● ● 0.04 ● ● ● ● ● ● ● 0.01 0.125 0.25 0.5 ● ● ● 1 ● ● ● ● ● 0.02 ● ● ● ● ● ● ●● ● ●● ● 2 ● ● ● ●● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ●● ●● ●● ● ●● ● ● 4 8 ● 16 32 Wall clock time (sec) 25 Conclusions I Modelling and computational considerations interact. I Static dipole models allow better interpretation. I Online inference under such models is possible with care. I Computational costs are manageable. . . I and parallelisation is easy. 26 References W. R. Gilks and C. Berzuini. Following a moving target – Monte Carlo inference for dynamic Bayesian models. Journal of the Royal Statistical Society B, 63:127–146, 2001. N. J. Gordon, S. J. Salmond, and A. F. M. Smith. Novel approach to nonlinear/non-Gaussian Bayesian state estimation. IEE Proceedings-F, 140(2):107–113, April 1993. A. Sorrentino, A. M. Johansen, J. A. D. Aston, T. E. Nichols, and W. S. Kendall. Filtering of dynamic and static dipoles in magnetoencephalography. Annals of Applied Statistics, 7(2):955–988, 2013. Y. Zhou, A. M. Johansen, and J. A. D. Aston. Towards automatic model comparison: An adaptive sequential Monte Carlo approach. Journal of Computational and Graphical Statistics, 2015. In press. 27