Functional Brain Imaging and Brain–Computer Interfaces
M2 MVA · Semester 2 · Modelling · 5 ECTS
Contents
- Introduction and overview
- 0. Review: vector calculus, linear algebra and the Gaussian linear model
- 1. From neural currents to electromagnetic fields
- 2. The M/EEG forward problem and finite elements
- 3. Preprocessing and denoising M/EEG signals
- 4. The M/EEG inverse problem
- 5. fMRI: the BOLD signal and the general linear model
- 6. Hypothesis testing and multiple comparisons
- 7. Connectivity, networks and covariance learning
- 8. Brain–computer interfaces
- 9. Complements: boundary elements, sparse imaging, random fields, decoding, effective connectivity
- 10. Research directions and open problems
- Exercises
- Projects and assessment
- References
Introduction and overview
| Module | Functional Brain Imaging and Brain–Computer Interfaces |
| Official title | Imagerie fonctionnelle cérébrale et interface cerveau machine |
| Instructors | B. THIRION, M.C. CORSI (master-mva.com, 2026–2027) |
| Period | Semester 2 · period 2 (04/01/2027 – 02/04/2027) |
| Credits and volume | 5 ECTS · 24 h (lectures 24 h) per the Université Paris-Saclay programme table |
| Label | ModellingTrack Santé |
| Language | Not displayed; the course description on master-mva.com is written in French |
| Assessment | Two TDs (travaux dirigés, guided exercise work; “L’évaluation du cours est constituée de 2 TD”, master-mva.com, “Mode de validation”); the resit is a critical commentary of a research paper; no weighting is displayed; the Université Paris-Saclay course detail gives the nature of the assessment as “Evaluation Continue non Intégrale” |
| Prerequisites | Integral calculus, elements of statistics, numerical computation, linear algebra, optimization (master-mva.com, “Prè-requis”) |
Audience: a student with a good M1 in mathematics, computer science or physics who wants to turn the electromagnetic or haemodynamic traces of brain activity into maps, statistics and commands, whether for neuroscience, for the clinic or for a brain–computer interface.
Empirical first: Bennett and colleagues (2010) put a dead Atlantic salmon in an MRI scanner, “showed” it photographs of people in social situations, and thresholded the voxelwise statistics at an uncorrected p < 0.001: a few voxels in the fish’s brain came out “active”. Eklund, Nichols and Knutsson (2016) then ran standard group analyses on resting-state data, where no task effect exists, and parametric cluster inference gave familywise false-positive rates far above the nominal 5 %: both failures come from statistics (ch. 6), not from the scanner.
The course is about two non-invasive windows on the working brain. Magneto- and electroencephalography (M/EEG) record, within milliseconds, the fields created by currents in the cortex. Functional MRI records, within millimetres but over seconds, a haemodynamic signal tied to the energy used by brain areas.
The page follows the official syllabus: the physics of the signals, the forward and inverse problems of M/EEG, the statistical analysis of functional images and networks, and brain–computer interfaces (BCIs). It shares the neural modelling of Mathematical Methods for Neuroscience, the regularised inversion of Inverse Problems and Imaging and the clinical statistics of Biostatistics.
What you will be able to do
- Derive the quasistatic equations of bioelectromagnetism and compute the potential and magnetic field of a current dipole.
- Explain why MEG is blind to radial sources in a spherical head, and prove it.
- Write the M/EEG forward problem as a boundary value problem, solve it with finite elements, and build a lead field by reciprocity.
- Denoise M/EEG recordings by filtering, averaging, whitening, signal-space projection and independent component analysis.
- Localise sources with dipole fitting, MUSIC, beamformers and minimum-norm imaging, and validate them with resolution matrices and simulations.
- Model an fMRI time series with the general linear model, test contrasts, and run a group analysis with mixed effects.
- Control false positives in statistical maps with permutation tests, familywise and false discovery rate procedures, and cluster inference.
- Estimate functional connectivity with partial correlations, shrinkage, the graphical lasso and the geometry of covariance matrices, and recognise the effect of volume conduction on M/EEG coherence.
- Build and evaluate a BCI pipeline (common spatial patterns, linear discriminant analysis, Riemannian classifiers) without leakage, and compute its information transfer rate.
- Discuss the role of feedback and user learning in a closed-loop BCI.
Official objectives and syllabus (2026–2027)
The course description on master-mva.com states that the course deals with functional brain imaging and its application to brain–computer interfaces, based on two non-invasive techniques that measure brain activity. M/EEG measures the electromagnetic field created by cortical electric currents; functional MRI measures a signal (BOLD) linked to the energy consumption of brain areas.
The description announces a course of 8 sessions. It lists the themes below, grouped in four parts, followed by the heading “Les intervenants” (the speakers). The Université Paris-Saclay course detail adds only the nature of the assessment.
| Official topic | Course section |
|---|---|
| Part “Basic notions of physics” | ch. 1 (where the signals come from, quasistatic Maxwell equations, dipoles, Biot–Savart, spherical models, source models) |
| Maxwell’s equations: quasistatic regime | Section 1.2: Definition 1.1, Proposition 1.2 (Poisson equation for the potential), Example 1.3 (orders of magnitude) |
| Biot–Savart law | Section 1.4: Theorem 1.7, Proposition 1.8; spherical models in section 1.5 (Theorem 1.9, Sarvas formula 1.10, Code 1.11); the Geselowitz formula in section 9.1 |
| Source models | Section 1.3 (current dipole, Definition 1.4, Proposition 1.5) and section 1.6 (equivalent dipoles, distributed and orientation-constrained models, Definition 1.12) |
| Part “Forward and inverse problem in M/EEG” | ch. 2 (forward), ch. 3 (denoising), ch. 4 (inverse and validation) |
| Forward problem: finite-element resolution | ch. 2: boundary value problem, weak formulation, P1 finite elements, Céa’s lemma, direct and subtraction source models, lead field and reciprocity, Code 2.9; boundary elements in section 9.1 |
| Denoising of M/EEG signals | ch. 3: filtering and averaging, noise covariance and whitening, signal-space projection, independent component analysis, Code 3.9; Maxwell filtering for MEG in section 9.1 |
| Inverse problem (MUSIC, beamforming, imaging) | ch. 4: dipole fitting (4.2), MUSIC (4.3, Theorem 4.3), LCMV beamforming (4.4, Theorem 4.4), minimum-norm imaging, dSPM and sLORETA (4.5, Theorems 4.6 and 4.8); sparse imaging in section 9.2 |
| Validation | Section 4.6: resolution matrix, point-spread and cross-talk functions, localisation error, simulations (Code 4.10), experimental validation |
| Part “Statistical analysis of functional data” | ch. 5, ch. 6, ch. 7 |
| Linear model, mixed-effects models | ch. 5: haemodynamic response and design matrix (5.2), estimation, contrasts and prewhitening (5.3), two-level mixed-effects models (5.4, Code 5.6) |
| Hypothesis testing, nonparametric tests, multiple comparisons | ch. 6: permutation tests (Theorem 6.2), familywise error and the maximum statistic (Proposition 6.3), false discovery rate (Theorem 6.4), cluster inference, Code 6.6; random field theory in section 9.3 |
| Inference of connectivity models, network learning and covariance learning | ch. 7: Gaussian graphical models, shrinkage, graphical lasso (Code 7.6), the manifold of covariance matrices (7.5); M/EEG coherence and volume conduction in section 9.5; effective connectivity (Granger causality, dynamic causal models) in section 9.6 |
| Part “Towards brain–computer interfaces” | ch. 8 |
| Communicating via brain activity | Section 8.1: definition, paradigms (motor imagery, P300, SSVEP), information transfer rate (Proposition 8.2, Example 8.3) |
| Extraction and classification of relevant features, model selection | Sections 8.2–8.4: common spatial patterns (Theorem 8.4), Riemannian features, LDA and shrinkage (Proposition 8.5), minimum distance to the mean; model selection by nested cross-validation (section 8.4), leakage and chance level (Proposition 8.6, Code 8.7) |
| Role of feedback | Section 8.5: closed loop, user learning, co-adaptation, adaptive classifiers (Proposition 8.8) |
| “Les intervenants” (heading that closes the list) | Fiche above: Bertrand Thirion and Marie-Constance Corsi, both listed with INRIA on master-mva.com |
| Objective: two non-invasive techniques, M/EEG (fields of cortical currents) and fMRI (BOLD signal) | M/EEG in ch. 1–ch. 4; the BOLD signal in section 5.1; connectivity of both in ch. 7 and section 9.5; EEG-based interfaces in ch. 8 |
| Objective: the “Présentation” link of the course page | Not covered: the linked presentation is not part of the official text these notes rely on |
| Organisation: a course of 8 sessions | The 8 sessions of the session plan |
| Assessment: two TDs; resit by a critical commentary of a paper | Projects and assessment: subjects sized as TDs, paper studies that train the critical commentary |
| Université Paris-Saclay course detail: “Evaluation Continue non Intégrale” | Fiche above (Assessment row) |
| Prerequisites: integral calculus, statistics, numerical computation, linear algebra, optimization | ch. 0 (vector calculus, SVD and Tikhonov regularisation, Gaussian linear model) |
| References: course handout, Poldrack–Mumford–Nichols, Brette–Destexhe | References, first three entries |
Extensions beyond the syllabus: the review ch. 0; the subtraction source model and discrete reciprocity (ch. 2); the proof that sLORETA has no localisation bias for one source (Theorem 4.8); the Riemannian geometry of covariance matrices (7.5); the complements of ch. 9 and the research directions of ch. 10.
Where this course fits in the programme
Official prerequisites: integral calculus, elements of statistics, numerical computation, linear algebra and optimization. The course is a second-semester Modelling course of 5 ECTS of the Santé track, taught by Bertrand Thirion and Marie-Constance Corsi (INRIA, as listed on master-mva.com).
- Refreshers — Linear Algebra, Analysis and Optimization for the SVD, Tikhonov regularisation and the Lagrange multipliers of ch. 0 and ch. 4; Probability and Statistics for the Gaussian linear model and the tests of ch. 5–ch. 6; Scientific Python, NumPy and PyTorch for the code.
- First-semester courses that prepare it — Mathematical Methods for Neuroscience (where the currents come from); Convex Optimization and Applications in Machine Learning (graphical lasso, proximal methods of section 9.2); Introduction to Statistical Learning (LDA, cross-validation); Computational Statistics (resampling); Machine Learning for Time Series (filtering, spectra); Medical Image Analysis Based on Generative, Geometric and Biophysical Models (MRI, registration, the Santé track).
- Related second-semester courses — Inverse Problems and Imaging (Bayesian regularisation); Large Random Matrices and Applications to Machine Learning (covariance estimation in high dimension); Biostatistics (mixed models, clinical validation); Deep Learning for Medical Imaging; Graphs in Machine Learning (brain networks as graphs); Kernel Methods for Machine Learning; Audio Signal Processing: Time–Frequency Analysis (spectral estimation).
- Alongside and after the course — the Hospital Immersion: Paired Project with a Physician, where clinical EEG and MRI are met in practice, and the Research Internship.
Course outline
- Review: vector calculus, linear algebra and the Gaussian linear model — divergence theorem and Green’s identity, the fundamental solution of the Laplacian, SVD and Tikhonov regularisation, Rayleigh quotients, the distribution of least squares.
- From neural currents to electromagnetic fields — the origin of M/EEG signals, the quasistatic Maxwell equations, the current dipole, Biot–Savart, spherical models and the silence of radial dipoles, source models.
- The M/EEG forward problem and finite elements — the boundary value problem, its weak form, P1 finite elements, singular sources, the lead field and Helmholtz reciprocity.
- Preprocessing and denoising M/EEG signals — filtering and averaging, noise covariance and whitening, signal-space projection, independent component analysis.
- The M/EEG inverse problem — ill-posedness, dipole fitting, MUSIC, beamformers, minimum-norm imaging, dSPM and sLORETA, validation.
- fMRI: the BOLD signal and the general linear model — the haemodynamic response, design matrices, contrasts, prewhitening, mixed-effects group models.
- Hypothesis testing and multiple comparisons — permutation tests, familywise error rate, false discovery rate, cluster-level inference.
- Connectivity, networks and covariance learning — partial correlations, shrinkage, the graphical lasso, the manifold of covariance matrices.
- Brain–computer interfaces — paradigms, information transfer rate, common spatial patterns, linear and Riemannian classifiers, evaluation, feedback.
- Complements — boundary elements and the Geselowitz formula, Maxwell filtering, sparse source imaging, random field theory, decoding and the interpretation of weights, M/EEG coherence and volume conduction, effective connectivity (self-study).
- Research directions and open problems — reproducibility, large cohorts, deep decoding of non-invasive signals, transfer across sessions and subjects, user training (self-study).
Session plan
24 h in class = 8 sessions of 3 h.
The volume is the Université Paris-Saclay programme table (lectures 24 h), and master-mva.com announces a course of 8 sessions, which gives 3 h per session. The split of the content into sessions is a proposal: it follows the four parts of the official syllabus in their order.
Level 1 = foundations, 2 = core models and algorithms, 3 = advanced or research-level material; the level never decreases.
| Session | Hours | Level | Content | Practice |
|---|---|---|---|---|
| 1 | 3 h | 1 | ch. 0 Review: vector calculus, SVD and Tikhonov, Gaussian linear model; ch. 1.1–1.2 Origin of the signals, quasistatic Maxwell equations | Example 1.3 by hand |
| 2 | 3 h | 1 | ch. 1.3–1.6 Current dipole, Biot–Savart, spherical models and the Sarvas formula, source models | Ex. 1, 8; lab: Code 1.11 |
| 3 | 3 h | 2 | ch. 2 Forward problem: boundary value problem, weak form, P1 finite elements, lead field and reciprocity; ch. 3.1–3.2 Signal model, filtering and averaging | Ex. 2, 9; lab: Code 2.9 |
| 4 | 3 h | 2 | ch. 3.3–3.5 Whitening, signal-space projection, ICA; ch. 4.1–4.3 Ill-posedness, dipole fitting, MUSIC | Lab: Code 3.9 |
| 5 | 3 h | 2 | ch. 4.4–4.6 Beamforming, minimum-norm imaging, dSPM and sLORETA, validation | Ex. 3, 10, 16; lab: Code 4.10 |
| 6 | 3 h | 2 | ch. 5 fMRI: BOLD, design matrix, contrasts, prewhitening, mixed effects; ch. 6.1–6.3 Mass-univariate tests, permutation, familywise error | Ex. 4, 11, 12; lab: Code 5.6 |
| 7 | 3 h | 3 | ch. 6.4–6.5 False discovery rate, cluster inference; ch. 7.1–7.4 Connectivity, partial correlation, shrinkage, graphical lasso | Ex. 5, 6, 13; labs: Codes 6.6 and 7.6 |
| 8 | 3 h | 3 | ch. 7.5 Covariance manifold and tangent space; ch. 8 Brain–computer interfaces: paradigms, ITR, CSP, classifiers, evaluation, feedback | Ex. 7, 14, 15, 17; lab: Code 8.7 |
Self-study, outside the 24 h (about 8 h in total): ch. 9 Complements: boundary elements and Maxwell filtering, sparse imaging (Code 9.4), random field theory, decoding, M/EEG coherence, effective connectivity (≈ 5 h, with Ex. 18) · ch. 10 Research directions and open problems (≈ 2 h) · the written-exam proposal of Projects and assessment as a self-test (≈ 1 h).
How to study this module
- Read ch. 0 first, even quickly: Green’s identity, the push-through identity and the distribution of least squares are used without warning in ch. 2, ch. 4 and ch. 5.
- Keep the orders of magnitude of Example 1.3 and Example 1.6 in mind: they explain most modelling choices of the M/EEG chapters.
- Run every code block: they use NumPy, SciPy and scikit-learn only, with fixed seeds and synthetic data, and each runs in a few seconds. Then change one parameter (the noise level, the depth of a source, the number of trials) and predict the output before running again.
- After each session, solve the exercises of the Practice column; the ★★★ exercises are good starting points for a TD or a project.
- For real data, the open-source libraries MNE-Python (M/EEG), Nilearn (fMRI) and pyRiemann (BCI) implement the methods of this page; the projects use them on public data sets.
- Read ch. 9 section by section as the matching chapter is taught: 9.1 after session 3, 9.2 after session 5, 9.3 after session 7, 9.4–9.6 after session 8.
0. Review: vector calculus, linear algebra and the Gaussian linear model
Three M1 toolboxes are used: vector calculus for the physics of ch. 1–ch. 2, regularised least squares for ch. 4, and the Gaussian linear model for ch. 5–ch. 6. This chapter states them with short proofs.
0.1 Vector calculus
Definition 0.1 — Differential operators For a scalar field f and a vector field F on \mathbb{R}^3: \nabla f = (\partial_1 f, \partial_2 f, \partial_3 f), \qquad \nabla \cdot F = \sum_i \partial_i F_i, \qquad \nabla \times F = \big(\partial_2 F_3 - \partial_3 F_2,\ \partial_3 F_1 - \partial_1 F_3,\ \partial_1 F_2 - \partial_2 F_1\big), and \Delta f = \nabla \cdot \nabla f. Two identities hold for smooth fields: \nabla \times (\nabla f) = 0, \qquad \nabla \cdot (\nabla \times F) = 0 . Conversely, on a simply connected domain a curl-free field is a gradient.
Theorem 0.2 — Divergence theorem and Green’s first identity Let \Omega be a bounded domain with smooth boundary \partial\Omega and outward normal n.
For smooth fields F, u, w and a positive function \sigma: \int_\Omega \nabla \cdot F \, dr = \oint_{\partial\Omega} F \cdot n \, dS, \qquad \int_\Omega w\, \nabla \cdot (\sigma \nabla u)\, dr = \oint_{\partial\Omega} w\, \sigma\, \partial_n u \, dS - \int_\Omega \sigma\, \nabla u \cdot \nabla w \, dr .
Proof. The first formula is the Gauss–Ostrogradski theorem. The second applies it to F = w\,\sigma \nabla u, whose divergence is \nabla \cdot (w\,\sigma \nabla u) = w\, \nabla\cdot(\sigma\nabla u) + \sigma \nabla u \cdot \nabla w . ∎
Proposition 0.3 — Fundamental solution of the Laplacian In \mathbb{R}^3, in the sense of distributions, \Delta \Big( -\frac{1}{4\pi |r|} \Big) = \delta_0, \qquad \nabla_r \frac{1}{|r - r'|} = -\frac{r - r'}{|r - r'|^3} = -\nabla_{r'} \frac{1}{|r - r'|} . In \mathbb{R}^2 the fundamental solution is \frac{1}{2\pi}\ln|r|. The solution of \Delta u = f that vanishes at infinity is the convolution of f with the fundamental solution.
0.2 Singular values and regularised least squares
Definition 0.4 — SVD and pseudo-inverse Every A \in \mathbb{R}^{m \times p} factors as A = U \Sigma V^\top with U, V orthogonal and \Sigma diagonal with entries s_1 \ge s_2 \ge \dots \ge 0.
The pseudo-inverse is A^+ = V \Sigma^+ U^\top, where \Sigma^+ inverts the non-zero singular values. The vector A^+ y is the least-squares solution of minimum norm.
Proposition 0.5 — Tikhonov regularisation and the push-through identity For \lambda > 0, the problem \min_x \|y - Ax\|^2 + \lambda \|x\|^2 has the unique solution \hat x_\lambda = (A^\top A + \lambda I_p)^{-1} A^\top y = A^\top (A A^\top + \lambda I_m)^{-1} y = \sum_i \frac{s_i}{s_i^2 + \lambda}\, (u_i^\top y)\, v_i .
Proof. The objective is strictly convex; its gradient 2A^\top(Ax - y) + 2\lambda x vanishes at the first expression.
The identity A^\top (AA^\top + \lambda I) = (A^\top A + \lambda I) A^\top gives the second one after multiplication by both inverses.
The third follows by inserting the SVD: each component u_i^\top y is divided by s_i and damped by the filter factor s_i^2/(s_i^2+\lambda). ∎
The second form costs one m \times m inversion. With m \approx 300 sensors and p \approx 10^4 sources, this is what makes minimum-norm imaging cheap (ch. 4).
Proposition 0.6 — Generalised Rayleigh quotient Let C_1 be symmetric and C_2 symmetric positive definite. The quotient R(w) = \frac{w^\top C_1 w}{w^\top C_2 w} is maximised (minimised) by the eigenvector of the generalised problem C_1 w = \mu C_2 w with the largest (smallest) eigenvalue \mu, and the extreme values of R are these eigenvalues.
Proof. Set v = C_2^{1/2} w. Then R = v^\top M v / v^\top v with M = C_2^{-1/2} C_1 C_2^{-1/2} symmetric. The ordinary Rayleigh principle gives the extreme eigenvectors of M, and M v = \mu v is equivalent to C_1 w = \mu C_2 w. ∎
0.3 The Gaussian linear model
Theorem 0.7 — Distribution of least squares Let y = X\beta + \varepsilon with X \in \mathbb{R}^{n \times p} of rank p and \varepsilon \sim \mathcal{N}(0, \sigma^2 I_n). Then \hat\beta = (X^\top X)^{-1} X^\top y and the residual variance \hat\sigma^2 = \|y - X\hat\beta\|^2/(n-p) satisfy \hat\beta \sim \mathcal{N}\big(\beta, \sigma^2 (X^\top X)^{-1}\big), \qquad \frac{(n-p)\,\hat\sigma^2}{\sigma^2} \sim \chi^2_{n-p}, \qquad \hat\beta \perp \hat\sigma^2 .
Proof. \hat\beta is a linear function of a Gaussian vector, with the stated mean and covariance. The residual is (I - H)\varepsilon, where H = X(X^\top X)^{-1}X^\top is the orthogonal projector onto the columns of X.
Since I - H is a projector of rank n - p, \|(I-H)\varepsilon\|^2/\sigma^2 is \chi^2_{n-p} (Cochran).
Finally \hat\beta depends on H\varepsilon and the residual on (I-H)\varepsilon: these Gaussian vectors are uncorrelated, hence independent. ∎
Key takeaways — chapter 0
- Green’s identity turns a boundary value problem into an energy identity; it gives uniqueness in ch. 2 and reciprocity in section 2.4.
- Tikhonov regularisation damps small singular values; its “sensor-space” form needs one m \times m inversion.
- Generalised eigenvectors maximise ratios of variances; they reappear in CSP (ch. 8).
- In the Gaussian linear model, \hat\beta is Gaussian and independent of \hat\sigma^2, which yields the t and F tests of ch. 5.
1. From neural currents to electromagnetic fields
This chapter follows the signal from the synapse to the sensor and reduces Maxwell’s equations to the two formulas used by M/EEG software: a Poisson equation for the potential and the Biot–Savart law for the field.
1.1 Where the signals come from
When a neurotransmitter opens ion channels on the dendrite of a cortical pyramidal neuron, a current enters the cell, flows along the dendrite, and returns through the extracellular medium. The intracellular part of this loop is the primary current; the extracellular return is the volume current.
Pyramidal cells are aligned perpendicular to the cortical surface, so their primary currents add up when synchronous; a measurable signal needs tens of thousands of cells active together. Brief action potentials contribute little at a distance.
| EEG | MEG | fMRI | |
|---|---|---|---|
| Measures | potential differences on the scalp | magnetic field outside the head | BOLD signal (blood oxygenation) |
| Typical amplitude | 10–100 µV | 10–1000 fT | 1–5 % signal change |
| Temporal resolution | about 1 ms | about 1 ms | seconds (sampling every 1–2 s) |
| Spatial resolution | centimetres, after source modelling | centimetres to millimetres, after source modelling | 2–3 mm voxels |
| Sensors | 32–256 electrodes | about 300 sensors in a shielded room | MRI scanner |
The magnetic field of the brain is about 10^8 times smaller than the Earth’s field of 50 µT; MEG needs superconducting or optically pumped magnetometers in a magnetically shielded room.
1.2 Maxwell’s equations in the quasistatic regime
Definition 1.1 — Maxwell’s equations in a conductor In a medium of conductivity \sigma, permittivity \varepsilon and permeability \mu_0, the fields E, B and the current density J satisfy \nabla \cdot E = \frac{\rho}{\varepsilon}, \qquad \nabla \times E = -\partial_t B, \qquad \nabla \cdot B = 0, \qquad \nabla \times B = \mu_0 \big( J + \varepsilon\, \partial_t E \big). The total current is the sum of the primary current and the ohmic volume current: J = J^p + \sigma E .
Brain signals lie below about 1 kHz. Two dimensionless numbers then justify dropping the time derivatives: the ratio of displacement to ohmic currents, \omega\varepsilon/\sigma, and the ratio of the head size to the skin depth \delta = \sqrt{2/(\omega \mu_0 \sigma)}.
Proposition 1.2 — Quasistatic equations If \partial_t B and \varepsilon\,\partial_t E are neglected, the electric field derives from a potential, E = -\nabla V, and V solves the Poisson equation
Key result — the M/EEG forward equation \nabla \cdot (\sigma \nabla V) = \nabla \cdot J^p
Proof. Without \partial_t B, \nabla \times E = 0, so E = -\nabla V (Definition 0.1).
Without \varepsilon\,\partial_t E, \nabla \times B = \mu_0 J; taking the divergence gives \nabla \cdot J = 0.
Substituting J = J^p - \sigma \nabla V yields the equation. ∎
The time dependence is now a parameter: at every instant the potential is the static response to the primary currents of that instant. This is why M/EEG models are linear and instantaneous.
Example 1.3 — Orders of magnitude Take \sigma = 0.33 S/m (brain and scalp) and a frequency of 100 Hz, so \omega = 628 rad/s.
- Even with a large relative permittivity of 10^5, the ratio of displacement to ohmic currents is \frac{\omega \varepsilon}{\sigma} = \frac{628 \times 10^5 \times 8.85 \times 10^{-12}}{0.33} \approx 1.7 \times 10^{-3} .
- The skin depth is \delta = \sqrt{\frac{2}{\omega \mu_0 \sigma}} \approx 88 \text{ m}, about a thousand times the size of a head, so induction is negligible.
- At 1 kHz the two numbers become 1.7 \times 10^{-2} and 28 m: the approximation still holds.
1.3 The current dipole and the potential in a homogeneous medium
Definition 1.4 — Current dipole A primary current concentrated at r_0 with moment q \in \mathbb{R}^3 (unit A·m) is the current dipole J^p(r) = q\, \delta(r - r_0) . A synchronously active patch of cortex, from a few square millimetres to a few square centimetres, is well summarised by a dipole of 1–100 nA·m, oriented along the normal to the cortex.
Proposition 1.5 — Potential of a dipole in an infinite homogeneous conductor If \sigma is constant on \mathbb{R}^3, the solution of Proposition 1.2 that vanishes at infinity is V_\infty(r) = \frac{1}{4\pi\sigma}\, \frac{q \cdot (r - r_0)}{|r - r_0|^3} .
Proof. The equation reads \Delta V = \nabla \cdot J^p / \sigma. By Proposition 0.3, V(r) = -\frac{1}{4\pi\sigma} \int \frac{\nabla' \cdot J^p(r')}{|r - r'|}\, dr' = \frac{1}{4\pi\sigma} \int J^p(r') \cdot \nabla' \frac{1}{|r - r'|}\, dr', after an integration by parts. With \nabla' |r - r'|^{-1} = (r - r')/|r - r'|^3 and J^p = q\,\delta_{r_0}, the integral evaluates at r' = r_0. ∎
The potential decreases as the inverse square of the distance, with a positive lobe in the direction of q and a negative lobe behind it.
Example 1.6 — An evoked source seen from 4 cm A dipole of q = 10 nA·m in \sigma = 0.33 S/m, observed at 4 cm along its axis, produces V_\infty = \frac{10^{-8}}{4\pi \times 0.33 \times 0.04^2} \approx 1.5 \ \mu\text{V}. The poorly conducting skull, between about 15 and 80 times less conductive than the brain depending on the study, smears this potential over the scalp. This is why the head must be modelled (ch. 2).
1.4 The magnetic field: Biot–Savart
Theorem 1.7 — Biot–Savart law Under the quasistatic approximation, \nabla \times B = \mu_0 J and \nabla \cdot B = 0 give, for currents of bounded support, B(r) = \frac{\mu_0}{4\pi} \int J(r') \times \frac{r - r'}{|r - r'|^3}\, dr' .
Proof. Since \nabla\cdot B = 0, write B = \nabla \times A with the gauge \nabla \cdot A = 0. Then \nabla \times \nabla \times A = \nabla(\nabla\cdot A) - \Delta A = -\Delta A = \mu_0 J . Proposition 0.3 gives A(r) = \frac{\mu_0}{4\pi}\int J(r')/|r - r'|\, dr'. Taking the curl under the integral, with \nabla_r |r - r'|^{-1} = -(r - r')/|r - r'|^3, gives the formula. ∎
Both primary and volume currents contribute. Splitting J = J^p - \sigma \nabla V gives B = B_0 + B_v, where B_0 is the field of the primary current alone.
Proposition 1.8 — Field of the primary dipole For J^p = q\,\delta_{r_0}, B_0(r) = \frac{\mu_0}{4\pi}\, \frac{q \times (r - r_0)}{|r - r_0|^3} . For q = 10 nA·m at 4 cm, perpendicular to q, this gives 10^{-7} \times 10^{-8}/0.04^2 \approx 625 fT, the order of magnitude of evoked MEG responses.
1.5 Spherical head models
In general the volume currents depend on the whole conductivity profile. A sphere is the exception that makes MEG modelling simple.
Theorem 1.9 — MEG in a spherically symmetric conductor Let the conductivity depend only on |r| inside a ball and vanish outside. For every r outside the ball:
- the volume currents do not contribute to the radial component, r \cdot B(r) = r \cdot B_0(r);
- the field B outside depends only on q and r_0, not on the conductivity profile;
- a radial dipole (q parallel to r_0) produces no magnetic field outside the ball.
Proof. Step 1. The volume currents contribute B_v(r) = -\frac{\mu_0}{4\pi}\int \sigma(r')\,\nabla' V \times \frac{r - r'}{|r - r'|^3}\, dr' . Using (a \times b)\cdot c = a \cdot (b \times c), \Big(\nabla' V \times (r - r')\Big) \cdot r = \nabla' V \cdot \big((r - r') \times r\big) = \nabla' V \cdot (r \times r') . Integrate by parts, moving the gradient onto f(r') = \sigma(|r'|)\, \frac{r \times r'}{|r - r'|^3} . Three terms appear, and all vanish:
- the divergence of r \times r' in r' is zero;
- the gradient of \sigma(|r'|), including the jump at the surface, is parallel to r', which is orthogonal to r \times r';
- the gradient of |r - r'|^{-3} is parallel to r - r', also orthogonal to r \times r'.
Step 2. Outside the conductor J = 0, so \nabla \times B = 0 and B = -\mu_0 \nabla U, with U \to 0 at infinity. Integrating along the ray from r to infinity, U(r) = \frac{1}{\mu_0} \int_0^\infty \hat r \cdot B(r + t \hat r)\, dt , which, by step 1, only involves B_0, hence only q and r_0.
Step 3. Expand the radial part of the primary field: r \cdot \big(q \times (r - r_0)\big) = r \cdot (q \times r) - r \cdot (q \times r_0) = -\, r \cdot (q \times r_0) . If q is parallel to r_0, then q \times r_0 = 0, so r \cdot B_0 = 0 everywhere outside. By step 2, U = 0 and B = 0. ∎
MEG is thus blind to radial sources, located at the crests of the gyri, and most sensitive to tangential sources in the walls of the sulci. EEG sees both, which is one reason to combine the two modalities.
Proposition 1.10 — Sarvas formula (Sarvas, 1987) With the sphere centred at 0, a = r - r_0, a = |a| and r = |r|, the field outside is B(r) = \frac{\mu_0}{4\pi F^2}\Big( F\, q \times r_0 - \big((q \times r_0)\cdot r\big)\, \nabla F \Big), \qquad F = a\,(r a + r^2 - r_0 \cdot r), \nabla F = \Big(\frac{a^2}{r} + \frac{a \cdot r}{a} + 2a + 2r\Big)\, r - \Big(a + 2r + \frac{a \cdot r}{a}\Big)\, r_0 . It is obtained by computing the integral of step 2 in closed form. It depends on q only through q \times r_0: the radial part of q drops out.
Code 1.11 — Sarvas field, primary field and the silent radial dipole
import numpy as np
mu0 = 4e-7 * np.pi
def b_primary(r, r0, q):
"""Biot-Savart field of the primary current dipole alone (T)."""
a = r - r0
return mu0 / (4 * np.pi) * np.cross(q, a) / np.linalg.norm(a) ** 3
def b_sarvas(r, r0, q):
"""Field outside a spherically symmetric conductor centred at 0 (Sarvas, 1987)."""
a_vec = r - r0
a, rn = np.linalg.norm(a_vec), np.linalg.norm(r)
F = a * (rn * a + rn**2 - r0 @ r)
gradF = ((a**2 / rn + a_vec @ r / a + 2 * a + 2 * rn) * r
- (a + 2 * rn + a_vec @ r / a) * r0)
qxr0 = np.cross(q, r0)
return mu0 / (4 * np.pi * F**2) * (F * qxr0 - (qxr0 @ r) * gradF)
r0 = np.array([0.0, 0.0, 0.07]) # source 7 cm from the centre
r = np.array([0.03, 0.01, 0.105]) # sensor about 4 cm away
rhat = r / np.linalg.norm(r)
q_tan = np.array([10e-9, 0.0, 0.0]) # 10 nAm tangential dipole
q_rad = np.array([0.0, 0.0, 10e-9]) # 10 nAm radial dipole
for name, q in [("tangential", q_tan), ("radial", q_rad)]:
B, B0 = b_sarvas(r, r0, q), b_primary(r, r0, q)
print(f"{name:10s} |B| = {np.linalg.norm(B)*1e15:7.1f} fT, |B0| = "
f"{np.linalg.norm(B0)*1e15:7.1f} fT, radial parts: "
f"{B @ rhat*1e15:7.2f} vs {B0 @ rhat*1e15:7.2f} fT")Output: the tangential dipole gives |B| = 156.9 fT against |B_0| = 346.8 fT, with equal radial parts of 60.82 fT (Theorem 1.9). The radial dipole gives |B| = 0: volume currents cancel its 301 fT primary field.
1.6 Source models
Definition 1.12 — Source models and lead field By linearity of Proposition 1.2 in J^p, the measurements are linear in the dipole moments. Three source models are used:
- Equivalent current dipoles: a few dipoles with unknown positions r_k and moments q_k; the model is nonlinear in r_k.
- Distributed models: p dipoles at fixed positions on a grid or on the cortical surface, with unknown moments; the model is linear.
- Orientation constraints: a free orientation uses three unknowns per position; a fixed orientation, normal to the cortical surface extracted from an anatomical MRI, uses one.
For m sensors and a distributed model, the lead field (gain matrix) G \in \mathbb{R}^{m \times p} maps source amplitudes to measurements: M = G J + N.
Column j of G is the topography that a unit source at position j would produce on the sensors. Computing it is the forward problem of ch. 2; inverting it is the inverse problem of ch. 4.
Key takeaways — chapter 1
- M/EEG signals come from synchronous postsynaptic currents of pyramidal neurons; a 10 nA·m dipole gives about a microvolt and a few hundred femtotesla.
- Below 1 kHz the quasistatic approximation holds: \nabla\cdot(\sigma\nabla V) = \nabla\cdot J^p, and B follows from Biot–Savart.
- The measurements are linear in the source moments; positions enter nonlinearly.
- In a spherical conductor, the external magnetic field depends only on q \times r_0: MEG is blind to radial dipoles, whatever the conductivity profile.
2. The M/EEG forward problem and finite elements
Given a source, what do the sensors of a realistic head record? This forward problem is a boundary value problem; this chapter solves it with finite elements and uses reciprocity to get a whole lead field from one solve per electrode.
2.1 The boundary value problem
Definition 2.1 — The EEG forward problem Let \Omega be the head, a bounded domain with outward normal n, and \sigma its conductivity, piecewise constant or tensor-valued. Given a primary current J^p supported inside \Omega, find V such that \nabla \cdot (\sigma \nabla V) = \nabla \cdot J^p \ \text{ in } \Omega, \qquad \sigma\, \partial_n V = 0 \ \text{ on } \partial\Omega . The boundary condition says that no current flows into the air. Across internal interfaces, V and the normal current \sigma\,\partial_n V are continuous.
Typical values are about 0.33 S/m for the scalp and the grey matter, 1.79 S/m for the cerebrospinal fluid, and between 0.004 and 0.02 S/m for the skull; the white matter is anisotropic. The skull value is the main source of modelling error in EEG.
Proposition 2.2 — Compatibility and uniqueness The data of Definition 2.1 are compatible, and two solutions differ by a constant on a connected \Omega.
Proof. Compatibility. By the divergence theorem and the boundary condition, \int_\Omega \nabla\cdot(\sigma\nabla V) = \oint \sigma\,\partial_n V = 0 . Likewise \int_\Omega \nabla \cdot J^p = \oint J^p \cdot n = 0, since J^p vanishes near the boundary.
Uniqueness. The difference W of two solutions satisfies the homogeneous problem. Green’s identity (Theorem 0.2) with u = w = W gives \int_\Omega \sigma\, |\nabla W|^2 = 0, so \nabla W = 0 and W is constant. ∎
The potential is only defined up to a constant: EEG always measures differences, with respect to a reference electrode or to the average of all electrodes.
2.2 Weak formulation
Theorem 2.3 — Variational formulation and well-posedness Let 0 < \sigma_{\min} \le \sigma \le \sigma_{\max} and J^p \in L^2(\Omega)^3. Let H be the space of functions of H^1(\Omega) with zero mean. There is a unique V \in H such that a(V, w) := \int_\Omega \sigma\, \nabla V \cdot \nabla w \, dr = \int_\Omega J^p \cdot \nabla w \, dr =: \ell(w) \qquad \text{for all } w \in H^1(\Omega).
Proof. From strong to weak. Multiply the equation by w and apply Green’s identity on both sides. The boundary term on the left vanishes by the Neumann condition, and the one on the right because J^p = 0 on \partial\Omega.
Well-posedness. For constant w both sides vanish, so testing on H suffices. The form a is continuous on H^1. On H, the Poincaré–Wirtinger inequality \|w\|_{L^2} \le C_P \|\nabla w\|_{L^2} makes it coercive: a(w, w) \ge \sigma_{\min} \|\nabla w\|^2 \ge \frac{\sigma_{\min}}{1 + C_P^2}\, \|w\|_{H^1}^2 . Since \ell is continuous, the Lax–Milgram theorem concludes. ∎
A point dipole is not in L^2: for it, \ell(w) = q \cdot \nabla w(r_0), which is not continuous on H^1. Two classical remedies follow. The direct approach evaluates this formula on piecewise-linear test functions anyway. The subtraction approach removes the singularity analytically (Proposition 2.6).
2.3 Galerkin approximation with P1 elements
Definition 2.4 — P1 finite elements Mesh \Omega into tetrahedra (triangles in 2D) of size h, with nodes x_1, \dots, x_N. Let \varphi_i be the continuous, piecewise-linear “hat” function with \varphi_i(x_j) = \delta_{ij}.
Seeking V_h = \sum_j v_j \varphi_j with a(V_h, \varphi_i) = \ell(\varphi_i) for all i gives the linear system K v = b, \qquad K_{ij} = \int_\Omega \sigma\, \nabla \varphi_i \cdot \nabla \varphi_j, \qquad b_i = \ell(\varphi_i) . K is sparse, symmetric and positive semi-definite, with kernel spanned by the constant vector. For a dipole, the direct approach takes b_i = q \cdot \nabla \varphi_i(r_0).
Proposition 2.5 — Céa’s lemma (energy-norm optimality) Let V solve Theorem 2.3 and V_h the Galerkin problem, both with zero mean, and write \|u\|_a^2 = a(u, u). Then V_h is the best approximation of V in the discrete space: \|V - V_h\|_a = \min_{w_h} \|V - w_h\|_a .
Proof. Subtracting the discrete equations from the continuous ones gives Galerkin orthogonality: a(V - V_h, w_h) = 0 for every discrete w_h.
For any w_h, write V - w_h = (V - V_h) + (V_h - w_h), with the second term discrete. By orthogonality, \|V - w_h\|_a^2 = \|V - V_h\|_a^2 + \|V_h - w_h\|_a^2 \ge \|V - V_h\|_a^2 . ∎
For a smooth solution, interpolation gives an error of order h in the energy norm and h^2 in L^2 (Ern and Guermond, 2004). A dipole solution is not smooth near r_0, which spoils this rate unless the singularity is removed.
Proposition 2.6 — Subtraction source model Suppose \sigma equals a constant \sigma_\infty near r_0, and let V_\infty be the infinite-medium potential of Proposition 1.5 computed with \sigma_\infty.
Then V = V_\infty + W, where the correction W is smooth near r_0 and solves, for all w, \int_\Omega \sigma \nabla W \cdot \nabla w = \int_\Omega (\sigma_\infty - \sigma)\, \nabla V_\infty \cdot \nabla w \; - \oint_{\partial\Omega} \sigma_\infty\, \partial_n V_\infty \; w \, dS . Derivation: apply Green’s identity to V_\infty on \Omega, then subtract it from the weak form of V. The volume integrand vanishes near r_0, so every right-hand side is regular.
2.4 Lead field and reciprocity
Definition 2.7 — Lead field Column j of the lead field G is the forward solution for a unit dipole at source j, sampled at the electrodes. With the average reference it becomes G \leftarrow H G, \qquad H = I_m - \tfrac{1}{m} \mathbf{1}\mathbf{1}^\top . For MEG, the field is then computed from V by Biot–Savart; the Geselowitz formula of section 9.1 does this with surface integrals.
Computing G column by column takes one solve per source, that is 10^4 solves for a cortical source space. Reciprocity reverses the roles of sources and sensors.
Theorem 2.8 — Helmholtz reciprocity Let U_{ab} be the potential created when a current I is injected at electrode a and extracted at electrode b: \nabla \cdot (\sigma \nabla U_{ab}) = 0 \ \text{ in } \Omega, \qquad \sigma\, \partial_n U_{ab} = I\, (\delta_a - \delta_b) \ \text{ on } \partial\Omega . Then, for every primary current J^p, V(a) - V(b) = \frac{1}{I} \int_\Omega J^p \cdot \nabla U_{ab}\, dr, \qquad \text{and for a dipole} \qquad V(a) - V(b) = \frac{q \cdot \nabla U_{ab}(r_0)}{I} .
Proof. Apply Green’s identity (Theorem 0.2) to the pair (V, U_{ab}) in both orders.
First order. Since \nabla\cdot(\sigma\nabla U_{ab}) = 0, \int_\Omega \sigma \nabla V \cdot \nabla U_{ab} = \oint V\, \sigma\, \partial_n U_{ab} = I\,\big(V(a) - V(b)\big) .
Second order. Since \sigma\,\partial_n V = 0 on the boundary, \int_\Omega \sigma \nabla U_{ab} \cdot \nabla V = -\int_\Omega U_{ab}\, \nabla \cdot J^p = \int_\Omega J^p \cdot \nabla U_{ab} , the last step by parts, J^p vanishing on the boundary. Equating the two expressions gives the result. ∎
One solve per electrode (relative to the reference) thus gives every row of G. The discrete version is exact: since K is symmetric, (e_a - e_b)^\top K^{+} b = b^\top K^{+} (e_a - e_b), which is the identity of Theorem 2.8 for the FEM solution.
Code 2.9 — P1 finite elements on a disk: direct versus subtraction source model, and reciprocity The 2D unit disk with \sigma = 1 has an exact solution by the method of images: the Neumann function is N(r, s) = \frac{1}{2\pi}\big(\ln|r - s| + \ln|r - s^*|\big) with s^* = s/|s|^2, and V = -q \cdot \nabla_s N(r, s) at s = r_0.
import numpy as np
from scipy.spatial import Delaunay
from scipy.sparse import coo_matrix
from scipy.sparse.linalg import spsolve
def disk_mesh(n_rings):
"""Nodes on concentric rings of the unit disk; the last ring is the scalp."""
pts = [np.zeros((1, 2))]
for k in range(1, n_rings + 1):
t = 2 * np.pi * np.arange(6 * k) / (6 * k)
pts.append(k / n_rings * np.c_[np.cos(t), np.sin(t)])
p = np.vstack(pts)
return p, Delaunay(p).simplices, np.arange(len(p) - 6 * n_rings, len(p))
def stiffness(p, tri, sigma=1.0):
"""P1 stiffness matrix and the gradients of the hat functions per triangle."""
M = np.concatenate([np.ones((len(tri), 3, 1)), p[tri]], axis=2)
G = np.linalg.inv(M)[:, 1:, :].transpose(0, 2, 1) # (T, 3, 2)
area = np.abs(np.linalg.det(M)) / 2
Ke = sigma * area[:, None, None] * G @ G.transpose(0, 2, 1)
I, J = np.repeat(tri, 3, axis=1).ravel(), np.tile(tri, (1, 3)).ravel()
return coo_matrix((Ke.ravel(), (I, J)), shape=(len(p),) * 2).tocsr(), G
def solve_neumann(K, b):
"""Ground node 0 (V is defined up to a constant), then remove the mean."""
K = K.tolil(); K[0, :] = 0; K[0, 0] = 1; b = b.copy(); b[0] = 0
v = spsolve(K.tocsr(), b)
return v - v.mean()
def v_inf(x, r0, q): # 2-D infinite-medium dipole, sigma = 1
d = x - r0
return (d @ q) / (2 * np.pi * np.sum(d**2, axis=1))
def grad_v_inf(x, r0, q):
d = x - r0; d2 = np.sum(d**2, axis=1)[:, None]
return (q / d2 - 2 * (d @ q)[:, None] * d / d2**2) / (2 * np.pi)
def rhs_direct(p, tri, G, r0, q): # b_i = q . grad phi_i(r0)
t = Delaunay(p).find_simplex(r0)
b = np.zeros(len(p)); b[tri[t]] = G[t] @ q
return b
def rhs_subtraction(p, bd, r0, q): # b_i = - int dV_inf/dn phi_i ds
b, (gx, gw) = np.zeros(len(p)), np.polynomial.legendre.leggauss(3)
s, w = (gx + 1) / 2, gw / 2
for i, j in zip(bd, np.roll(bd, -1)):
e = p[j] - p[i]; L = np.linalg.norm(e); n = np.array([e[1], -e[0]]) / L
flux = grad_v_inf(p[i] + s[:, None] * e, r0, q) @ n
b[i] -= L * np.sum(w * flux * (1 - s)); b[j] -= L * np.sum(w * flux * s)
return b
def exact(x, r0, q, h=1e-6): # image solution in the unit disk
def N(s):
return (np.log(np.linalg.norm(x - s, axis=1))
+ np.log(np.linalg.norm(x - s / (s @ s), axis=1))) / (2 * np.pi)
v = -sum(qk * (N(r0 + h * e) - N(r0 - h * e)) / (2 * h)
for qk, e in zip(q, np.eye(2)))
return v - v.mean()
r0, q = np.array([0.3, 0.2]), np.array([1.0, 0.5])
for n in [10, 20, 40, 80]:
p, tri, bd = disk_mesh(n)
K, G = stiffness(p, tri)
va = exact(p[bd], r0, q)
v1 = solve_neumann(K, rhs_direct(p, tri, G, r0, q))
v2 = solve_neumann(K, rhs_subtraction(p, bd, r0, q)) + v_inf(p, r0, q)
err = [np.linalg.norm(v[bd] - v[bd].mean() - va) / np.linalg.norm(va) for v in (v1, v2)]
print(f"rings {n:2d}, h = {1/n:.4f}: direct {err[0]:.1e}, subtraction {err[1]:.1e}")
a, b = bd[0], bd[len(bd) // 4] # reciprocity on the finest mesh
inj = np.zeros(len(p)); inj[a], inj[b] = 1.0, -1.0
U = solve_neumann(K, inj) # unit current injected at a, out at b
t = Delaunay(p).find_simplex(r0)
print(f"V(a) - V(b) = {v1[a] - v1[b]:.6f}, q . grad U(r0) = {q @ (G[t].T @ U[tri[t]]):.6f}")Output: the relative error of the scalp potential falls from 9.7 \times 10^{-4} to 1.5 \times 10^{-5} with the subtraction model, a factor of about 4 per halving of h. The direct model stalls between 3 \times 10^{-3} and 4 \times 10^{-2}, depending on where the dipole falls inside its triangle. Both sides of the reciprocity identity print 0.311940.
Boundary element methods, which mesh only the interfaces, are the main alternative for nested homogeneous compartments (section 9.1). Finite elements handle anisotropy, holes in the skull and arbitrary geometry, at the price of a volume mesh built from a segmented MRI.
Key takeaways — chapter 2
- The EEG forward problem is a Neumann problem for \nabla\cdot(\sigma\nabla V) = \nabla\cdot J^p; its solution is unique up to a constant.
- The weak form is well posed for L^2 sources (Lax–Milgram); P1 finite elements give the energy-optimal approximation (Céa).
- A point dipole is singular: the subtraction approach restores the h^2 convergence that the direct approach loses.
- Reciprocity gives each row of the lead field from one solve with current injected at a pair of electrodes.
3. Preprocessing and denoising M/EEG signals
A raw recording mixes brain activity of interest with eye blinks, heartbeats, muscle activity, line noise and ongoing background activity, often larger than the signal sought. This chapter gives the linear tools that separate them, and states the assumptions each one makes.
3.1 Signal model and sources of noise
Definition 3.1 — Measurement model Over T time samples, the data matrix X \in \mathbb{R}^{m \times T} is modelled as X = G S + A + N, where G S is the activity of interest, A the artifacts (ocular, cardiac, muscular, movement, 50 Hz line noise and its harmonics), and N the sensor noise and background brain activity, spatially correlated.
3.2 Filtering and averaging
A band-pass filter keeps the band of interest (1–40 Hz for evoked responses, 8–30 Hz for sensorimotor rhythms) and a notch removes the line frequency. Offline, zero-phase filtering avoids delays; online, as in a BCI, filters must be causal.
Proposition 3.2 — Averaging over trials Let epochs time-locked to a stimulus be x_k(t) = s(t) + n_k(t), k = 1, \dots, N, with a response s identical across trials and noises n_k independent, centred and of variance \sigma^2. The average \bar x satisfies \mathbb{E}\,\bar x(t) = s(t), \qquad \mathrm{Var}\, \bar x(t) = \frac{\sigma^2}{N} , so the amplitude signal-to-noise ratio grows as \sqrt N.
Proof. Linearity of expectation gives the mean. The noises are independent, so the variance of their sum is N\sigma^2, divided by N^2. ∎
Example 3.3 — How many trials? An evoked component of 2 µV in background activity of standard deviation 10 µV has a single-trial SNR of 0.2. Reaching an SNR of 3 requires \sqrt N \ge 15: N \ge 225 \text{ trials}. If the latency jitters from trial to trial, the average is the response convolved with the jitter distribution, smaller and wider than s.
3.3 Noise covariance and whitening
Definition 3.4 — Whitening Let C_N = \mathbb{E}[n n^\top] be the noise covariance across sensors, estimated on a baseline or on an empty-room recording, and regularised when few samples are available. The whitener is W = C_N^{-1/2}, \qquad \tilde X = W X = (W G)\, S + W N, \qquad \mathrm{Cov}(W n) = I_m .
Proof. Since C_N^{-1/2} is symmetric, \mathrm{Cov}(Wn) = W C_N W^\top = C_N^{-1/2} C_N C_N^{-1/2} = I . ∎
Whitening puts channels of different units (EEG in volts, magnetometers and gradiometers in teslas and teslas per metre) on a common scale. Least squares on whitened data is generalised least squares, the efficient estimator under correlated noise (Proposition 5.3 states the same fact for fMRI).
3.4 Signal-space projection
Proposition 3.5 — Signal-space projection (SSP; Uusitalo and Ilmoniemi, 1997) Let the columns of U_a \in \mathbb{R}^{m \times k} be an orthonormal basis of the artifact topographies, estimated by a PCA of artifact epochs (blinks, heartbeats) or of empty-room data. The matrix P = I_m - U_a U_a^\top is the orthogonal projector onto the complement of \mathrm{span}(U_a). Then P A = 0 for every artifact whose topographies lie in \mathrm{span}(U_a), and the projected data obey P X = (P G) S + P N.
Proof. P is symmetric and P^2 = I - 2U_aU_a^\top + U_a (U_a^\top U_a) U_a^\top = P, since U_a^\top U_a = I_k. If A = U_a C, then PA = U_a C - U_a C = 0. The last identity is linearity. ∎
Two consequences matter in practice. The lead field must be projected as well (PG), otherwise source estimates are biased. And the component of every brain topography along U_a is lost: a source whose topography resembles a blink is attenuated with it.
3.5 Independent component analysis
Definition 3.6 — ICA model The data are an instantaneous mixture x(t) = A\, s(t) of k sources, with A \in \mathbb{R}^{m \times k} of rank k and source components that are mutually independent, centred and of unit variance. ICA seeks an unmixing matrix B with B x = P D\, s , for some permutation P and diagonal D: order and scale are not identifiable.
Theorem 3.7 — Identifiability (Comon, 1994) If at most one source is Gaussian, the mixing matrix is identifiable up to permutation and scaling of its columns. With two or more Gaussian sources, any rotation of them is again a valid solution. The proof rests on the Darmois–Skitovich theorem.
After PCA whitening, z = W x has identity covariance and z = Q s with Q orthogonal, since Q Q^\top = \mathrm{Cov}(z) = I. It remains to find a rotation, which non-Gaussianity determines.
Proposition 3.8 — Kurtosis as a contrast Let \kappa_i be the fourth cumulant (excess kurtosis) of s_i, assumed positive for all i. For a unit vector w, set u = Q^\top w (also a unit vector), so that y = w^\top z = u^\top s. Then \kappa(y) = \sum_i u_i^4 \kappa_i , and the maximum over the unit sphere is attained at u = \pm e_{i^*} with i^* = \arg\max_i \kappa_i: the output is then one of the sources.
Proof. Fourth cumulants add over independent variables and scale with the fourth power, which gives the formula.
Since |u_i| \le 1, u_i^4 \le u_i^2, so \sum_i u_i^4 \kappa_i \le \max_i \kappa_i \sum_i u_i^2 = \kappa_{i^*}, with equality at u = \pm e_{i^*}. Each \pm e_i is moreover a local maximum, and Delfosse and Loubaton (1995) show that there are no others. Deflation then extracts the sources one by one. ∎
FastICA (Hyvärinen and Oja, 2000) maximises an approximation of negentropy with a nonlinearity g and the fixed-point update, followed by normalisation, w \leftarrow \mathbb{E}[z\, g(w^\top z)] - \mathbb{E}[g'(w^\top z)]\, w . Components that correlate with an EOG or ECG channel, or look like blinks, are zeroed before back-projection.
Code 3.9 — Removing blinks by SSP and by ICA
import numpy as np
from sklearn.decomposition import FastICA
from scipy.stats import kurtosis
rng = np.random.default_rng(0)
fs, T = 250, 20 # 250 Hz, 20 s
t = np.arange(fs * T) / fs
alpha = np.sin(2 * np.pi * 10 * t) * (1 + 0.5 * np.sin(2 * np.pi * 0.2 * t))
beta = rng.standard_normal(t.size) # broadband background source
blink = np.zeros_like(t)
for t0 in rng.uniform(0.5, T - 0.5, size=12): # 12 blinks, about 0.3 s each
blink += 8 * np.exp(-0.5 * ((t - t0) / 0.06) ** 2)
S = np.vstack([alpha, beta, blink]) # (3 sources, time)
n_ch = 8
A = rng.standard_normal((n_ch, 3))
A[:, 2] = np.abs(A[:, 2]) * np.linspace(2, 0.2, n_ch) # blink: frontal channels
X_brain = A[:, :2] @ S[:2]
X = X_brain + np.outer(A[:, 2], blink) + 0.1 * rng.standard_normal((n_ch, t.size))
def report(name, Xc):
D = Xc - X_brain
D -= D.mean(axis=1, keepdims=True) # offsets are removed by high-pass filtering
err = np.linalg.norm(D) / np.linalg.norm(X_brain)
print(f"{name:22s} relative error to the artifact-free signal: {err:.3f}")
report("raw", X)
# Signal-space projection: first principal direction of the blink periods
mask = blink > 1.0
U, _, _ = np.linalg.svd(X[:, mask] - X[:, mask].mean(1, keepdims=True), full_matrices=False)
u = U[:, :1]
P = np.eye(n_ch) - u @ u.T # projector onto the complement
report("SSP (1 component)", P @ X)
# ICA: the blink component is the one with the largest kurtosis
ica = FastICA(n_components=3, whiten="unit-variance", random_state=0, max_iter=1000)
Sh = ica.fit_transform(X.T) # (time, components)
k = np.argmax(kurtosis(Sh, axis=0))
Sh[:, k] = 0
report("ICA (blink removed)", ica.inverse_transform(Sh).T)
print("kurtosis of the components:", np.round(kurtosis(ica.transform(X.T), axis=0), 1))
print("angle between blink topography and SSP vector (deg):",
round(np.degrees(np.arccos(abs(u[:, 0] @ A[:, 2]) / np.linalg.norm(A[:, 2]))), 2))Output: the relative error drops from 2.655 (raw) to 0.388 with SSP and 0.060 with ICA. The SSP vector is within 2.3° of the blink topography, yet SSP also removes the brain signal along it (Proposition 3.5). ICA isolates the blink (kurtosis 11.8).
Key takeaways — chapter 3
- Averaging N time-locked trials divides the noise standard deviation by \sqrt N, if the response is identical across trials and the noise independent.
- Whitening by C_N^{-1/2} equalises sensor types and turns least squares into generalised least squares.
- SSP removes a subspace of topographies exactly, together with the brain signal in that subspace; the lead field must be projected too.
- ICA separates independent non-Gaussian sources up to order and scale; artifacts are removed by zeroing their components.
4. The M/EEG inverse problem
Given the measurements and the lead field, where are the active sources? The problem is ill-posed, and every method adds an assumption: few dipoles, uncorrelated sources, or a prior on the amplitudes. This chapter covers MUSIC, beamforming and imaging, and their validation.
4.1 Ill-posedness
Proposition 4.1 — Non-uniqueness and instability Let M = G J + N with G \in \mathbb{R}^{m \times p} and p > m.
- The kernel of G has dimension at least p - m: adding any J_0 \in \ker G (a silent source) leaves the data unchanged.
- With the SVD G = \sum_i s_i u_i v_i^\top, the minimum-norm least-squares solution is G^+ M = \sum_{s_i > 0} \frac{u_i^\top M}{s_i}\, v_i, so noise along u_i is amplified by 1/s_i.
Proof. Item 1 is the rank–nullity theorem, since \mathrm{rank}\, G \le m. Item 2 is Definition 0.4. ∎
Helmholtz (1853) already noted that currents inside a conductor cannot be recovered from external measurements; radial dipoles in MEG (Theorem 1.9) are an explicit silent source. The singular values of a realistic lead field decay over several orders of magnitude, so regularisation is unavoidable.
4.2 Dipole fitting
Proposition 4.2 — Variable projection For k dipoles at positions \mathbf r = (r_1, \dots, r_k), with lead field G(\mathbf r) \in \mathbb{R}^{m \times 3k} and moments Q \in \mathbb{R}^{3k \times T}, \min_{Q} \|M - G(\mathbf r)\, Q\|_F^2 = \big\| \big(I - G(\mathbf r) G(\mathbf r)^+\big) M \big\|_F^2 , attained at Q = G(\mathbf r)^+ M. The fit reduces to a nonlinear problem in 3k position parameters.
Proof. For fixed positions the problem is linear least squares, column by column; its solution is G^+ M and the residual is the projection of M onto the orthogonal complement of the range of G(\mathbf r). ∎
The reduced cost has local minima and is minimised from a grid of starting points. The goodness of fit 1 - \|P^\perp M\|^2/\|M\|^2 is the explained variance. Dipole fitting suits focal responses, such as early auditory components.
4.3 MUSIC
Assume k sources with fixed positions, topographies G_S = [g_1, \dots, g_k] and time courses of covariance C_Q, in white noise (after whitening). The data covariance is R = G_S C_Q G_S^\top + \sigma^2 I_m .
Theorem 4.3 — MUSIC (Schmidt, 1986; Mosher, Lewis and Leahy, 1992) Let G_S have full column rank k and C_Q be positive definite. Let U_s be the eigenvectors of R with the k largest eigenvalues.
For a candidate topography g(r), the subspace correlation c(r) = \frac{\|U_s^\top g(r)\|^2}{\|g(r)\|^2} \in [0, 1] equals 1 exactly when g(r) \in \mathrm{span}(G_S); in particular c(r_j) = 1 at every true source.
Proof. The matrix G_S C_Q G_S^\top has range \mathrm{span}(G_S). It is contained in it. Conversely, for x = G_S y, choose z with G_S^\top z = C_Q^{-1} y, which is possible since G_S^\top has full row rank; then G_S C_Q G_S^\top z = G_S y = x .
Its non-zero eigenvalues are positive and its eigenvectors span this range. Adding \sigma^2 I shifts all eigenvalues by \sigma^2, so the top k eigenvectors of R span \mathrm{span}(G_S).
Finally c(r) is the squared cosine between g(r) and this subspace, equal to 1 if and only if g(r) lies in it. ∎
In practice R is estimated and c peaks near, not exactly at, the sources. RAP-MUSIC (Mosher and Leahy, 1999) projects out each source found before scanning again, which avoids picking secondary peaks of the same source. If two sources are perfectly correlated, C_Q is singular and the theorem fails.
4.4 Beamforming
Theorem 4.4 — LCMV beamformer (Van Veen et al., 1997) Let C be the data covariance, positive definite. The spatial filter that passes a source at r with unit gain and minimises the output power, \min_{w}\ w^\top C w \quad \text{subject to} \quad w^\top g(r) = 1, is w(r) = \frac{C^{-1} g(r)}{g(r)^\top C^{-1} g(r)}, \qquad \text{with output power} \qquad P(r) = \frac{1}{g(r)^\top C^{-1} g(r)} .
Proof. The Lagrangian w^\top C w - 2\mu\,(w^\top g - 1) has gradient 2Cw - 2\mu g, which vanishes at w = \mu C^{-1} g. The constraint gives \mu = 1/(g^\top C^{-1} g). The objective is strictly convex, so this point is the minimum, and w^\top C w = \mu^2\, g^\top C^{-1} g = \mu. ∎
Proposition 4.5 — A single source is recovered with its power If C = P\, g_0 g_0^\top + C_N (one source of power P plus noise), then at the true location P(r_0) = P + \frac{1}{g_0^\top C_N^{-1} g_0} .
Proof. Set \alpha = g_0^\top C_N^{-1} g_0. By the Sherman–Morrison formula, g_0^\top C^{-1} g_0 = \alpha - \frac{P \alpha^2}{1 + P\alpha} = \frac{\alpha}{1 + P\alpha} , whose inverse is P + 1/\alpha. ∎
The noise term 1/\alpha grows with depth, because deep sources have small topographies. The neural activity index divides P(r) by 1/(g^\top C_N^{-1} g) to remove it. Beamformers assume uncorrelated sources: two perfectly correlated sources cancel each other (Exercise 10).
4.5 Distributed imaging: minimum-norm estimates
Theorem 4.6 — Minimum-norm estimate as a posterior mean (Hämäläinen and Ilmoniemi, 1994) Let M = G J + N with N \sim \mathcal{N}(0, C_N) and the prior J \sim \mathcal{N}(0, R/\lambda), R positive definite. The posterior mean of J, which is also the minimiser of \|M - G J\|^2_{C_N^{-1}} + \lambda\, J^\top R^{-1} J , is the linear estimate
Key result — the minimum-norm inverse operator \hat J = W M, \qquad W = R\, G^\top \big(G R G^\top + \lambda\, C_N\big)^{-1}
Proof. (J, M) is jointly Gaussian with \mathrm{Cov}(J, M) = R G^\top/\lambda and \mathrm{Cov}(M) = G R G^\top/\lambda + C_N. The conditional mean is \mathrm{Cov}(J, M)\,\mathrm{Cov}(M)^{-1} M, which gives W after multiplying inside and outside by \lambda.
For a Gaussian posterior the mean is also the mode, hence the minimiser of the negative log-posterior, which is the displayed objective up to constants. Equivalently, change variables to \tilde J = R^{-1/2} J and \tilde M = C_N^{-1/2} M, and apply Proposition 0.5. ∎
With R = I, the estimate favours superficial sources, whose topographies have a large norm. Depth weighting uses R = \mathrm{diag}(\|g_j\|^{-2\gamma}) with \gamma between 0.5 and 0.8. The regularisation \lambda is often set to 1/\mathrm{SNR}^2 on whitened data.
Definition 4.7 — dSPM and sLORETA Take R = I and write T = (G G^\top + \lambda C_N)^{-1}, so that W = G^\top T. Two normalisations of \hat J_j are standard:
- dSPM (Dale et al., 2000) divides by the noise standard deviation of the estimate: z_j = \hat J_j / \sqrt{(W C_N W^\top)_{jj}}.
- sLORETA (Pascual-Marqui, 2002) divides by the standard deviation under the full model (source plus noise), which equals the diagonal of the resolution matrix W G: s_j = \frac{\hat J_j^2}{(W G)_{jj}}, \qquad \text{since} \quad W (G G^\top + \lambda C_N) W^\top = G^\top T G = W G .
Theorem 4.8 — sLORETA localises a single source without bias With fixed orientations, noise-free data M = g_k\, a from one source k of amplitude a \neq 0, and any \lambda > 0, the sLORETA map is maximal at the true source: s_j \le s_k \quad \text{for all } j, \qquad \text{with equality only if } g_j \text{ is collinear with } g_k .
Proof. T is symmetric positive definite, so \langle x, y \rangle_T = x^\top T y is an inner product. The estimate is \hat J_j = g_j^\top T g_k\, a and (W G)_{jj} = \langle g_j, g_j \rangle_T, hence s_j = \frac{\langle g_j, g_k\rangle_T^2}{\langle g_j, g_j\rangle_T}\, a^2 \le \langle g_k, g_k \rangle_T\, a^2 = s_k by Cauchy–Schwarz, with equality only for collinear vectors. ∎
The theorem says nothing about several simultaneous sources or about noise, where sLORETA can be biased; the unnormalised MNE is biased even in this ideal case. Sparse priors (minimum current or mixed-norm estimates) are treated in section 9.2.
4.6 Validation
Definition 4.9 — Resolution matrix, point spread and cross-talk For a linear inverse operator W, \hat J = W G J + W N. The resolution matrix is \mathcal R = W G \in \mathbb{R}^{p \times p}.
- Column k is the point-spread function of source k: how a unit source at k is spread over the estimate.
- Row j is the cross-talk function of location j: how all sources leak into the estimate at j.
- The localisation error of source k is the distance from k to the peak of its point-spread function. With d_{jk} the distance between locations, the spatial dispersion is \mathrm{SD}_k = \Big(\sum_j d_{jk}^2 \mathcal R_{jk}^2 \Big/ \sum_j \mathcal R_{jk}^2\Big)^{1/2} .
For MNE with R = I, \mathcal R = G^\top T G is symmetric: point-spread and cross-talk functions coincide. Validation also uses simulations at realistic SNR, phantoms, known functional anatomy, intracranial recordings or fMRI of the same task, and test–retest reliability.
Code 4.10 — Localisation error of five inverse methods on a toy EEG model The forward model is Proposition 1.5 (infinite homogeneous medium), with radial dipoles on two shells at 7 cm (superficial) and 5 cm (deep), and 60 electrodes at 9 cm.
import numpy as np
rng = np.random.default_rng(1)
def fib_sphere(n, radius, zmin=0.0):
"""Quasi-uniform points on the upper part (z > zmin) of a sphere."""
k = np.arange(n) + 0.5
z = 1 - k / n * (1 - zmin)
phi = np.pi * (1 + 5**0.5) * k
rho = np.sqrt(1 - z**2)
return radius * np.c_[rho * np.cos(phi), rho * np.sin(phi), z]
# Sources: radial dipoles on two shells (superficial 7 cm, deep 5 cm); 60 EEG electrodes at 9 cm
src = np.vstack([fib_sphere(300, 0.07, 0.2), fib_sphere(150, 0.05, 0.2)])
ori = src / np.linalg.norm(src, axis=1, keepdims=True)
elec = fib_sphere(60, 0.09, 0.0)
sigma = 0.33
d = elec[:, None, :] - src[None, :, :] # (60, 450, 3)
G = np.einsum("ijk,jk->ij", d, ori) / (4 * np.pi * sigma * np.linalg.norm(d, axis=2) ** 3)
H = np.eye(60) - 1 / 60 # average reference
G = H @ G # V/(A m)
def simulate(k, snr=1.0, n_t=200):
s = 10e-9 * np.sin(2 * np.pi * 10 * np.arange(n_t) / 1000) # 10 nAm, 10 Hz
M0 = np.outer(G[:, k], s)
noise_sd = np.linalg.norm(M0) / np.sqrt(M0.size) / snr
return M0 + H @ (noise_sd * rng.standard_normal(M0.shape)), noise_sd**2 * H
def localise(M, Cn, lam=1 / 9):
Cn_r = Cn + 1e-6 * np.trace(Cn) / 60 * np.eye(60) # regularised noise covariance
T = np.linalg.inv(G @ G.T + lam * np.trace(G @ G.T) / np.trace(Cn_r) * Cn_r)
W = G.T @ T # minimum-norm operator
J = W @ M
p_mne = np.sum(J**2, axis=1)
p_dspm = p_mne / np.einsum("ij,jk,ik->i", W, Cn_r, W) # noise-normalised
p_slor = p_mne / np.einsum("ij,ji->i", W, G) # diag of the resolution matrix
C = M @ M.T / M.shape[1] + 0.05 * np.trace(M @ M.T) / M.shape[1] / 60 * np.eye(60)
Ci = np.linalg.inv(C)
p_lcmv = 1 / np.einsum("ij,jk,ki->i", G.T, Ci, G) # unit-gain beamformer power
p_lcmv /= np.einsum("ij,jk,ki->i", G.T, np.linalg.inv(Cn_r), G) ** -1 # neural activity index
U = np.linalg.svd(M, full_matrices=False)[0][:, :1] # signal subspace, rank 1
p_music = np.sum((U.T @ G) ** 2, axis=0) / np.sum(G**2, axis=0)
return {name: np.argmax(p) for name, p in
[("MNE", p_mne), ("dSPM", p_dspm), ("sLORETA", p_slor),
("LCMV", p_lcmv), ("MUSIC", p_music)]}
for depth, ks in [("superficial", range(0, 300, 30)), ("deep", range(300, 450, 15))]:
errs = {}
for k in ks:
M, Cn = simulate(k)
for name, j in localise(M, Cn).items():
errs.setdefault(name, []).append(1000 * np.linalg.norm(src[j] - src[k]))
print(f"{depth:11s} mean localisation error (mm): " +
", ".join(f"{n} {np.mean(e):5.1f}" for n, e in errs.items()))Output, in mm: superficial sources, MNE 6.9, dSPM 12.4, sLORETA, LCMV and MUSIC 0.0; deep sources, MNE 40.4, dSPM 3.9, the others 0.0. The depth bias of MNE is plain; at an SNR of 0.1 all methods degrade.
Key takeaways — chapter 4
- The inverse problem has silent sources and small singular values: every method adds an assumption.
- Dipole fitting reduces to a nonlinear problem in the positions (variable projection); MUSIC scans the signal subspace; LCMV filters with unit gain and minimum power.
- The minimum-norm estimate is the posterior mean under Gaussian priors; dSPM and sLORETA normalise it, and sLORETA has no localisation bias for one noise-free source.
- The resolution matrix WG summarises a linear method; simulations, phantoms and known anatomy validate it.
5. fMRI: the BOLD signal and the general linear model
In which of the hundred thousand voxels of an fMRI run does the signal follow the task, and is the effect present in the population, not only in the subjects scanned? The general linear model and its two-level extension answer.
5.1 The BOLD signal
Deoxyhaemoglobin is paramagnetic and oxyhaemoglobin is not. When a brain area becomes active, blood flow increases more than oxygen consumption, so the local concentration of deoxyhaemoglobin falls. The field inhomogeneities it creates decrease, the transverse relaxation time T_2^* lengthens, and the MR signal rises by 1–5 % at 3 T: the BOLD contrast (Ogawa et al., 1990).
The response is slow: it peaks about 5 s after a brief stimulus, then undershoots. It correlates best with local field potentials, hence with synaptic activity (Logothetis et al., 2001). A volume of 2–3 mm voxels is acquired every 1–2 s (the repetition time, TR), corrected for motion, registered to a template and often smoothed.
5.2 The linear model of the response
Definition 5.1 — Haemodynamic response and design matrix The BOLD response is modelled as a linear time-invariant system (Friston et al., 1994): for experimental conditions with onset functions u_c, y(t) = \sum_c \beta_c\, (h * u_c)(t) + d(t) + \varepsilon(t), with the canonical haemodynamic response function (HRF), a difference of two gamma densities, time in seconds: h(t) = \frac{t^5 e^{-t}}{5!} - \frac{1}{6}\, \frac{t^{15} e^{-t}}{15!} , which peaks at 5 s and has its undershoot near 16 s. Sampling at the n scan times gives y = X\beta + \varepsilon. The columns of the design matrix X \in \mathbb{R}^{n \times p} are the convolved regressors, a low-frequency drift basis d (cosines of period above about 128 s) and a constant.
Linearity holds well for stimuli a few seconds apart; closer stimuli saturate, which nonlinear models such as the balloon model describe (Buxton et al., 1998). Adding the time derivative of h to the design absorbs small shifts of latency.
5.3 Estimation and inference
Theorem 5.2 — t and F tests of contrasts Assume \varepsilon \sim \mathcal{N}(0, \sigma^2 I_n) and \mathrm{rank}\, X = p; let c \in \mathbb{R}^p and C \in \mathbb{R}^{q \times p} of rank q.
Under H_0: c^\top \beta = 0, respectively H_0: C\beta = 0, t = \frac{c^\top \hat\beta}{\sqrt{\hat\sigma^2\, c^\top (X^\top X)^{-1} c}} \sim t_{n-p}, \qquad F = \frac{(C\hat\beta)^\top \big[C (X^\top X)^{-1} C^\top\big]^{-1} C\hat\beta}{q\, \hat\sigma^2} \sim F_{q,\, n-p} .
Proof. By Theorem 0.7, under H_0, c^\top\hat\beta \sim \mathcal{N}\big(0, \sigma^2 c^\top(X^\top X)^{-1}c\big), independently of (n-p)\hat\sigma^2/\sigma^2 \sim \chi^2_{n-p}. The ratio of a standard normal to the square root of an independent \chi^2_{n-p}/(n-p) is t_{n-p}.
For F, the quadratic form in the numerator is \sigma^2 \chi^2_q under H_0, since C\hat\beta is Gaussian with covariance \sigma^2 C (X^\top X)^{-1} C^\top. ∎
Proposition 5.3 — Prewhitening If \varepsilon \sim \mathcal{N}(0, \sigma^2 V) with V known and positive definite, let W satisfy W V W^\top = I. Then W y = (W X)\beta + W\varepsilon has white errors, and least squares on the whitened model is the generalised least-squares estimate \hat\beta_{\mathrm{GLS}} = (X^\top V^{-1} X)^{-1} X^\top V^{-1} y , the best linear unbiased estimate; Theorem 5.2 applies to (Wy, WX).
Proof. The whitened errors have covariance \sigma^2 W V W^\top = \sigma^2 I, and W^\top W = V^{-1}, which turns the OLS formula into the GLS formula. Optimality is the Gauss–Markov theorem in the whitened coordinates. ∎
fMRI noise is autocorrelated; an AR(1) model with coefficient \rho has a bidiagonal whitener, with first row \sqrt{1-\rho^2}, then rows (-\rho, 1). Ignoring the autocorrelation inflates false positives (Code 5.6). The efficiency of a design for c is 1/\big(c^\top (X^\top X)^{-1} c\big): blocks of 15–20 s maximise it; jittered events estimate the response shape better.
5.4 Mixed-effects models for group analysis
Definition 5.4 — Two-level model For subjects s = 1, \dots, S, the first level gives an estimate \hat\beta_s of the subject’s effect, with known variance v_s; the second level models the subjects as a sample of the population: \hat\beta_s = \beta_s + e_s, \quad e_s \sim \mathcal{N}(0, v_s), \qquad \beta_s = \mu + \eta_s, \quad \eta_s \sim \mathcal{N}(0, \tau^2) , so that marginally \hat\beta_s \sim \mathcal{N}(\mu, v_s + \tau^2). A fixed-effects analysis sets \tau^2 = 0 and concerns only the subjects scanned; a random-effects (mixed-effects) analysis concerns the population.
Proposition 5.5 — Weighted mean and the summary-statistics test For known variances, the maximum-likelihood estimate of \mu is the precision-weighted mean \hat\mu = \frac{\sum_s w_s \hat\beta_s}{\sum_s w_s}, \qquad w_s = \frac{1}{v_s + \tau^2}, \qquad \mathrm{Var}(\hat\mu) = \frac{1}{\sum_s w_s} . If all v_s are equal, \hat\mu is the plain mean. The one-sample t test on the subject estimates is then exact with S - 1 degrees of freedom, without estimating \tau^2 or the v_s.
Proof. The log-likelihood is -\frac12 \sum_s w_s(\hat\beta_s - \mu)^2 up to constants, maximised at the weighted mean; its variance is \sum_s w_s^2 (v_s + \tau^2)/(\sum_s w_s)^2 = 1/\sum_s w_s. In the balanced case the \hat\beta_s are i.i.d. \mathcal{N}(\mu, v + \tau^2), the setting of the one-sample t test. ∎
This summary-statistics approach (Holmes and Friston, 1998) is robust when within-subject variances are similar. In general, the linear mixed model y = X\beta + Z b + \varepsilon, with b \sim \mathcal{N}(0, \Gamma), has covariance V = Z \Gamma Z^\top + \sigma^2 I; its fixed effects follow by GLS (Proposition 5.3), its variance components by restricted maximum likelihood.
Code 5.6 — First-level GLM with AR(1) noise, and fixed versus random effects
import numpy as np
from scipy.stats import gamma, t as student
rng = np.random.default_rng(2)
TR, n = 2.0, 200 # 200 scans, 6 min 40 s
def hrf(tt): # canonical double-gamma (SPM shape)
return gamma.pdf(tt, 6) - gamma.pdf(tt, 16) / 6
dt = 0.1
tt = np.arange(0, 32, dt)
u = (np.arange(0, n * TR, dt) % 40 < 20).astype(float) # 20 s on / 20 s off
reg = np.convolve(u, hrf(tt))[: u.size] * dt
reg = reg[:: int(TR / dt)] # sample at the scan times
k = np.arange(1, 5) # discrete cosine drifts, period > 128 s
time = np.arange(n) * TR
drift = np.cos(np.pi * np.outer(time / (n * TR), k))
X = np.column_stack([reg, drift, np.ones(n)])
c = np.r_[1.0, np.zeros(X.shape[1] - 1)] # contrast: effect of the task
def ar1_noise(rho, sd, size):
e = np.zeros(size)
e[0] = rng.normal(0, sd / np.sqrt(1 - rho**2))
for i in range(1, size):
e[i] = rho * e[i - 1] + rng.normal(0, sd)
return e
def glm_t(y, X, rho=0.0):
"""OLS (rho = 0) or GLS after AR(1) prewhitening with a known rho."""
W = np.eye(len(y)) - rho * np.eye(len(y), k=-1)
W[0, 0] = np.sqrt(1 - rho**2)
Xw, yw = W @ X, W @ y
beta, *_ = np.linalg.lstsq(Xw, yw, rcond=None)
res = yw - Xw @ beta
dof = len(y) - X.shape[1]
s2 = res @ res / dof
var_c = s2 * c @ np.linalg.inv(Xw.T @ Xw) @ c
return c @ beta, (c @ beta) / np.sqrt(var_c), dof
# One voxel: 1% signal change on a baseline of 100, AR(1) noise with rho = 0.4
y = 100 + 1.0 * reg / reg.max() + 0.5 * drift[:, 0] + ar1_noise(0.4, 0.8, n)
for name, rho in [("OLS", 0.0), ("GLS, AR(1)", 0.4)]:
b, tval, dof = glm_t(y, X, rho)
print(f"{name:11s} beta = {b:.3f}, t = {tval:.2f}, p = {student.sf(tval, dof):.1e}")
# False-positive rate of OLS under AR(1) noise and no activation (nominal 5 %)
fp = [np.mean([glm_t(100 + ar1_noise(0.4, 0.8, n), X, r)[1] > student.isf(0.05, n - X.shape[1])
for _ in range(500)]) for r in (0.0, 0.4)]
print(f"null voxels declared active at p < 0.05: OLS {fp[0]:.3f}, GLS {fp[1]:.3f}")
# Group: 12 subjects, true mean effect 0.4, between-subject sd 0.5
betas, var_b = [], []
for s in range(12):
effect = 0.4 + 0.5 * rng.standard_normal()
ys = 100 + effect * reg / reg.max() + ar1_noise(0.4, 0.8, n)
b, tval, dof = glm_t(ys, X, 0.4)
betas.append(b); var_b.append((b / tval) ** 2)
betas, var_b = np.array(betas), np.array(var_b)
t_fixed = betas.sum() / np.sqrt(var_b.sum()) # ignores between-subject variance
t_random = betas.mean() / (betas.std(ddof=1) / np.sqrt(12))
print(f"group: fixed-effects t = {t_fixed:.2f}, random-effects t = {t_random:.2f} "
f"(p = {student.sf(t_random, 11):.3f}, 11 dof)")Output: OLS gives t = 8.00 and GLS t = 5.39 for the same voxel. On 500 null voxels, OLS declares 11.8 % active at the nominal 5 %, GLS 5.6 %. At the group level, the fixed-effects t is 6.14 and the random-effects t is 2.55 (p = 0.014): only the second supports a claim about the population.
Key takeaways — chapter 5
- BOLD is a slow, indirect marker of synaptic activity: the HRF peaks about 5 s after the event.
- The GLM convolves the experimental conditions with the HRF; contrasts are tested with t and F statistics (Theorem 5.2).
- Autocorrelated noise must be prewhitened, otherwise false positives inflate.
- Population inference needs the between-subject variance: two-level mixed-effects models, or the summary-statistics t test when the design is balanced.
6. Hypothesis testing and multiple comparisons
A statistical map tests one hypothesis per voxel, or per sensor and time point: tens of thousands of tests at once. This chapter makes precise which error rate is controlled, and gives tests that remain valid without distributional assumptions.
6.1 Mass-univariate testing
Definition 6.1 — Familywise error and false discovery rates Among V tests, let V_0 be the true nulls, R the number of rejections and F the number of false rejections. The familywise error rate and the false discovery rate are \mathrm{FWER} = P(F \ge 1), \qquad \mathrm{FDR} = \mathbb{E}\Big[\frac{F}{\max(R, 1)}\Big] .
At an uncorrected threshold of p < 0.001, a map of 50 000 voxels under the global null contains 50 false positives on average: the dead salmon of the introduction.
6.2 Permutation tests
Theorem 6.2 — Exactness of permutation tests Let \mathcal{G} be a finite group of B transformations of the data (relabellings, or sign flips) that leave the distribution of the data X invariant under H_0. For a statistic T, define p(X) = \frac{1}{B}\, \#\{g \in \mathcal{G} : T(gX) \ge T(X)\} . Then P(p(X) \le \alpha) \le \alpha under H_0 for every \alpha \in [0, 1].
Proof. Let g' be uniform on \mathcal{G}, independent of X. Under H_0, g'X has the law of X, so P(p(X) \le \alpha) = P(p(g'X) \le \alpha) .
The orbit \{g g' X : g \in \mathcal G\} equals \{gX\}, since the transformations form a group. Hence p(g'X) is the rank, from the top, of T(g'X) among the values of the orbit, divided by their number.
Given the orbit, at most \alpha B of its elements have a rank of at most \alpha B, and g' picks one uniformly. So the conditional probability is at most \alpha, and so is its expectation. ∎
For a group analysis, the subject effect maps are symmetric around zero under H_0, so flipping their signs leaves the distribution invariant: 2^S transformations (Nichols and Holmes, 2002). When B is too large, a random sample of B - 1 transformations plus the identity keeps the test valid.
6.3 Controlling the familywise error rate
Proposition 6.3 — Bonferroni and the maximum statistic
- Rejecting the tests with p_v \le \alpha / V gives \mathrm{FWER} \le \alpha.
- Let u_\alpha be the (1-\alpha) quantile of the permutation distribution of \max_v T_v. Rejecting the tests with T_v > u_\alpha controls the FWER at level \alpha under the global null.
Proof.
- By the union bound over the set \mathcal{V}_0 of true nulls, P(F \ge 1) \le \sum_{v \in \mathcal{V}_0} P(p_v \le \alpha/V) \le \frac{V_0\, \alpha}{V} \le \alpha .
- Under the global null, a false rejection occurs exactly when \max_v T_v > u_\alpha, an event of probability at most \alpha by Theorem 6.2 applied to the statistic \max_v T_v. ∎
The maximum statistic adapts to the correlation between tests: on a smooth map it gives a lower threshold than Bonferroni. Control extends to any configuration of true nulls under the subset pivotality condition (Westfall and Young, 1993). Random field theory is the parametric alternative (section 9.3).
6.4 The false discovery rate
Theorem 6.4 — Benjamini–Hochberg procedure (1995) Sort the p-values p_{(1)} \le \dots \le p_{(V)}, let k = \max\{i : p_{(i)} \le q\, i / V\}, and reject the k smallest. If the null p-values are uniform and independent of each other and of the non-null ones, \mathrm{FDR} = \frac{V_0}{V}\, q \le q .
Proof. For a null test v, let R_0^{(v)} be the number of rejections when p_v is replaced by 0; it depends only on the other p-values.
The step-up rule gives the equality of events \{v \text{ rejected}, R = k\} = \{p_v \le qk/V,\ R_0^{(v)} = k\}: a rejected p_v can be lowered to 0 without changing the rejections, and conversely.
By independence, P(v \text{ rejected}, R = k) = \frac{qk}{V} P(R_0^{(v)} = k). Hence \mathbb{E}\Big[\frac{\mathbb{1}\{v \text{ rejected}\}}{\max(R,1)}\Big] = \sum_{k=1}^V \frac{1}{k}\, \frac{qk}{V}\, P(R_0^{(v)} = k) = \frac{q}{V}, and summing over the V_0 null tests gives the result. ∎
The bound also holds under positive regression dependence (Benjamini and Yekutieli, 2001), a reasonable model for smooth maps. FDR is an average: on a given map the proportion of false discoveries can exceed q.
6.5 Cluster-level inference
Definition 6.5 — Cluster inference Threshold the map at a cluster-forming level u (for instance p < 0.001), form the connected components of supra-threshold voxels, and measure each by its size or mass (sum of statistics). Comparing each cluster with the permutation distribution of the largest cluster controls the FWER at the cluster level.
A significant cluster means that at least one of its voxels is active. The result depends on u, which threshold-free cluster enhancement avoids (Smith and Nichols, 2009). Eklund et al. (2016) found parametric cluster inference invalid at liberal thresholds, and permutation valid. For M/EEG, clusters span sensors, times and frequencies (Maris and Oostenveld, 2007).
Code 6.6 — Uncorrected, Bonferroni, maximum-statistic and FDR thresholds on a smooth map
import numpy as np
from scipy.ndimage import gaussian_filter
from scipy.stats import t as student
rng = np.random.default_rng(4)
n_sub, shape = 16, (40, 40) # 16 subjects, 1600 "voxels"
truth = np.zeros(shape, bool); truth[10:18, 10:18] = True # 64 active voxels
maps = np.array([gaussian_filter(rng.standard_normal(shape), 1.5) for _ in range(n_sub)])
maps /= maps.std()
maps[:, truth] += 1.0 # effect of 1 noise sd
def tmap(Y): # one-sample t over the first axis
return Y.mean(0) / (Y.std(0, ddof=1) / np.sqrt(len(Y)))
t_obs = tmap(maps).ravel()
dof, V = n_sub - 1, t_obs.size
# Sign-flipping permutation distribution of the maximum statistic
flat = maps.reshape(n_sub, -1)
max_null = np.array([tmap(rng.choice([-1, 1], size=(n_sub, 1)) * flat).max()
for _ in range(2000)])
thr_maxT = np.quantile(max_null, 0.95)
def bh(p, q=0.05): # Benjamini-Hochberg step-up
order = np.argsort(p)
ok = p[order] <= q * np.arange(1, p.size + 1) / p.size
k = np.max(np.nonzero(ok)[0]) + 1 if ok.any() else 0
out = np.zeros(p.size, bool); out[order[:k]] = True
return out
p = student.sf(t_obs, dof)
rules = {"uncorrected p<0.05": p < 0.05,
"uncorrected p<0.001": p < 0.001,
"Bonferroni 0.05": p < 0.05 / V,
f"max-T permutation (t>{thr_maxT:.2f})": t_obs > thr_maxT,
"BH-FDR q=0.05": bh(p)}
for name, rej in rules.items():
tp, fp = np.sum(rej & truth.ravel()), np.sum(rej & ~truth.ravel())
print(f"{name:32s} discoveries {rej.sum():4d} false {fp:3d} true {tp:2d}/64")
print(f"Bonferroni t threshold: {student.isf(0.05 / V, dof):.2f}")Output: uncorrected p < 0.05 finds all 64 active voxels but 80 false ones. Bonferroni (t > 5.49) finds 8 true voxels and the maximum statistic (t > 5.37) finds 12, both without false positives. Benjamini–Hochberg finds 58 true and 2 false voxels.
Key takeaways — chapter 6
- State the error rate: FWER (no false positive anywhere) or FDR (a controlled proportion of false discoveries).
- Permutation and sign-flipping tests are exact under exchangeability, whatever the distribution.
- The maximum statistic gives FWER control adapted to the smoothness of the map; Benjamini–Hochberg controls the FDR.
- Cluster inference gains power but only supports cluster-level claims; its parametric version can fail.
7. Connectivity, networks and covariance learning
Connectivity analysis asks which brain regions interact. With a few hundred time points and up to hundreds of regions, the main difficulty is statistical: estimating a large covariance matrix and its inverse.
7.1 Functional and effective connectivity
Definition 7.1 — Functional and effective connectivity Functional connectivity is the statistical dependence between the signals of brain regions: correlation, partial correlation, coherence. Effective connectivity is the influence that one region exerts on another within an explicit model, such as Granger causality or dynamic causal models (section 9.6). Coherence between M/EEG signals is treated with volume conduction in section 9.5.
The usual pipeline divides the brain into p regions with an atlas, extracts one time series per region, X \in \mathbb{R}^{n \times p}, and estimates a p \times p matrix, read as a weighted graph whose nodes are the regions.
7.2 Partial correlation and Gaussian graphical models
Theorem 7.2 — Precision matrix and conditional independence Let X \sim \mathcal{N}(0, \Sigma) with precision matrix K = \Sigma^{-1}. For i \neq j, the correlation of X_i and X_j given all other variables is \rho_{ij \mid \text{rest}} = -\frac{K_{ij}}{\sqrt{K_{ii} K_{jj}}} , and X_i and X_j are conditionally independent given the rest if and only if K_{ij} = 0.
Proof. The density is proportional to \exp(-\frac12 x^\top K x). With the other coordinates fixed, it is, as a function of (x_i, x_j), a Gaussian whose precision is the 2 \times 2 block of K on \{i, j\}.
Its covariance is the inverse of that block, proportional to \begin{pmatrix} K_{jj} & -K_{ij} \\ -K_{ij} & K_{ii} \end{pmatrix}, which gives the correlation. For Gaussian vectors, zero correlation is equivalent to independence. ∎
The sparsity pattern of K is the graph of the Gaussian graphical model. In a chain X_1 \to X_2 \to X_3, X_1 and X_3 are correlated, but their partial correlation is zero: partial correlations separate direct from indirect links (Smith et al., 2011).
7.3 Shrinkage estimation of covariance
The sample covariance S is singular when n \le p and ill-conditioned when n is a few times p: its large eigenvalues are biased upwards and its small ones downwards.
Proposition 7.3 — Oracle shrinkage towards the identity Let \mathbb{E} S = \Sigma, \mu = \mathrm{tr}(\Sigma)/p, and \hat\Sigma_\alpha = (1 - \alpha) S + \alpha \mu I. The weight minimising the expected Frobenius risk is \alpha^\star = \frac{\mathbb{E}\|S - \Sigma\|_F^2}{\mathbb{E}\|S - \mu I\|_F^2} \in [0, 1] .
Proof. Write \hat\Sigma_\alpha - \Sigma = (1 - \alpha)(S - \Sigma) + \alpha(\mu I - \Sigma) . The cross term has zero expectation because \mathbb{E}S = \Sigma, so \mathbb{E}\|\hat\Sigma_\alpha - \Sigma\|_F^2 = (1-\alpha)^2\, \mathbb{E}\|S - \Sigma\|_F^2 + \alpha^2\, \|\mu I - \Sigma\|_F^2 . This quadratic in \alpha is minimal at \alpha^\star = a/(a + b), with a = \mathbb{E}\|S - \Sigma\|_F^2 and b = \|\mu I - \Sigma\|_F^2. The same cross-term argument gives \mathbb{E}\|S - \mu I\|_F^2 = a + b. ∎
Ledoit and Wolf (2004) estimate a and b consistently from the data, which yields a well-conditioned estimate for any n. Shrinkage is also the standard regulariser of noise covariances (ch. 3) and of LDA (ch. 8).
7.4 Sparse inverse covariance: the graphical lasso
Definition 7.4 — Graphical lasso Given S and \lambda > 0, the graphical lasso estimates a sparse precision matrix by \hat K = \arg\max_{K \succ 0}\ \log\det K - \mathrm{tr}(S K) - \lambda \sum_{i \neq j} |K_{ij}| . The objective is concave, since \log\det is concave on positive definite matrices, so the problem is convex (Friedman, Hastie and Tibshirani, 2008).
Proposition 7.5 — Optimality conditions \hat K is optimal if and only if \hat K^{-1} - S = \lambda\, \Gamma, \qquad \Gamma_{ii} = 0, \qquad \Gamma_{ij} \in \partial|\hat K_{ij}| \ \ (i \neq j) . In particular, if \lambda \ge \max_{i \neq j} |S_{ij}|, the solution is diagonal: \hat K = \mathrm{diag}(1/S_{11}, \dots, 1/S_{pp}) .
Proof. The gradient of \log\det K - \mathrm{tr}(SK) is K^{-1} - S, and the subdifferential of |K_{ij}| is \{\mathrm{sign}(K_{ij})\} or [-1, 1] at zero; for a concave problem these conditions are necessary and sufficient.
For the diagonal candidate, \hat K^{-1} = \mathrm{diag}(S_{ii}), so \hat K^{-1} - S has zero diagonal and off-diagonal entries -S_{ij}. The choice \Gamma_{ij} = -S_{ij}/\lambda lies in [-1, 1] exactly when |S_{ij}| \le \lambda. ∎
Decreasing \lambda from this value adds edges one by one, which traces a path of graphs. For a group of subjects, a penalty shared across subjects (group sparsity) estimates a common support with subject-specific values (Varoquaux et al., 2010).
Code 7.6 — Inverse sample covariance, Ledoit–Wolf and graphical lasso on a sparse network
import numpy as np
from sklearn.covariance import LedoitWolf, GraphicalLassoCV, empirical_covariance
rng = np.random.default_rng(5)
p, n = 30, 60 # 30 regions, 60 time points
K = np.eye(p) # sparse precision: a ring + 5 chords
for i in range(p):
K[i, (i + 1) % p] = K[(i + 1) % p, i] = -0.4
for i, j in [(0, 15), (3, 20), (5, 12), (8, 25), (10, 27)]:
K[i, j] = K[j, i] = -0.3
Sigma = np.linalg.inv(K)
X = rng.multivariate_normal(np.zeros(p), Sigma, size=n)
edges = np.abs(np.triu(K, 1)) > 0
def partial_corr(P):
d = 1 / np.sqrt(np.diag(P))
return -P * np.outer(d, d)
S = empirical_covariance(X)
lw = LedoitWolf().fit(X)
gl = GraphicalLassoCV(cv=5).fit(X)
print(f"condition number: sample {np.linalg.cond(S):.0f}, "
f"Ledoit-Wolf {np.linalg.cond(lw.covariance_):.0f} (shrinkage {lw.shrinkage_:.2f})")
for name, P in [("inverse of S", np.linalg.inv(S)),
("inverse of Ledoit-Wolf", lw.precision_),
("graphical lasso", gl.precision_)]:
err = np.linalg.norm(P - K) / np.linalg.norm(K)
pc = np.abs(np.triu(partial_corr(P), 1))
top = pc >= np.sort(pc[np.triu_indices(p, 1)])[-edges.sum()] # keep as many as true edges
print(f"{name:23s} rel. error {err:.2f}, true edges among the top-{edges.sum()}: "
f"{np.sum(top & edges)}/{edges.sum()}")
nz = np.abs(np.triu(gl.precision_, 1)) > 1e-8
print(f"graphical lasso (alpha = {gl.alpha_:.3f}): {nz.sum()} edges selected, "
f"{np.sum(nz & edges)} true, {np.sum(nz & ~edges)} spurious")Output: the condition number falls from 152 to 19 with Ledoit–Wolf (shrinkage 0.25). The relative errors on K are 2.13, 0.38 and 0.28; the top-35 partial correlations hold 24, 30 and 34 of the 35 true edges. The cross-validated graphical lasso keeps 136 entries, 101 spurious: cross-validation tunes \lambda for likelihood, not for support recovery.
7.5 Covariance matrices as points of a manifold
Definition 7.7 — Affine-invariant geometry On symmetric positive definite (SPD) matrices, the affine-invariant distance is \delta(A, B) = \big\| \log\big(A^{-1/2} B A^{-1/2}\big) \big\|_F = \Big( \sum_i \ln^2 \mu_i \Big)^{1/2}, where \mu_i are the eigenvalues of A^{-1}B. The geometric mean of \Sigma_1, \dots, \Sigma_S minimises \sum_s \delta^2(C, \Sigma_s).
The tangent-space embedding at a reference C maps \Sigma to the upper triangle of \log(C^{-1/2} \Sigma C^{-1/2}), with off-diagonal entries multiplied by \sqrt 2.
Proposition 7.8 — Invariance under congruence For every invertible W, \delta(W A W^\top, W B W^\top) = \delta(A, B) .
Proof. (WAW^\top)^{-1} WBW^\top = W^{-\top} A^{-1} B\, W^\top is similar to A^{-1}B, so it has the same eigenvalues \mu_i. ∎
Distances between covariances are thus unchanged by any invertible mixing of the channels. Tangent-space embeddings turn connectomes into vectors for standard classifiers and predict phenotypes from resting-state fMRI well (Dadi et al., 2019). The same geometry drives the Riemannian classifiers of ch. 8.
Key takeaways — chapter 7
- Partial correlations, read off the precision matrix, separate direct from indirect statistical links (Theorem 7.2).
- Shrinkage (Ledoit–Wolf) and the graphical lasso make covariance and precision estimates usable when n is close to p.
- Covariance matrices live on a manifold; the affine-invariant distance is invariant to linear mixing, and tangent-space embeddings make them vectors.
8. Brain–computer interfaces
A brain–computer interface decodes, trial after trial, a few bits of intention from noisy signals and shows the result to the user, who learns in turn. This chapter assembles the previous tools into such a loop.
8.1 Communicating via brain activity
Definition 8.1 — Brain–computer interface A BCI measures brain activity and converts it, in real time, into commands for an external device, without using the normal output pathways of nerves and muscles (Wolpaw et al., 2002). Its loop is: acquisition, preprocessing, feature extraction, classification, command, and feedback to the user.
Non-invasive BCIs mostly use EEG and three paradigms:
- Motor imagery: imagining a movement of the right hand reduces the power of the mu (8–12 Hz) and beta (13–30 Hz) rhythms over the left sensorimotor cortex, an event-related desynchronisation (Pfurtscheller and Lopes da Silva, 1999).
- P300: a rare, attended stimulus evokes a positive deflection about 300 ms later; the P300 speller flashes the rows and columns of a 6 \times 6 letter matrix (Farwell and Donchin, 1988).
- SSVEP: targets flickering at distinct frequencies evoke responses at those frequencies over the visual cortex.
Proposition 8.2 — Information transfer rate With N equiprobable targets, accuracy P, and errors spread uniformly over the N - 1 other targets, the mutual information between intended and decoded targets is, in bits per selection, B = \log_2 N + P \log_2 P + (1 - P) \log_2 \frac{1 - P}{N - 1} .
Proof. By symmetry the decoded target is uniform, of entropy \log_2 N. Given the intended target, the decoded one equals it with probability P and each other target with probability (1-P)/(N-1); its entropy is minus the last two terms. Mutual information is the difference. ∎
Example 8.3 — Two BCIs compared
- Motor imagery with N = 4 classes, P = 0.8 and one trial every 4 s: B = 0.96 bit per trial, that is 14.4 bits/min.
- A P300 speller with N = 36 symbols, P = 0.9 and one letter every 15 s: B = 4.19 bits per letter, that is 16.8 bits/min.
8.2 Feature extraction
For evoked potentials, features are the decimated amplitudes of a post-stimulus window, possibly after spatial filtering. For rhythms, they are band powers after a spatial filter that the following theorem optimises.
Theorem 8.4 — Common spatial patterns (CSP) Let C_0, C_1 be the average covariance matrices of band-passed trials of the two classes, with C_0 + C_1 positive definite. The spatial filters w that maximise or minimise the fraction of variance due to class 1, \frac{w^\top C_1 w}{w^\top (C_0 + C_1) w} \in [0, 1], are the generalised eigenvectors of C_1 w = \mu\, (C_0 + C_1)\, w with the largest or smallest eigenvalues. They diagonalise both matrices: W^\top (C_0 + C_1) W = I and W^\top C_1 W = \mathrm{diag}(\mu).
Proof. Apply Proposition 0.6 with C_2 = C_0 + C_1. The quotient lies in [0, 1] because 0 \le w^\top C_1 w \le w^\top (C_0 + C_1) w. Generalised eigenvectors of a symmetric pencil with a positive definite second matrix can be chosen C_2-orthonormal, which is the joint diagonalisation. ∎
The features are the log-variances of the 2 or 3 filtered signals at each end of the spectrum (Ramoser et al., 2000). CSP overfits with few trials and is sensitive to outliers. The Riemannian alternative uses the trial covariances themselves (Definition 7.7).
8.3 Classification
Proposition 8.5 — Linear discriminant analysis is Bayes-optimal for Gaussian classes If x \mid y = k \sim \mathcal{N}(m_k, \Sigma) with a shared covariance and priors \pi_k, the Bayes rule chooses class 1 if and only if w^\top x + b > 0, with w = \Sigma^{-1}(m_1 - m_0), \qquad b = -\tfrac12\, w^\top (m_0 + m_1) + \ln \frac{\pi_1}{\pi_0} .
Proof. The log-ratio of the posterior probabilities is the log-ratio of the densities plus \ln(\pi_1/\pi_0). The quadratic terms x^\top \Sigma^{-1} x cancel because the covariance is shared, leaving an affine function of x equal to w^\top x + b. ∎
For evoked-potential features of dimension in the hundreds, \Sigma is replaced by its Ledoit–Wolf estimate (Proposition 7.3; Blankertz et al., 2011). The minimum distance to the mean classifier assigns a trial covariance to the class whose geometric mean is closest (Definition 7.7); it needs no spatial filter (Barachant et al., 2012).
8.4 Model selection and evaluation
Band, time window, number of filters and shrinkage are hyperparameters, chosen by nested cross-validation. Every data-dependent step, CSP and ICA included, must be fitted inside the training folds; fitted on all trials, CSP separates even random labels. Folds should respect blocks and sessions, since EEG is non-stationary.
Model selection by nested cross-validation Score K candidate settings by cross-validation and keep the best. Its score is optimistic: each score is a noisy estimate, and the expectation of a maximum exceeds the maximum of the expectations.
Nested cross-validation removes this bias. Each outer fold is held out in turn; on the remaining trials, an inner cross-validation picks the setting, and the pipeline is refitted with it. It is then scored once on the outer fold. The mean outer score estimates the accuracy of the whole procedure, selection included.
Proposition 8.6 — Chance level for a finite test set For n independent test trials and two balanced classes, the number of correct answers of a chance classifier is \mathrm{Bin}(n, 1/2). An accuracy is significant at level \alpha only if it reaches the smallest k/n with P(\mathrm{Bin}(n, 1/2) \ge k) \le \alpha: 65\,\% \text{ for } n = 40, \qquad 60\,\% \text{ for } n = 80, \qquad 59\,\% \text{ for } n = 100 \qquad (\alpha = 0.05) .
Proof. Under the null hypothesis each answer is correct with probability 1/2, independently; the threshold is the upper \alpha quantile of the binomial law. ∎
Cross-validated accuracies come from overlapping training sets, so a permutation test of the whole pipeline (Theorem 6.2) is the safer assessment (Combrisson and Jerbi, 2015).
Code 8.7 — CSP + LDA on simulated motor imagery, leakage and chance level
import numpy as np
from scipy.linalg import eigh
from scipy.signal import butter, sosfiltfilt
from scipy.stats import binom
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
from sklearn.model_selection import cross_val_score, StratifiedKFold
from sklearn.pipeline import make_pipeline
rng = np.random.default_rng(6)
fs, n_ch, n_tr, n_s = 128, 16, 80, 2 * 128 # 80 trials of 2 s, 16 channels
sos = butter(4, [8, 13], btype="band", fs=fs, output="sos")
def mu_rhythm(size): # band-limited (8-13 Hz) source activity
return sosfiltfilt(sos, rng.standard_normal(size), axis=-1)
A = rng.standard_normal((n_ch, n_ch)) # mixing: sources -> channels
y = np.repeat([0, 1], n_tr // 2) # 0 = left hand, 1 = right hand imagery
X = np.empty((n_tr, n_ch, n_s))
for i, c in enumerate(y):
S = mu_rhythm((n_ch, n_s))
S[0] *= 0.5 if c == 1 else 1.0 # ERD of source 0 during right-hand imagery
S[1] *= 0.5 if c == 0 else 1.0 # ERD of source 1 during left-hand imagery
X[i] = A @ S + 0.5 * rng.standard_normal((n_ch, n_s))
X = sosfiltfilt(sos, X, axis=-1) # band-pass, as in any MI pipeline
class CSP(BaseEstimator, TransformerMixin):
"""Common spatial patterns: generalised eigenvectors of (C1, C0 + C1)."""
def __init__(self, n_filters=4):
self.n_filters = n_filters
def fit(self, X, y):
C = [np.mean([x @ x.T / x.shape[1] for x in X[y == k]], axis=0) for k in (0, 1)]
vals, W = eigh(C[1], C[0] + C[1]) # ascending eigenvalues in (0, 1)
idx = np.r_[np.arange(self.n_filters // 2), np.arange(-(self.n_filters // 2), 0)]
self.W_ = W[:, idx]
return self
def transform(self, X):
Z = np.einsum("ck,ncs->nks", self.W_, X)
return np.log(np.var(Z, axis=2)) # log-variance features
class LogVar(BaseEstimator, TransformerMixin): # baseline: log-variance of raw channels
def fit(self, X, y): return self
def transform(self, X): return np.log(np.var(X, axis=2))
cv = StratifiedKFold(5, shuffle=True, random_state=0)
for name, pipe in [("log-variance + LDA", make_pipeline(LogVar(), LDA())),
("CSP(4) + LDA", make_pipeline(CSP(4), LDA()))]:
acc = cross_val_score(pipe, X, y, cv=cv)
print(f"{name:20s} accuracy {acc.mean():.3f} +/- {acc.std():.3f}")
# Leakage: CSP fitted on all trials with random labels, then cross-validated LDA
y_rand = rng.permutation(y)
Z = CSP(4).fit(X, y_rand).transform(X)
print(f"random labels, CSP outside CV: {cross_val_score(LDA(), Z, y_rand, cv=cv).mean():.3f}")
print(f"random labels, CSP inside CV: "
f"{cross_val_score(make_pipeline(CSP(4), LDA()), X, y_rand, cv=cv).mean():.3f}")
k = binom.isf(0.05, n_tr, 0.5) + 1 # smallest k with P(Bin >= k) <= 0.05
print(f"chance level at p = 0.05 with {n_tr} trials: {k / n_tr:.3f}")Output: raw log-variances with LDA reach 61.3 %, CSP with LDA 93.8 %. With random labels, CSP fitted outside the cross-validation gives 82.5 %, pure leakage; inside, 57.5 %, below the 60 % threshold for 80 trials.
8.5 The role of feedback
A BCI is a closed loop: the user sees the decoded output and adapts to it. Controlling sensorimotor rhythms is a skill learned through feedback, so two learners interact, the user and the classifier.
Feedback changes the signals: features recorded during calibration without feedback differ from those of online use. Between 15 and 30 % of users do not reach useful control (Vidaurre and Blankertz, 2010), and standard training protocols have been criticised (Jeunet et al., 2016). Neurofeedback uses the same loop for therapy.
Proposition 8.8 — Unsupervised bias adaptation of LDA In the setting of Proposition 8.5 with balanced classes, suppose that during online use both class means shift by the same vector \delta. The Bayes rule keeps the same w, and its bias becomes b' = -w^\top \bar m', where \bar m' = \tfrac12(m_0 + m_1) + \delta is the mean of all online features, which can be estimated without labels.
Proof. The difference m_1 - m_0, hence w, is unchanged. The bias of Proposition 8.5 with the shifted means is -\frac12 w^\top (m_0 + m_1 + 2\delta) = -w^\top \bar m', and with balanced classes the overall mean of the features is \bar m'. ∎
Running averages thus track slow drifts without labels (Vidaurre et al., 2011). Adapting faster than the user learns can destabilise the loop.
Key takeaways — chapter 8
- A BCI is a closed loop; motor imagery, P300 and SSVEP are its main non-invasive paradigms, compared by their information transfer rate.
- CSP finds the spatial filters that maximise variance ratios (a generalised eigenproblem); Riemannian methods use the covariances directly.
- LDA is Bayes-optimal for Gaussian classes with a shared covariance; shrinkage makes it usable in high dimension.
- Fit every data-dependent step inside cross-validation, and compare accuracy with the binomial or permutation chance level.
- Feedback makes the user a learner: classifiers must adapt, slowly enough for the user to follow.
9. Complements: boundary elements, sparse imaging, random fields, decoding, effective connectivity
This self-study chapter completes the course chapters with six topics that the official syllabus names or implies: the surface-integral form of the forward problem and Maxwell filtering, sparse source imaging, the parametric theory of thresholds, the interpretation of decoders, M/EEG coherence under volume conduction, and directed connectivity.
9.1 Boundary elements, the Geselowitz formula and Maxwell filtering
Proposition 9.1 — Geselowitz formula for the magnetic field Let \sigma be piecewise constant, with interfaces S_j of outward normal n, conductivity \sigma_j^- inside and \sigma_j^+ outside (\sigma^+ = 0 for the scalp). Then B(r) = B_0(r) - \frac{\mu_0}{4\pi} \sum_j \big(\sigma_j^- - \sigma_j^+\big) \int_{S_j} V(r')\; n(r') \times \frac{r - r'}{|r - r'|^3}\; dS' .
Proof. By Theorem 1.7 and Proposition 0.3, the volume currents -\sigma\nabla V contribute B_v(r) = -\frac{\mu_0}{4\pi}\int \sigma\, \nabla' V \times \nabla' \frac{1}{|r - r'|}\, dr' .
Since the curl of a gradient vanishes, \nabla' V \times \nabla'\frac{1}{|r-r'|} = \nabla' \times \Big(V \nabla' \frac{1}{|r - r'|}\Big) .
On each compartment \sigma is constant, and the curl theorem reads \int_\Omega \nabla \times F = \oint_{\partial\Omega} n \times F . Each interface receives \sigma_j^- from the inside and -\sigma_j^+ from the outside, where the outward normal of the outer compartment is -n. ∎
The MEG forward problem therefore only needs V on the interfaces. Green’s representation gives, for the potential itself, a second-kind integral equation on the interfaces (Geselowitz, 1967). Discretising it on triangulated surfaces is the boundary element method; the symmetric formulation of Kybic et al. (2005), implemented in OpenMEEG (Gramfort et al., 2010), is accurate even for the thin skull compartment.
MEG: Maxwell filtering Outside the head and inside the sensor array, B = -\mu_0 \nabla U with U harmonic. Signal-space separation (Taulu and Kajola, 2005) expands U in spherical harmonics, splits the terms that decay away from the head (sources inside) from those that grow (interference outside), and keeps only the former. It suppresses external interference without any artifact template.
9.2 Sparse source imaging with mixed norms
Definition 9.2 — Mixed-norm estimate (MxNE) For data M \in \mathbb{R}^{m \times T} and sources J \in \mathbb{R}^{p \times T} with rows J_j, the mixed-norm estimate solves \min_J\ \tfrac12 \|M - G J\|_F^2 + \lambda \sum_{j=1}^p \|J_j\|_2 . The \ell_{2,1} penalty selects a few active locations (rows) and keeps their whole time course (Gramfort, Kowalski and Hämäläinen, 2012). For T = 1 it is the lasso, known in M/EEG as the minimum-current estimate (Uutela et al., 1999).
Proposition 9.3 — Block soft-thresholding and the critical \lambda
- The proximal operator of \tau \|\cdot\|_2 is \mathrm{prox}_{\tau\|\cdot\|_2}(y) = \Big(1 - \frac{\tau}{\|y\|_2}\Big)_+\, y .
- J = 0 solves Definition 9.2 if and only if \lambda \ge \lambda_{\max} = \max_j \|g_j^\top M\|_2 , where g_j is column j of G.
Proof.
- For a fixed norm t = \|x\|, the distance to y is minimal for x aligned with y. It remains to minimise over t \ge 0 \tfrac12 (t - \|y\|)^2 + \tau t, \qquad \text{which gives} \qquad t = (\|y\| - \tau)_+ .
- At J = 0 the gradient of the data term is -G^\top M, whose row j is -g_j^\top M, and the subdifferential of each row norm at 0 is the unit ball. The optimality condition 0 \in -G^\top M + \lambda\, \partial\|\cdot\|_{2,1}(0) holds if and only if every row satisfies \|g_j^\top M\|_2 \le \lambda. ∎
Proximal gradient descent alternates a gradient step on the data term with the block soft-thresholding of item 1; FISTA accelerates it to a rate of 1/k^2 in objective (Beck and Teboulle, 2009).
Code 9.4 — MxNE by FISTA recovers two sources that MNE spreads out
import numpy as np
rng = np.random.default_rng(7)
def fib_sphere(n, radius, zmin=0.0):
k = np.arange(n) + 0.5
z = 1 - k / n * (1 - zmin)
phi = np.pi * (1 + 5**0.5) * k
return radius * np.c_[np.sqrt(1 - z**2) * np.cos(phi), np.sqrt(1 - z**2) * np.sin(phi), z]
src, elec = fib_sphere(400, 0.07, 0.2), fib_sphere(60, 0.09)
ori = src / np.linalg.norm(src, axis=1, keepdims=True)
d = elec[:, None] - src[None]
G = np.einsum("ijk,jk->ij", d, ori) / (4 * np.pi * 0.33 * np.linalg.norm(d, axis=2) ** 3)
G = (np.eye(60) - 1 / 60) @ G
G /= np.linalg.norm(G, axis=0) # normalised columns
t = np.arange(100) / 500
active = [40, 250] # two sources, different time courses
J_true = np.zeros((400, 100))
J_true[active[0]] = np.sin(2 * np.pi * 10 * t)
J_true[active[1]] = np.exp(-((t - 0.1) / 0.03) ** 2)
M = G @ J_true
M += 0.1 * np.linalg.norm(M) / np.sqrt(M.size) * rng.standard_normal(M.shape)
def mxne(M, G, lam, n_iter=500):
"""FISTA for min 1/2 ||M - G J||_F^2 + lam * sum_j ||J_j.||_2."""
L = np.linalg.norm(G, 2) ** 2 # Lipschitz constant of the gradient
J = Z = np.zeros((G.shape[1], M.shape[1])); tk = 1.0
for _ in range(n_iter):
Y = Z - G.T @ (G @ Z - M) / L
norms = np.linalg.norm(Y, axis=1, keepdims=True)
J_new = np.maximum(0, 1 - lam / L / np.maximum(norms, 1e-12)) * Y # block soft-threshold
tk_new = (1 + np.sqrt(1 + 4 * tk**2)) / 2
Z = J_new + (tk - 1) / tk_new * (J_new - J)
J, tk = J_new, tk_new
return J
lam_max = np.max(np.linalg.norm(G.T @ M, axis=1)) # above it, J = 0
J = mxne(M, G, 0.3 * lam_max)
support = np.nonzero(np.linalg.norm(J, axis=1) > 1e-8)[0]
print("lambda_max =", round(lam_max, 2), "| selected sources:", support.tolist())
for k in active:
j = support[np.argmin(np.linalg.norm(src[support] - src[k], axis=1))]
print(f"true source {k}: nearest selected {j}, distance "
f"{1000 * np.linalg.norm(src[j] - src[k]):.1f} mm")
J_mne = G.T @ np.linalg.solve(G @ G.T + 0.1 * np.eye(60), M)
energy = np.linalg.norm(J_mne, axis=1) ** 2
print(f"MNE: sources holding 90% of the energy: "
f"{np.searchsorted(np.cumsum(np.sort(energy)[::-1]) / energy.sum(), 0.9) + 1}")Output: \lambda_{\max} = 7.08; at \lambda = 0.3\,\lambda_{\max}, MxNE selects exactly the two true sources, 40 and 250. The minimum-norm estimate needs 39 sources to hold 90 % of its energy.
9.3 Random field theory
Proposition 9.5 — Euler characteristic heuristic (Worsley et al., 1996) Let Z be a smooth, stationary, centred Gaussian random field of unit variance on a 3D search region of R resels (volume divided by \mathrm{FWHM}^3 for a Gaussian autocorrelation). For a high threshold u, and ignoring boundary terms, P\big(\max Z > u\big) \approx \mathbb{E}\, \chi(A_u) \approx R\, \frac{(4 \ln 2)^{3/2}}{(2\pi)^2}\, (u^2 - 1)\, e^{-u^2/2}, where \chi(A_u) is the Euler characteristic of the excursion set A_u = \{Z > u\}.
Proof. Sketch. At a high threshold the excursion set is empty or a single convex blob, so \chi(A_u) \in \{0, 1\} and its expectation approximates the probability that the maximum exceeds u. The expected Euler characteristic is computed exactly by the Kac–Rice formula, which counts critical points of Z above u weighted by the sign of the Hessian (Adler, 1981). ∎
Example 9.6 — Random field versus Bonferroni threshold A brain of 100 000 voxels of 2 mm, that is 800 cm³, smoothed with an FWHM of 9.3 mm contains about 8 \times 10^5 / 9.3^3 \approx 1000 resels.
- Solving \mathbb{E}\chi(A_u) = 0.05 gives u \approx 4.64.
- Bonferroni over the 100 000 voxels gives z = 4.89.
The gap grows with smoothness: with 100 resels the random-field threshold is 4.05. The approximation requires smoothness to be stationary and well estimated; Eklund et al. (2016) showed that cluster-level versions fail when these assumptions do not hold.
9.4 Decoding and the interpretation of linear weights
Decoding predicts the stimulus or the mental state from a distributed pattern of activity (Haxby et al., 2001), over the whole brain or in moving spheres called searchlights (Kriegeskorte, Goebel and Bandettini, 2006). Linear models with \ell_2 or sparse penalties dominate. Their accuracy must be estimated by cross-validation across runs or subjects, whose variance is large on typical sample sizes (Varoquaux et al., 2017).
Proposition 9.7 — From filters to patterns (Haufe et al., 2014) Let a linear decoder extract \hat s = W^\top x from data x \in \mathbb{R}^m of covariance \Sigma_x, with \Sigma_{\hat s} = W^\top \Sigma_x W invertible.
The forward model x = A \hat s + \varepsilon with \varepsilon uncorrelated with \hat s has A = \Sigma_x\, W\, \Sigma_{\hat s}^{-1} .
Proof. On the one hand \mathrm{Cov}(x, \hat s) = \Sigma_x W. On the other hand, since \varepsilon is uncorrelated with \hat s, \mathrm{Cov}(x, \hat s) = A\, \Sigma_{\hat s} + \mathrm{Cov}(\varepsilon, \hat s) = A\, \Sigma_{\hat s} . Solving for A gives the formula. ∎
Example 9.8 — A large weight on a channel without signal Let x_1 = s + n and x_2 = n, with s and n independent of variances \sigma_s^2 and \sigma_n^2.
- The filter w = (1, -1) recovers s exactly, with a weight of -1 on x_2, which contains no signal: it cancels the noise.
- The pattern is proportional to \Sigma_x w = \big(\sigma_s^2 + \sigma_n^2 - \sigma_n^2,\ \sigma_n^2 - \sigma_n^2\big) = (\sigma_s^2, 0), which locates the signal on channel 1 only.
Weights of decoders (or of CSP filters) are not maps of activity; patterns are.
9.5 M/EEG connectivity and volume conduction
Definition 9.9 — Coherency and phase locking For two signals with cross-spectrum S_{ij}(f), the coherency is C_{ij}(f) = S_{ij}(f)/\sqrt{S_{ii}(f) S_{jj}(f)}; the coherence is its modulus. The phase-locking value is the modulus of the average of e^{i(\phi_i - \phi_j)} over trials, where \phi_i is the instantaneous phase in a narrow band (Lachaux et al., 1999).
Proposition 9.10 — Volume conduction gives real cross-spectra (Nolte et al., 2004) If x(t) = A\, s(t) with a real, instantaneous mixing A and mutually independent stationary sources s, the cross-spectral matrix of x is real at every frequency. A non-zero imaginary part of coherency therefore cannot come from volume conduction of independent sources.
Proof. The Fourier transform commutes with the instantaneous mixing, so S_x(f) = A\, S_s(f)\, A^\top. Independence makes S_s(f) diagonal, with real auto-spectra. A product of real matrices is real. ∎
Coherence between sensors, or between sources estimated by a linear inverse (ch. 4), is inflated by the spatial spread of the fields; the imaginary part of coherency and related lagged measures are insensitive to it, at the price of missing true zero-lag interactions.
9.6 Effective connectivity: Granger causality and dynamic causal models
Definition 9.11 — Granger causality Fit a vector autoregressive model of order L to the multivariate series: x(t) = \sum_{l=1}^{L} A_l\, x(t - l) + e(t) . Series j Granger-causes series i if some coefficient (A_l)_{ij} is non-zero, that is, if the past of x_j improves the prediction of x_i given the past of all series. Geweke (1982) measures it by the log-ratio of residual variances, tested by a likelihood ratio: F_{j \to i} = \ln \frac{\sigma^2_{i \mid \text{without } j}}{\sigma^2_{i \mid \text{all}}} .
On fMRI, the haemodynamic delay varies between regions by more than the neural delays, which makes lag-based methods unreliable on BOLD signals (Smith et al., 2011). On M/EEG, Granger measures are computed per frequency and must be protected against volume conduction (section 9.5).
Definition 9.12 — Dynamic causal models (Friston, Harrison and Penny, 2003) The neural states z of a few regions follow the bilinear model \dot z = \Big(A + \sum_j u_j\, B^{(j)}\Big) z + C u , with intrinsic couplings A, modulations B^{(j)} of the couplings by the experimental inputs u_j, and driving inputs C. The states drive a haemodynamic model (Buxton et al., 1998) that predicts the BOLD signal. Parameters are estimated by variational Bayes, and competing connectivity hypotheses are compared through their model evidence.
Key takeaways — chapter 9
- The Geselowitz formula reduces the MEG forward problem to surface integrals of the potential; boundary elements solve for it on the interfaces.
- The \ell_{2,1} mixed norm selects few active locations; its proximal operator is block soft-thresholding, and J = 0 above \lambda_{\max}.
- Random field theory sets FWER thresholds from the smoothness of the map; it needs its assumptions to hold.
- Decoder weights are filters, not patterns: interpret \Sigma_x W \Sigma_{\hat s}^{-1}.
- Volume conduction cannot create an imaginary cross-spectrum; Granger causality and dynamic causal models infer directed influences under explicit models.
10. Research directions and open problems
This self-study chapter surveys active questions around the course, with entry points into the literature.
10.1 Reproducibility and the size of studies
- Analytic flexibility. Botvinik-Nezer et al. (2020) gave the same fMRI data set to 70 teams to test nine hypotheses; the teams’ conclusions differed substantially, mostly because of analysis choices. Standardised preprocessing such as fMRIPrep (Esteban et al., 2019) and the BIDS data standard (Gorgolewski et al., 2016) reduce this variability without removing it.
- Sample size. Marek et al. (2022) showed that associations between brain measures and individual traits are small and need thousands of participants to replicate. Open question: which designs and which within-subject measures give reliable individual-level biomarkers with fewer subjects?
10.2 Prediction from large cohorts
- Connectomes. Dadi et al. (2019) benchmarked pipelines that predict phenotypes from resting-state fMRI and found that tangent-space covariance embeddings (section 7.5) with linear models perform well across cohorts.
- Without source modelling. Sabbagh et al. (2019) showed that Riemannian regression on sensor covariances predicts targets from M/EEG without inverse modelling; Engemann et al. (2020) combined MEG and MRI to improve the prediction of brain age. Open question: how to transfer such models across scanners, sites and populations.
10.3 Deep learning for non-invasive signals
- Architectures. Convolutional networks designed for EEG decode motor imagery and evoked responses (Schirrmeister et al., 2017; Lawhern et al., 2018), with gains over CSP and Riemannian pipelines that depend strongly on the amount of data.
- Decoding language. Défossez et al. (2023) trained a model with a contrastive objective to identify, from a few seconds of MEG or EEG, which speech segment a participant was hearing.
- Open problems. Generalisation across subjects and sessions, self-supervised pretraining on large unlabelled recordings, and interpretation of the learned filters in the sense of Proposition 9.7.
10.4 Transfer learning and calibration-free BCIs
- Calibration sessions are tiring for patients. Re-centring each session’s covariances at their own mean before tangent-space classification aligns sessions and subjects (Zanini et al., 2018).
- The MOABB benchmark (Jayaram and Barachant, 2018) compares BCI pipelines on many public data sets. Open question: which representation of the signals transfers best between users with different anatomies and strategies?
10.5 The user in the loop
- A sizeable fraction of users fail to control a BCI (section 8.5). Corsi et al. (2020) related training performance to the functional network organisation of the brain measured with M/EEG; Jeunet et al. (2016) questioned the instructional design of standard protocols.
- Open questions: which feedback (modality, timing, adaptation rate) speeds up learning, and how to model the joint dynamics of user and classifier.
10.6 Invasive interfaces as a benchmark
- Intracortical and electrocorticographic interfaces reach far higher rates: decoding attempted handwriting (Willett et al., 2021) or speech (Moses et al., 2021) in paralysed participants, or restoring walking through a brain–spine interface (Lorach et al., 2023).
- These results set a target for non-invasive BCIs and raise questions shared by both: long-term stability, adaptation and the protection of neural data.
10.7 Further open problems
- Individual head models: estimating skull conductivity in vivo, which dominates EEG forward errors (ch. 2).
- Uncertainty quantification for source estimates, beyond point estimates such as those of ch. 4.
- Fusion of M/EEG and fMRI, which have complementary resolutions but different physiological origins.
- High-field (7 T) fMRI resolving cortical layers, which calls for new models of the BOLD response across depth.
Exercises
★ Orders of magnitude. A dipole of 20 nA·m sits in a medium of conductivity 0.33 S/m. (a) Compute the potential 3 cm away along its axis (Proposition 1.5). (b) Compute the primary magnetic field 3 cm away, perpendicular to the dipole (Proposition 1.8). (c) Compare it with the Earth’s field of 50 µT.
Solution: (a) and (b) give V = \frac{2 \times 10^{-8}}{4\pi \times 0.33 \times 0.03^2} \approx 5.4 \ \mu\text{V}, \qquad B_0 = \frac{10^{-7} \times 2 \times 10^{-8}}{0.03^2} \approx 2.2 \text{ pT}.
- The ratio is \frac{2.2 \times 10^{-12}}{5 \times 10^{-5}} \approx 4 \times 10^{-8}, which is why MEG needs a shielded room and gradiometers.
★ How many trials? A P300 of 5 µV is recorded in background EEG of standard deviation 20 µV per trial. (a) How many trials give an SNR of 2 after averaging? (b) The response is a Gaussian bump of standard deviation 50 ms and its latency jitters with a Gaussian of standard deviation 50 ms. By what factor is the averaged peak reduced, and how many trials are then needed?
Solution: (a) 5\sqrt N/20 \ge 2 gives N \ge 64 (Proposition 3.2). (b) The average is the bump convolved with the jitter density: a Gaussian of standard deviation \sqrt{50^2 + 50^2} \approx 71 ms, with the same area, so its peak is multiplied by 50/71 \approx 0.71. The condition becomes 0.71 \times 5\sqrt N / 20 \ge 2, so N \ge 128 .
★ A minimum-norm estimate by hand. Two sensors and three sources have the lead field G = \begin{pmatrix} 1 & 0 & 1 \\ 0 & 1 & 1 \end{pmatrix}, with C_N = I, R = I and \lambda = 1. (a) Give a silent source. (b) Compute W (Theorem 4.6). (c) Compute the MNE and sLORETA maps for the data (1, 1) and (1, 0), and check Theorem 4.8.
Solution: (a) G(1, 1, -1)^\top = 0. (b) GG^\top + I = \begin{pmatrix} 3 & 1 \\ 1 & 3 \end{pmatrix}, so T = \frac18 \begin{pmatrix} 3 & -1 \\ -1 & 3 \end{pmatrix} and W = G^\top T. The diagonal of WG is (3/8, 3/8, 1/2).
- For M = (1,1), the third source: \hat J = (0.25, 0.25, 0.5) and sLORETA (0.167, 0.167, 0.5). For M = (1, 0), the first source: \hat J = (0.375, -0.125, 0.25) and sLORETA (0.375, 0.042, 0.125). Both maps peak at the true source, with amplitudes shrunk by the regularisation.
★ A contrast by hand. Six scans follow a block design with centred regressor x = (1, 1, 1, -1, -1, -1) and a constant; the data are y = (3, 4, 5, 1, 2, 3). Estimate \beta, \hat\sigma^2, the t statistic of the task effect and its one-sided p-value (Theorem 5.2).
Solution: the columns are orthogonal, so \hat\beta_{\text{task}} = x^\top y / 6 = 1 and \hat\beta_0 = \bar y = 3. The residuals are (-1, 0, 1, -1, 0, 1), so \hat\sigma^2 = 4/4 = 1 with n - p = 4 degrees of freedom. The standard error is \sqrt{1/6} = 0.408, hence t = 2.45, \qquad p = 0.035 \ (t_4) .
★ Bonferroni and Benjamini–Hochberg. Ten tests give the p-values 0.0001, 0.0004, 0.0019, 0.0095, 0.020, 0.028, 0.030, 0.034, 0.046, 0.32. Which are rejected by Bonferroni at FWER 0.05 and by Benjamini–Hochberg at FDR 0.05?
Solution: Bonferroni compares with 0.005 and rejects the first three. Benjamini–Hochberg compares p_{(i)} with 0.005\, i. The largest such i is 8, since 0.034 is below 0.040 while 0.046 exceeds 0.045: it rejects the eight smallest (Theorem 6.4).
★ Partial correlations of a chain. Let X_1 = Z_1, X_2 = X_1 + Z_2, X_3 = X_2 + Z_3 with independent standard Gaussian variables Z_i. Compute the covariance and the precision matrices, then the correlation and the partial correlation of X_1 and X_3.
Solution: one checks that \Sigma K = I for \Sigma = \begin{pmatrix} 1 & 1 & 1 \\ 1 & 2 & 2 \\ 1 & 2 & 3 \end{pmatrix}, \qquad K = \begin{pmatrix} 2 & -1 & 0 \\ -1 & 2 & -1 \\ 0 & -1 & 1 \end{pmatrix} .
The correlation of X_1 and X_3 is 1/\sqrt 3 \approx 0.58, but K_{13} = 0, so their partial correlation is 0 (Theorem 7.2): the link goes through X_2. The partial correlations of the two edges are 0.5 and 1/\sqrt 2 \approx 0.71.
★ Information transfer rates. (a) Compute the ITR of a 4-target SSVEP interface with 95 % accuracy and one selection every 2 s. (b) What is the maximal ITR of a two-class BCI with one trial every 4 s? (c) Which accuracy does it need to reach 10 bits/min?
Solution: (a) B = 2 + 0.95\log_2 0.95 + 0.05\log_2(0.05/3) = 1.63 bits, that is 49 bits/min (Proposition 8.2). (b) At most 1 bit per trial, so 15 bits/min. (c) 10 bits/min means 2/3 bit per trial: 1 - H(P) \ge 2/3, with H the binary entropy, which requires P \ge 0.94 .
★★ MEG sees the tangential part. In a spherically symmetric conductor, write q = q_r \hat r_0 + q_t with q_t \perp r_0. (a) Show that the external field depends only on q_t. (b) A dipole is tilted by 30° from the radial direction. Compare its field with that of a tangential dipole of the same moment, and check with Code 1.11.
Solution: (a) B is linear in q (Proposition 1.10), and the radial part contributes nothing (Theorem 1.9, item 3), so B(q) = B(q_t). (b) |q_t| = |q| \sin 30° = |q|/2, and q_t has the direction of the tangential dipole, so the field is exactly half of it at every sensor. In Code 1.11,
q = 10e-9 * np.array([np.sin(np.pi/6), 0, np.cos(np.pi/6)])gives |B| = 78.4 fT, half of 156.9 fT.★★ Reciprocity in an infinite medium. In an infinite homogeneous conductor, a current I enters at point a and leaves at point b. (a) Give the potential U_{ab}. (b) Check Theorem 2.8 for a dipole at r_0, that is, show with Proposition 1.5 that \frac{q \cdot \nabla U_{ab}(r_0)}{I} = V_\infty(a) - V_\infty(b) .
Solution: (a) Each point source of current I produces I/(4\pi\sigma|r - a|), since the outgoing flux through a sphere is I. Hence U_{ab}(r) = \frac{I}{4\pi\sigma}\Big(\frac{1}{|r - a|} - \frac{1}{|r - b|}\Big) .
- Its gradient at r_0 is \nabla U_{ab}(r_0) = \frac{I}{4\pi\sigma}\Big(\frac{a - r_0}{|a - r_0|^3} - \frac{b - r_0}{|b - r_0|^3}\Big), and its dot product with q/I is V_\infty(a) - V_\infty(b).
★★ Correlated sources defeat the beamformer. Two sources have orthonormal topographies g_1, g_2 and power P, in white noise \sigma^2 I. Compute the LCMV output power at g_1 (Theorem 4.4) (a) for uncorrelated sources and (b) for identical time courses. Let \sigma^2 \to 0.
Solution: (a) C = P g_1 g_1^\top + P g_2 g_2^\top + \sigma^2 I, so g_1^\top C^{-1} g_1 = 1/(P + \sigma^2) and the output power is P + \sigma^2, as in Proposition 4.5.
- With u = (g_1 + g_2)/\sqrt 2, C = 2P\, u u^\top + \sigma^2 I, and Sherman–Morrison gives C^{-1} = \frac{1}{\sigma^{2}}\Big(I - \frac{2P}{\sigma^2 + 2P}\, u u^\top\Big), \qquad g_1^\top C^{-1} g_1 = \frac{\sigma^2 + P}{\sigma^2(\sigma^2 + 2P)} . The output power \frac{\sigma^2(\sigma^2 + 2P)}{\sigma^2 + P} \xrightarrow[\sigma \to 0]{} 0 vanishes: the filter uses source 2 to cancel source 1.
★★ Weighted versus unweighted group means. Three subjects give \hat\beta = (1.0, 0.8, 0.2) with first-level variances v = (0.01, 0.01, 0.25), and \tau^2 = 0.04. Compute the weighted estimate of Proposition 5.5 and its standard error, then the plain mean and its standard error under the same model.
Solution: the weights are 1/(0.05, 0.05, 0.29) = (20, 20, 3.45), of sum 43.45. The weighted mean is 36.69/43.45 = 0.84, with standard error 1/\sqrt{43.45} = 0.15. The plain mean is 0.67, with variance (0.05 + 0.05 + 0.29)/9 = 0.043, that is a standard error of 0.21. Down-weighting the noisy third subject gains precision; the summary-statistics test is exact only when the v_s are equal.
★★ Sign flipping needs symmetry (Python). For 10 subjects with one voxel each, simulate 4000 null data sets and compute the exact sign-flipping p-value of the one-sample t statistic (all 2^{10} flips, Theorem 6.2), in both tails. Compare symmetric noise (Student t_3) with centred exponential noise, of mean zero but skewed.
Solution:
import numpy as np from itertools import product rng = np.random.default_rng(8) S = 10 flips = np.array(list(product([-1, 1], repeat=S))) # all 1024 sign flips def tstat(Y): return Y.mean(-1) / (Y.std(-1, ddof=1) / np.sqrt(S)) def pvalues(x): # upper- and lower-tail p-values t0, tb = tstat(x), tstat(flips * x) return np.mean(tb >= t0), np.mean(tb <= t0) for name, draw in [("Student t(3)", lambda: rng.standard_t(3, S)), ("centred exponential", lambda: rng.exponential(1.0, S) - 1.0)]: p = np.array([pvalues(draw()) for _ in range(4000)]) print(f"{name:20s} P(p <= 0.05): upper tail {np.mean(p[:, 0] <= 0.05):.3f}, " f"lower tail {np.mean(p[:, 1] <= 0.05):.3f}")Output: with Student noise, the rejection rates at 0.05 are 0.048 (upper tail) and 0.057 (lower tail). The exact rate is 51/1024 \approx 0.050 in each tail, and the Monte Carlo standard error is about 0.0035, so both lie within about two standard errors of it. With skewed noise they are 0.016 and 0.128: flipping signs is not a symmetry of a skewed law, so the exactness of Theorem 6.2 is lost.
★★ The first edge of the graphical lasso. For two variables with S = \begin{pmatrix} 1 & r \\ r & 1 \end{pmatrix} and 0 < \lambda < |r|, solve the graphical lasso with Proposition 7.5. Show that the estimated partial correlation is the soft-thresholded correlation.
Solution: write W = \hat K^{-1}. The diagonal condition gives W_{ii} = S_{ii} = 1. In dimension 2, \hat K_{12} has the sign opposite to W_{12}, so W_{12} = r - \lambda\, \mathrm{sign}(r).
For a 2 \times 2 matrix, the partial correlation read from the precision equals the correlation of its inverse, here W_{12}, so \hat\rho_{12} = \mathrm{sign}(r)\,(|r| - \lambda), and it is 0 for \lambda \ge |r|.
★★ CSP with two channels. The class covariances are C_1 = \begin{pmatrix} 3 & 1 \\ 1 & 3 \end{pmatrix} and C_0 = \begin{pmatrix} 3 & -1 \\ -1 & 3 \end{pmatrix}. Find the CSP filters and eigenvalues (Theorem 8.4), and the class variances along each filter.
Solution: C_0 + C_1 = 6I, so the problem is the eigenproblem of C_1/6: eigenvalues 2/3 and 1/3, with eigenvectors (1, 1) and (1, -1), normalised to (1, \pm 1)/\sqrt{12}.
Along (1, 1)/\sqrt{12}, class 1 has variance 2/3 and class 0 has 1/3; along (1, -1)/\sqrt{12} the roles swap. The log-variances of the two filtered signals separate the classes.
★★ Leakage and the chance level (Python). In Code 8.7, set
n_tr = 40. For 100 random labellings, compute the cross-validated accuracy (a) with CSP fitted on all trials and (b) with CSP inside the pipeline. Compare the 95th percentile of (b) with the binomial threshold of Proposition 8.6.Hints and expected result: with CSP outside the cross-validation, the mean accuracy on random labels is about 0.88, and the 95th percentile 0.95. With CSP inside, the mean is 0.48, slightly below 0.5 as is usual for cross-validation under the null, and the 95th percentile is 0.63, below the binomial threshold of 0.65. The true labels give 0.95.
★★★ Two sources and sLORETA (Python). Using the model of Code 4.10 without noise, activate two superficial sources with the same time course and equal amplitudes. Locate the peak of the sLORETA map as a function of the distance between the sources, and explain why Theorem 4.8 does not extend.
Hints and expected result: take \lambda small (for instance 10^{-3}\, \mathrm{tr}(GG^\top)/60) and draw 300 random pairs. For sources less than 4 cm apart, the peak falls between them in 35–55 % of the pairs, depending on the draw (mean error 4–6 mm); beyond 4 cm it falls on one of them, and the weaker lobe of the other may not be a local maximum.
With data g_{k_1} + g_{k_2}, the map of Theorem 4.8 becomes s_j \propto \frac{\langle g_j, g_{k_1} + g_{k_2}\rangle_T^2}{\langle g_j, g_j\rangle_T}, maximised by the topography best aligned with the sum, which need not be a source.
★★★ A drifting BCI (Python). Simulate an LDA calibrated on 60 trials, then used online on 400 trials whose features drift slowly. Compare the static classifier with the unsupervised bias adaptation of Proposition 8.8, using a running mean with forgetting factor 0.05. Then discuss how a learning user, whose class separation grows with feedback, interacts with the adaptation rate.
Solution:
import numpy as np rng = np.random.default_rng(9) d, n_cal, n_on = 4, 60, 400 m0, m1 = np.zeros(d), np.r_[1.2, 0.6, 0, 0] cov = np.eye(d) def draw(n, shift): y = rng.integers(0, 2, n) X = np.where(y[:, None] == 1, m1, m0) + rng.standard_normal((n, d)) + shift return X, y Xc, yc = draw(n_cal, 0.0) mu0, mu1 = Xc[yc == 0].mean(0), Xc[yc == 1].mean(0) S = np.cov(np.vstack([Xc[yc == 0] - mu0, Xc[yc == 1] - mu1]).T) w = np.linalg.solve(S, mu1 - mu0); b = -w @ (mu0 + mu1) / 2 acc = {"static": [], "bias-adapted": []} mbar, eta = (mu0 + mu1) / 2, 0.05 for t in range(n_on): shift = np.r_[3.0, -2.0, 1.0, 0.0] * t / n_on # slow global drift x, y = draw(1, shift); x, y = x[0], y[0] acc["static"].append(((w @ x + b) > 0) == y) acc["bias-adapted"].append(((w @ x - w @ mbar) > 0) == y) mbar = (1 - eta) * mbar + eta * x # unsupervised running mean for k, v in acc.items(): v = np.array(v); print(k, "first 100 trials %.3f, last 100 trials %.3f" % (v[:100].mean(), v[-100:].mean()))Output: over the first 100 online trials, the two classifiers reach 0.73 and 0.74; over the last 100, the static one falls to 0.64 while the adapted one keeps 0.72, close to the Bayes accuracy \Phi(\Delta/2) \approx 0.75, where \Delta = \|m_1 - m_0\| \approx 1.34 is the distance between the class means (identity covariance). If the user learns, the class means move apart: a fast adaptation of the bias follows the drift but also follows short-term fluctuations, while re-estimating w requires labels or a model of the user. The adaptation rate trades tracking for stability.
★★★ Filters versus patterns (Python). For the CSP filters fitted in Code 8.7, compute the patterns of Proposition 9.7, using the average trial covariance as \Sigma_x. Compare filters and patterns with the true mixing columns
A[:, 0]andA[:, 1]of the two sources that carry the class information.Hints and expected result: with W the four CSP filters, the patterns are \Sigma_x W (W^\top \Sigma_x W)^{-1}. The best absolute cosine between a pattern and each true mixing column is about 0.97–0.98, while the best cosine for the filters themselves is about 0.5. Filters cancel the other sources and the noise; patterns show where the discriminative sources project, which is what a physiological interpretation needs.
Projects and assessment
The official assessment is two TDs (travaux dirigés, guided exercise work: “L’évaluation du cours est constituée de 2 TD”, master-mva.com); the resit is a critical commentary of a research paper, and the Université Paris-Saclay course detail gives “Evaluation Continue non Intégrale”. No weighting is displayed.
Everything below is a proposal. Each solo subject is sized like one graded TD; the group subjects suit a team TD or a final project. Most subjects study a named paper, which also trains the resit exercise: a commentary that states the question, the method, the evidence, the limits and what would be needed to reproduce it.
Solo projects
- [Solo · ≈ 20 h] When is sLORETA unbiased? A paper study of Pascual-Marqui (2002). The question: how far does the zero-localisation-error property of Theorem 4.8 survive noise, depth and several sources?
- Implement: MNE, dSPM and sLORETA from scratch, checked against MNE-Python (Gramfort et al., 2013), on a three-shell spherical EEG model and a volume source space built with MNE-Python, so that no download is needed.
- Probe: localisation error and spatial dispersion (Definition 4.9) as functions of SNR, depth, \lambda and the number of simultaneous sources (Exercise 16).
- Deliverables: code, a 4–6 page report, a 10-minute talk. Chapters: ch. 1, 2, 4.
- Success: zero error for single noise-free sources reproduced to machine precision; error curves with 95 % intervals over at least 200 simulated sources per condition.
- [Solo · ≈ 20 h] Riemannian geometry against CSP for motor imagery. A paper study of Barachant, Bonnet, Congedo and Jutten (2012). Does the minimum distance to the Riemannian mean match or beat CSP with LDA, within and across sessions?
- Data: BCI Competition IV data set 2a (Brunner et al., 2008; 9 subjects, 4 motor-imagery classes, 22 EEG channels, 2 sessions), available through MOABB (Jayaram and Barachant, 2018).
- Implement: CSP + LDA (Code 8.7), the geometric mean by fixed-point iteration, MDM and tangent space + logistic regression (Definition 7.7); compare with pyRiemann.
- Deliverables: code, a 4–6 page report, a 10-minute talk. Chapters: ch. 7, 8.
- Success: per-subject accuracies within session (nested cross-validation) and across sessions, with permutation chance levels and a paired test across subjects.
- [Solo · ≈ 15 h] Cluster failure at small scale. A paper study of Eklund, Nichols and Knutsson (2016). Do parametric and permutation inference control the familywise error on real null data?
- Data: the development fMRI data set of Richardson et al. (2018), available through Nilearn (Abraham et al., 2014), analysed with a fake block design whose phase is drawn at random for each subject, so that no effect of the movie is shared across subjects.
- Implement: first-level GLMs (Code 5.6), random groups of 20 subjects, then voxelwise random-field thresholds (section 9.3), sign-flipping maximum statistic and cluster inference at two cluster-forming thresholds.
- Deliverables: code, a 4-page report, a 10-minute talk. Chapters: ch. 5, 6, 9.
- Success: estimated FWER of each method over at least 200 random groups, with binomial confidence intervals, and a reasoned comparison with the paper’s findings.
Group projects
- [Group of 3 · ≈ 30 h each] From raw MEG/EEG to validated source estimates. On the MNE-Python “sample” data set (auditory and visual stimuli; Gramfort et al., 2013), how consistent are the inverse methods of ch. 4, and how much does each preprocessing step matter?
- Implement: filtering, SSP or ICA against ocular and cardiac artifacts (ch. 3), epoching and averaging; a BEM forward model from the provided surfaces; shrunk noise covariance; MNE, dSPM, sLORETA, LCMV and a dipole fit of the auditory response.
- Split: preprocessing and denoising; forward and inverse models; validation by resolution matrices and simulations.
- Deliverables: repository, an 8–10 page report, a 15-minute defence. Chapters: ch. 1–4, 9.
- Success: auditory responses in the superior temporal cortex and visual responses in the occipital cortex for each method, with simulation-based error bars and the effect of removing each preprocessing step.
- [Group of 3 · ≈ 30 h each] Connectome-based prediction: children against adults. A paper study of Dadi et al. (2019). Which connectivity estimator predicts age group best from fMRI time series?
- Data: the development fMRI data set (Richardson et al., 2018; 155 participants, 122 children and 33 adults), through Nilearn.
- Implement: region time series with two atlases; correlation, partial correlation with Ledoit–Wolf and the graphical lasso, tangent space at the geometric mean (ch. 7); linear classifiers; nested cross-validation; permutation test of the accuracy.
- Split: time series and confounds; estimators and tangent space; evaluation and statistics.
- Deliverables: repository, an 8-page report, a 15-minute defence. Chapters: ch. 6, 7, 9.
- Success: balanced accuracy with confidence intervals for each pipeline, and a test of the paper’s conclusion that tangent-space embeddings perform best.
- [Group of 2–3 · ≈ 30 h each] Group inference and reproducibility on the Localizer data. How do detection and reproducibility depend on the group model, the correction and the number of subjects?
- Data: contrast and t maps of the Brainomics/Localizer data set (Pinel et al., 2007; Papadopoulos Orfanos et al., 2017), available through Nilearn; first-level variances follow from (\text{effect}/t)^2.
- Implement: summary-statistics and mixed-effects group models (Proposition 5.5), sign-flipping maximum statistic, cluster inference and Benjamini–Hochberg (ch. 6); a subsampling study from 10 to 90 subjects, in the spirit of Thirion et al. (2007).
- Split: group models; inference; reproducibility study.
- Deliverables: repository, an 8-page report, a 15-minute defence. Chapters: ch. 5, 6.
- Success: detection counts per method, a check of FWER on sign-randomised nulls, and Dice overlap of thresholded maps between disjoint subgroups as a function of group size.
Written exam (proposal)
Two hours, one handwritten A4 sheet and a calculator allowed; four questions, 20 points.
Question (5 points). (a) State the quasistatic equation for the potential and justify the two approximations with orders of magnitude. (b) Prove that a radial dipole in a spherically symmetric conductor produces no magnetic field outside it; you may admit that volume currents do not contribute to the radial component of B.
Expected:
- \nabla\cdot(\sigma\nabla V) = \nabla \cdot J^p, from \nabla \times E = 0 and \nabla \cdot J = 0; \omega\varepsilon/\sigma \approx 10^{-3} and a skin depth of tens of metres below 1 kHz (2 pts).
- When q \parallel r_0 (3 pts), r \cdot B = r \cdot B_0 = -\frac{\mu_0}{4\pi}\, \frac{r \cdot (q \times r_0)}{|r - r_0|^3} = 0 ; outside, B = -\mu_0 \nabla U and U is the integral of the radial component along rays, so U = 0 and B = 0.
Question (5 points). Two sensors and three sources have G = \begin{pmatrix} 2 & 1 & 0 \\ 0 & 1 & 2 \end{pmatrix}, with C_N = I. The data are M = (1, 1). (a) Compute the MNE with R = I and \lambda = 1. (b) Compute the sLORETA map. (c) With the data covariance C = g_2 g_2^\top + I, compute the LCMV output power and the neural activity index at each source.
Expected:
- The inverse operator uses (1.5 pts) T = \frac{1}{35}\begin{pmatrix} 6 & -1 \\ -1 & 6 \end{pmatrix}, \qquad \hat J = (2/7, 2/7, 2/7): MNE cannot choose, because source 2 has the smallest topography.
- (WG)_{jj} = (24/35, 10/35, 24/35), so sLORETA gives (0.12, 0.29, 0.12) and peaks at source 2 (1.5 pts).
- With (2 pts) C^{-1} = \frac13 \begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix}, the output powers are (0.375, 1.5, 0.375), where 1.5 = 1 + 1/\|g_2\|^2 (Proposition 4.5); the neural activity index is (1.5, 3, 1.5).
Question (5 points). (a) Explain the difference between fixed-effects and random-effects group analyses and when the one-sample t test on subject estimates is exact. (b) Ten voxels have p-values 0.00002, 0.0003, 0.0012, 0.004, 0.006, 0.011, 0.04, 0.09, 0.3, 0.7: which are rejected by Bonferroni (FWER 0.05) and by Benjamini–Hochberg (FDR 0.05)? (c) Prove that Bonferroni controls the FWER, and say why the maximum statistic is less conservative on a smooth map.
Expected:
- Fixed effects ignore \tau^2 and concern the subjects scanned; random effects use v_s + \tau^2 and concern the population; exact with equal first-level variances (Proposition 5.5) (1.5 pts).
- Bonferroni (threshold 0.005): the first four. BH: the largest i with p_{(i)} \le 0.005\, i is 6 (0.011 \le 0.030, while 0.04 > 0.035): the first six (2 pts).
- Union bound over the true nulls (Proposition 6.3); correlated tests have a maximum whose null quantile is below the Bonferroni threshold (1.5 pts).
Question (5 points). (a) Show that CSP filters solve a generalised eigenproblem. (b) Give the filters and eigenvalues for C_1 = \mathrm{diag}(4, 1) and C_0 = \mathrm{diag}(1, 4). (c) A two-class BCI reaches 70 % on 50 test trials, one trial every 5 s. Is it above chance at the 5 % level, and what is its information transfer rate?
Expected:
- The variance ratio is a generalised Rayleigh quotient; its stationary points satisfy C_1 w = \mu (C_0 + C_1) w (Theorem 8.4, Proposition 0.6) (2 pts).
- C_0 + C_1 = 5I: filters e_1 and e_2 (normalised by 1/\sqrt 5), with eigenvalues 0.8 and 0.2 (1 pt).
- The binomial threshold for 50 trials is 32 correct (64 %), so 35 correct is significant. B = 1 + 0.7\log_2 0.7 + 0.3 \log_2 0.3 = 0.12 bit per trial, that is 1.4 bits/min (2 pts).
Grading rubric (proposal)
| Criterion | Weight | What earns the marks |
|---|---|---|
| Question and baselines | 15 % | One precise question; simple baselines first (MNE before sparse priors, correlation before tangent space, log-variance before CSP) |
| Correctness | 20 % | Forward models, derivations and code right; units and orders of magnitude checked; known identities (reciprocity, Theorem 4.8) used as unit tests |
| Validation and statistics | 25 % | Simulations with ground truth; leakage-free nested cross-validation; permutation or binomial chance levels; the error rate of every map stated and controlled |
| Analysis and interpretation | 20 % | Patterns rather than weights; physiological plausibility; failure cases and negative results reported; the link to a result of the course |
| Reproducibility | 10 % | One command reruns everything; seeds, versions and data sources recorded; public data only |
| Communication | 10 % | Clear report and talk within the limits; figures readable on a projector; for the resit, a commentary that separates the paper’s claims from its evidence |
References
Official references (master-mva.com)
- The course handout (“Le polycopié du cours”), distributed by the instructors.
- R. A. Poldrack, J. A. Mumford, T. E. Nichols, Handbook of Functional MRI Data Analysis, Cambridge University Press, 2011.
- R. Brette, A. Destexhe (eds.), Handbook of Neural Activity Measurement, Cambridge University Press, 2012.
Textbooks
- P. L. Nunez, R. Srinivasan, Electric Fields of the Brain: The Neurophysics of EEG, 2nd ed., Oxford University Press, 2006.
- A. Ern, J.-L. Guermond, Theory and Practice of Finite Elements, Springer, 2004.
- A. Hyvärinen, J. Karhunen, E. Oja, Independent Component Analysis, Wiley, 2001.
- P. H. Westfall, S. S. Young, Resampling-Based Multiple Testing, Wiley, 1993.
- R. J. Adler, The Geometry of Random Fields, Wiley, 1981.
- J. R. Wolpaw, E. W. Wolpaw (eds.), Brain–Computer Interfaces: Principles and Practice, Oxford University Press, 2012.
- M. Clerc, L. Bougrain, F. Lotte (eds.), Brain–Computer Interfaces 1 and 2, ISTE–Wiley, 2016.
Physics, forward and inverse problems (ch. 1–4, 9)
- H. von Helmholtz, “Ueber einige Gesetze der Vertheilung elektrischer Ströme in körperlichen Leitern mit Anwendung auf die thierisch-elektrischen Versuche”, Annalen der Physik und Chemie, 1853.
- D. B. Geselowitz, “On bioelectric potentials in an inhomogeneous volume conductor”, Biophysical Journal 7, 1967.
- J. Sarvas, “Basic mathematical and electromagnetic concepts of the biomagnetic inverse problem”, Physics in Medicine and Biology 32, 1987.
- M. Hämäläinen, R. Hari, R. J. Ilmoniemi, J. Knuutila, O. V. Lounasmaa, “Magnetoencephalography — theory, instrumentation, and applications to noninvasive studies of the working human brain”, Reviews of Modern Physics 65, 1993.
- J. C. Mosher, R. M. Leahy, P. S. Lewis, “EEG and MEG: forward solutions for inverse methods”, IEEE Transactions on Biomedical Engineering 46, 1999.
- J. Kybic, M. Clerc, T. Abboud, O. Faugeras, R. Keriven, T. Papadopoulo, “A common formalism for the integral formulations of the forward EEG problem”, IEEE Transactions on Medical Imaging 24, 2005.
- A. Gramfort, T. Papadopoulo, E. Olivi, M. Clerc, “OpenMEEG: opensource software for quasistatic bioelectromagnetics”, BioMedical Engineering OnLine 9, 2010.
- M. A. Uusitalo, R. J. Ilmoniemi, “Signal-space projection method for separating MEG or EEG into components”, Medical and Biological Engineering and Computing 35, 1997.
- S. Taulu, M. Kajola, “Presentation of electromagnetic multichannel data: the signal space separation method”, Journal of Applied Physics 97, 2005.
- P. Comon, “Independent component analysis, a new concept?”, Signal Processing 36, 1994.
- N. Delfosse, P. Loubaton, “Adaptive blind separation of independent sources: a deflation approach”, Signal Processing 45, 1995.
- A. Hyvärinen, E. Oja, “Independent component analysis: algorithms and applications”, Neural Networks 13, 2000.
- R. O. Schmidt, “Multiple emitter location and signal parameter estimation”, IEEE Transactions on Antennas and Propagation 34, 1986.
- J. C. Mosher, P. S. Lewis, R. M. Leahy, “Multiple dipole modeling and localization from spatio-temporal MEG data”, IEEE Transactions on Biomedical Engineering 39, 1992.
- J. C. Mosher, R. M. Leahy, “Source localization using recursively applied and projected (RAP) MUSIC”, IEEE Transactions on Signal Processing 47, 1999.
- B. D. Van Veen, W. van Drongelen, M. Yuchtman, A. Suzuki, “Localization of brain electrical activity via linearly constrained minimum variance spatial filtering”, IEEE Transactions on Biomedical Engineering 44, 1997.
- M. S. Hämäläinen, R. J. Ilmoniemi, “Interpreting magnetic fields of the brain: minimum norm estimates”, Medical and Biological Engineering and Computing 32, 1994.
- A. M. Dale et al., “Dynamic statistical parametric mapping: combining fMRI and MEG for high-resolution imaging of cortical activity”, Neuron 26, 2000.
- R. D. Pascual-Marqui, “Standardized low-resolution brain electromagnetic tomography (sLORETA): technical details”, Methods and Findings in Experimental and Clinical Pharmacology 24 (Suppl. D), 2002.
- K. Uutela, M. Hämäläinen, E. Somersalo, “Visualization of magnetoencephalographic data using minimum current estimates”, NeuroImage 10, 1999.
- A. Gramfort, M. Kowalski, M. Hämäläinen, “Mixed-norm estimates for the M/EEG inverse problem using accelerated gradient methods”, Physics in Medicine and Biology 57, 2012.
- A. Beck, M. Teboulle, “A fast iterative shrinkage-thresholding algorithm for linear inverse problems”, SIAM Journal on Imaging Sciences 2, 2009.
- A. Gramfort et al., “MEG and EEG data analysis with MNE-Python”, Frontiers in Neuroscience 7, 2013.
fMRI and statistics (ch. 5–6, 9)
- S. Ogawa, T. M. Lee, A. R. Kay, D. W. Tank, “Brain magnetic resonance imaging with contrast dependent on blood oxygenation”, PNAS 87, 1990.
- N. K. Logothetis, J. Pauls, M. Augath, T. Trinath, A. Oeltermann, “Neurophysiological investigation of the basis of the fMRI signal”, Nature 412, 2001.
- R. B. Buxton, E. C. Wong, L. R. Frank, “Dynamics of blood flow and oxygenation changes during brain activation: the balloon model”, Magnetic Resonance in Medicine 39, 1998.
- K. J. Friston et al., “Statistical parametric maps in functional imaging: a general linear approach”, Human Brain Mapping 2, 1994.
- A. P. Holmes, K. J. Friston, “Generalisability, random effects and population inference”, NeuroImage 7 (S754), 1998.
- B. Thirion et al., “Analysis of a large fMRI cohort: statistical and methodological issues for group analyses”, NeuroImage 35, 2007.
- T. E. Nichols, A. P. Holmes, “Nonparametric permutation tests for functional neuroimaging: a primer with examples”, Human Brain Mapping 15, 2002.
- Y. Benjamini, Y. Hochberg, “Controlling the false discovery rate: a practical and powerful approach to multiple testing”, Journal of the Royal Statistical Society B 57, 1995.
- Y. Benjamini, D. Yekutieli, “The control of the false discovery rate in multiple testing under dependency”, Annals of Statistics 29, 2001.
- K. J. Worsley et al., “A unified statistical approach for determining significant signals in images of cerebral activation”, Human Brain Mapping 4, 1996.
- S. M. Smith, T. E. Nichols, “Threshold-free cluster enhancement: addressing problems of smoothing, threshold dependence and localisation in cluster inference”, NeuroImage 44, 2009.
- E. Maris, R. Oostenveld, “Nonparametric statistical testing of EEG- and MEG-data”, Journal of Neuroscience Methods 164, 2007.
- C. M. Bennett, A. A. Baird, M. B. Miller, G. L. Wolford, “Neural correlates of interspecies perspective taking in the post-mortem Atlantic salmon: an argument for proper multiple comparisons correction”, Journal of Serendipitous and Unexpected Results 1, 2010.
- A. Eklund, T. E. Nichols, H. Knutsson, “Cluster failure: why fMRI inferences for spatial extent have inflated false-positive rates”, PNAS 113, 2016.
- J. V. Haxby et al., “Distributed and overlapping representations of faces and objects in ventral temporal cortex”, Science 293, 2001.
- N. Kriegeskorte, R. Goebel, P. Bandettini, “Information-based functional brain mapping”, PNAS 103, 2006.
- S. Haufe et al., “On the interpretation of weight vectors of linear models in multivariate neuroimaging”, NeuroImage 87, 2014.
- G. Varoquaux et al., “Assessing and tuning brain decoders: cross-validation, caveats, and guidelines”, NeuroImage 145, 2017.
Connectivity (ch. 7, 9)
- O. Ledoit, M. Wolf, “A well-conditioned estimator for large-dimensional covariance matrices”, Journal of Multivariate Analysis 88, 2004.
- J. Friedman, T. Hastie, R. Tibshirani, “Sparse inverse covariance estimation with the graphical lasso”, Biostatistics 9, 2008.
- G. Varoquaux, A. Gramfort, J.-B. Poline, B. Thirion, “Brain covariance selection: better individual functional connectivity models using population prior”, NeurIPS, 2010.
- S. M. Smith et al., “Network modelling methods for FMRI”, NeuroImage 54, 2011.
- K. Dadi et al., “Benchmarking functional connectome-based predictive models for resting-state fMRI”, NeuroImage 192, 2019.
- J.-P. Lachaux, E. Rodriguez, J. Martinerie, F. J. Varela, “Measuring phase synchrony in brain signals”, Human Brain Mapping 8, 1999.
- G. Nolte et al., “Identifying true brain interaction from EEG data using the imaginary part of coherency”, Clinical Neurophysiology 115, 2004.
- J. Geweke, “Measurement of linear dependence and feedback between multiple time series”, Journal of the American Statistical Association 77, 1982.
- K. J. Friston, L. Harrison, W. Penny, “Dynamic causal modelling”, NeuroImage 19, 2003.
Brain–computer interfaces (ch. 8)
- L. A. Farwell, E. Donchin, “Talking off the top of your head: toward a mental prosthesis utilizing event-related brain potentials”, Electroencephalography and Clinical Neurophysiology 70, 1988.
- G. Pfurtscheller, F. H. Lopes da Silva, “Event-related EEG/MEG synchronization and desynchronization: basic principles”, Clinical Neurophysiology 110, 1999.
- H. Ramoser, J. Müller-Gerking, G. Pfurtscheller, “Optimal spatial filtering of single trial EEG during imagined hand movement”, IEEE Transactions on Rehabilitation Engineering 8, 2000.
- J. R. Wolpaw, N. Birbaumer, D. J. McFarland, G. Pfurtscheller, T. M. Vaughan, “Brain–computer interfaces for communication and control”, Clinical Neurophysiology 113, 2002.
- C. Brunner, R. Leeb, G. R. Müller-Putz, A. Schlögl, G. Pfurtscheller, “BCI Competition 2008 — Graz data set A”, Graz University of Technology, 2008.
- C. Vidaurre, B. Blankertz, “Towards a cure for BCI illiteracy”, Brain Topography 23, 2010.
- B. Blankertz, S. Lemm, M. Treder, S. Haufe, K.-R. Müller, “Single-trial analysis and classification of ERP components — a tutorial”, NeuroImage 56, 2011.
- C. Vidaurre, M. Kawanabe, P. von Bünau, B. Blankertz, K.-R. Müller, “Toward unsupervised adaptation of LDA for brain–computer interfaces”, IEEE Transactions on Biomedical Engineering 58, 2011.
- A. Barachant, S. Bonnet, M. Congedo, C. Jutten, “Multiclass brain–computer interface classification by Riemannian geometry”, IEEE Transactions on Biomedical Engineering 59, 2012.
- E. Combrisson, K. Jerbi, “Exceeding chance level by chance: the caveat of theoretical chance levels in brain signal classification and statistical assessment of decoding accuracy”, Journal of Neuroscience Methods 250, 2015.
- C. Jeunet, E. Jahanpour, F. Lotte, “Why standard brain–computer interface (BCI) training protocols should be changed: an experimental study”, Journal of Neural Engineering 13, 2016.
- F. Lotte et al., “A review of classification algorithms for EEG-based brain–computer interfaces: a 10 year update”, Journal of Neural Engineering 15, 2018.
- V. Jayaram, A. Barachant, “MOABB: trustworthy algorithm benchmarking for BCIs”, Journal of Neural Engineering 15, 2018.
Data sets and research directions (projects, ch. 10)
- A. Abraham et al., “Machine learning for neuroimaging with scikit-learn”, Frontiers in Neuroinformatics 8, 2014.
- P. Pinel et al., “Fast reproducible identification and large-scale databasing of individual functional cognitive networks”, BMC Neuroscience 8, 2007.
- D. Papadopoulos Orfanos et al., “The Brainomics/Localizer database”, NeuroImage 144, 2017.
- H. Richardson, G. Lisandrelli, A. Riobueno-Naylor, R. Saxe, “Development of the social brain from age three to twelve years”, Nature Communications 9, 2018.
- K. J. Gorgolewski et al., “The brain imaging data structure, a format for organizing and describing outputs of neuroimaging experiments”, Scientific Data 3, 2016.
- O. Esteban et al., “fMRIPrep: a robust preprocessing pipeline for functional MRI”, Nature Methods 16, 2019.
- R. Botvinik-Nezer et al., “Variability in the analysis of a single neuroimaging dataset by many teams”, Nature 582, 2020.
- S. Marek et al., “Reproducible brain-wide association studies require thousands of individuals”, Nature 603, 2022.
- D. Sabbagh, P. Ablin, G. Varoquaux, A. Gramfort, D. A. Engemann, “Manifold-regression to predict from MEG/EEG brain signals without source modeling”, NeurIPS, 2019.
- D. A. Engemann et al., “Combining magnetoencephalography with magnetic resonance imaging enhances learning of surrogate-biomarkers”, eLife 9, 2020.
- R. T. Schirrmeister et al., “Deep learning with convolutional neural networks for EEG decoding and visualization”, Human Brain Mapping 38, 2017.
- V. J. Lawhern et al., “EEGNet: a compact convolutional neural network for EEG-based brain–computer interfaces”, Journal of Neural Engineering 15, 2018.
- A. Défossez, C. Caucheteux, J. Rapin, O. Kabeli, J.-R. King, “Decoding speech perception from non-invasive brain recordings”, Nature Machine Intelligence 5, 2023.
- P. Zanini, M. Congedo, C. Jutten, S. Said, Y. Berthoumieu, “Transfer learning: a Riemannian geometry framework with applications to brain–computer interfaces”, IEEE Transactions on Biomedical Engineering 65, 2018.
- M.-C. Corsi et al., “Functional disconnection of associative cortical areas predicts performance during BCI training”, NeuroImage 209, 2020.
- F. R. Willett, D. T. Avansino, L. R. Hochberg, J. M. Henderson, K. V. Shenoy, “High-performance brain-to-text communication via handwriting”, Nature 593, 2021.
- D. A. Moses et al., “Neuroprosthesis for decoding speech in a paralyzed person with anarthria”, New England Journal of Medicine 385, 2021.
- H. Lorach et al., “Walking naturally after spinal cord injury using a brain–spine interface”, Nature 618, 2023.