‹ All demos
23 Nov 2026 · Medicine

Finding where a seizure starts by how brain signals switch, not just how loud they get

Before epilepsy surgery, doctors often put thin needle electrodes deep into the brain (stereo-EEG, or SEEG) and wait for a seizure. They then have to work out which of a hundred or more recording sites belong to the epileptogenic zone, the patch of brain that starts the seizures and has to be removed. This paper models each channel as a hidden Markov chain moving between a few brain "states". It flags the channels whose pattern of switching between states changes most at seizure onset. Below, the whole method (constrained Baum–Welch, both KL scores and the single-state benchmark) runs live on simulated SEEG recordings.

Giulia Tacconi, Federico Mason, Lorenzo Ferri, Elena Pasini, Lidia Di Vito, Matteo Martinoni, Lara Alvisi, Anna Scarabello, Luca Zanuttini, Francesca Bisulli, Andrea Zanella

Why it matters

For about a third of people with epilepsy, medicines don't stop the seizures, and surgery can cure them only if doctors remove the right patch of brain, which today they find mostly by reading hundreds of SEEG traces by eye. Across 30 patients, scoring how each channel's switching between hidden states changes at seizure onset picked out the surgeons' target channels with a mean AUROC of about 0.8, versus 0.53–0.65 for a comparable method that ignored the order of states.

The paper

Transition Dynamics Matter: Hidden Markov Scoring of Epileptogenic Channels in SEEG

Giulia Tacconi, Federico Mason, Lorenzo Ferri, Elena Pasini, Lidia Di Vito, Matteo Martinoni, Lara Alvisi, Anna Scarabello, Luca Zanuttini, Francesca Bisulli and Andrea Zanella (Department of Information Engineering, University of Padova; Institut de Neurosciences des Systèmes, Aix-Marseille University; IRCCS Institute of Neurological Sciences of Bologna; Department of Neuromotor and Biomedical Sciences, University of Bologna). arXiv:2611.26142 [eess.SP], submitted 19 November 2026; submitted to IEEE ICC 2027. Read on arXiv · PDF

In plain language: each SEEG channel is cut into 1-second windows (shifted by 0.25 s). Each window becomes a feature vector oi[w]: the energy, phase entropy and connectivity strength in seven frequency bands. The authors assume every channel moves through the same small set of hidden states, each producing features from its own Gaussian. What differs between channels is how often they jump from one state to another, captured by a transition matrix Ai. Baum–Welch is first run on all channels together to learn the shared Gaussians. It is then rerun on each channel alone, with the Gaussians held fixed, to learn a baseline matrix Aibase from the interictal period (between seizures). The same step on windows after onset gives the ictal (seizure) matrices Ai,wictal, using either a cumulative window (from onset up to w) or a sliding window (w − L … w + L).

A channel's change is measured in two ways. Transition KL (paper Eq. 8) compares the rows of the two matrices, weighted by how often the channel sat in each state at baseline (the stationary distribution πbase):

Ditr(w) = Σz πibase(z) Σq Ai,wictal(z,q) log [ Ai,wictal(z,q) / Aibase(z,q) ]

Occupancy KL (Eq. 9) compares only the long-run share of time spent in each state:

Diocc(w) = Σz πi,wictal(z) log [ πi,wictal(z) / πibase(z) ],    Di = Σw ≥ w* Di(w)

The higher Di, the more likely channel i is in the epileptogenic zone. The benchmark is the same model with a single state (Z = 1): each channel is just one Gaussian, so the order in which windows occur is ignored.

Try it: find the seizure-onset channels

The demo makes 16 simulated channels, each 200 s long: 170 s of baseline and then 30 s of seizure, in windows every 0.25 s (W = 797, onset at w* = 680, as in the paper). There are three hidden states, normal, busy and critical, and each window yields one feature (log high-frequency energy). That feature is Gaussian with means 0, 1.5 and 3 and the spread σ you set. At onset, the epileptogenic channels switch to a new transition matrix Aictal = (1−s)Abase + s[mAflicker + (1−m)Acrit]. Acrit makes them sit in the critical state. Aflicker = 1πbase has the same long-run state shares as baseline but no memory, so the channel flickers between states. "Spread" gives some healthy channels a weaker critical shift, like a seizure spreading to them. The demo then estimates everything blind with the paper's constrained Baum–Welch, holding the shared Gaussians fixed (we skip stage 1 and use the true ones).

Score:
Ictal window: Patient:
AUROC, hidden Markov score
AUROC, single-Gaussian benchmark
Best F1, hidden Markov score
Epileptogenic channels in the top k

Decoded hidden state per channel (Viterbi), last 60 s; red labels = epileptogenic zone
normalbusycriticaldashed: seizure onset
Abnormality score Di(w) after onset
epileptogenichealthy
ROC: epileptogenic vs healthy channels
hidden Markov score Disingle-Gaussian benchmark
Total score Di per channel, ranked
epileptogenichealthy
Estimated transition matrices, top channel
Abase (interictal)
Aictal (cumulative, whole seizure)

What the paper found

Limits the authors note: the Gaussians assume features are independent within a state, even though features from the same band are correlated. Only one seizure per patient and the first 30 s of the seizure were used, so channels recruited later can be missed. Thermocoagulated channels are only a stand-in for the true epileptogenic zone.

How to use it

Demo maths: 3-state HMM with 1-D Gaussian emissions shared by all channels and held fixed. Channel-specific transition matrices come from scaled forward–backward Baum–Welch (baseline: 20 iterations on windows 0…679; ictal: 6 iterations warm-started from Abase, with a 0.5 pseudo-count per transition so logs stay finite). Stationary distributions are found by power iteration. The benchmark is KL(𝒩ictal ‖ 𝒩base) between per-channel Gaussians fitted on the same windows (our reading of the Z = 1 case). AUROC uses the Mann–Whitney rank formula. All numbers in the stats come from the simulation, not the paper.