Quickest-Onset Seizure Alarms with a Learned Transition State

A seizure does not switch on instantly. For several seconds the brain's electrical activity drifts away from its normal background before the full seizure pattern appears. That drifting stretch is exactly where an alarm would need to fire to be clinically useful, and it is where today's detectors do worst. There are three reasons. The stretch is ambiguous, because it looks partly like both states. It is extremely rare, because it is a few seconds out of recordings that run for days. And any method that steadies the detector's jittery output, such as buffering, smoothing, or offline clustering, adds delay. We propose treating seizure-onset detection as a quickest change detection problem: raise an alarm as soon as possible after a change in the signal, subject to a fixed false-alarm rate. A small raw-waveform network is trained on class-balanced data to recognize three states: background, transition, and seizure. Its outputs are then passed through a causal three-state filter. The filter divides out the artificial training balance and puts back the true, tiny rate at which seizures begin.

The core claim is that class imbalance and output flickering are best handled at decision time rather than inside the loss function. The network is trained on balanced batches so that the rare transition windows get enough gradient. The real-world rarity of onsets then enters only as one interpretable number in the filter: the per-second probability that a seizure starts. Because the filter is forward-only, it suppresses flickering without the lookahead of Viterbi decoding or the fixed multi-second buffer of accumulation rules. We expect this design to shorten the time to alarm at a matched false-alarm rate, at a per-step cost of a few dozen arithmetic operations on top of a CPU-friendly 1D convolutional network.

Where This Sits

Transitional ambiguity is the core mechanism, latency is the hard constraint, and imbalance is the training obstacle.

The closest prior work is the probabilistic seizure detector of Xu et al. (Shorter latency of real-time epileptic seizure detection via probabilistic prediction; Deep Learning for Short-Latency Epileptic Seizure Detection with Probabilistic Classification). It defines a "crossing period" and gives it soft labels rising linearly from 0.05 to 1. It extracts five-scale spectrogram features, feeds them to a 3D convolutional network, smooths the output by linear regression over 5 seconds, and fires when the accumulated probability crosses an empirically chosen threshold. This work motivates ours, since it shows that modeling the transition cuts detection delay. It also leaves three things that we change. The linear ramp is an arbitrary shape imposed on the target. The 5-second accumulation sets a floor on how early the alarm can fire. The threshold is tuned per patient rather than derived from a target false-alarm rate. Rather than regressing a hand-designed ramp, we treat the transition as a hidden state whose evidence is weak, and we make the alarm a calibrated posterior.

Two lines of work show that smoothing removes flicker but costs real-time operation, and so they constrain our design. SODor segments long recordings into persistent states by clustering inverse covariance structure. This removes flickering, but the authors state it runs offline. The real-time surgical phase recognition framework of Mezzina et al. smooths frame-wise predictions with Viterbi decoding of a Hidden Markov Model, a probabilistic model of state sequences. This raises segmental edit score by an order of magnitude. However, the best Viterbi path depends on future frames, and the smoother sits outside training. We keep the state-transition structure but use only the causal forward recursion, which needs no future data and can be differentiated through.

For latency and evaluation we reuse the methods of Cho et al.'s real-time EEG benchmark. That paper fixes 4-second windows advanced every 1 second, requires each window to finish in under 1 second, and reports raw-waveform 1D convolutional networks running in as little as 0.009 s on a CPU. It also introduces MARGIN, a metric that checks whether alarms fall within a few seconds of the true onset. It argues that AUROC hides failures at onset on imbalanced streams.

Two further papers contrast with our treatment of imbalance. Logit-adjusted test-time adaptation corrects logits with a running estimate of the class priors in the test stream. On an EEG stream, that running estimate would be dragged toward "seizure" during a seizure and toward zero during days of background, which is unsafe for a detector. We use a fixed, clinically set onset rate instead. BF-EML reaches 97.65% accuracy on unseen CHB-MIT patients by removing patient-specific bias. Its authors state that the Fisher-information cost blocks real-time use. It is a window classifier and does not model onset dynamics, so we treat cross-patient debiasing as orthogonal.

Core Mechanism

Let the hidden state at second $t$ be $s_t \in \{B, X, I\}$, standing for background, crossing (transition), and ictal (seizure). A raw-waveform encoder, either ResNet-short with an LSTM or a smaller 1D network, outputs a softmax $q(s \mid x_t)$ over the current 4-second window $x_t$. It is trained with class-balanced sampling, so the training prior $\pi(s)$ is known by construction. Dividing by that prior turns the classifier output into a quantity proportional to a likelihood. The causal filter is

$$ \alpha_t(s) \;\propto\; \frac{q(s \mid x_t)}{\pi(s)} \sum_{s'} A_{s's}\, \alpha_{t-1}(s'), $$

where $\alpha_t(s)$ is the filtered probability of state $s$ at time $t$, and $A$ is a left-to-right transition matrix. In $A$, background moves to crossing with hazard $h$, the per-second onset rate estimated from the deployment population. Crossing moves to ictal with rate $1/D$, where $D$ is the expected crossing duration in seconds. An alarm fires when $\alpha_t(X) + \alpha_t(I) > \gamma$. The threshold $\gamma$ is chosen on validation data to hit a target false-alarm rate per hour.

With only two states, this recursion reduces to the Shiryaev–Roberts style of change detector, whose delay-versus-false-alarm behavior is well understood. The crossing state is the new ingredient. It lets weak, early transition evidence accumulate without the model having to commit to "seizure." Imbalance appears only through $h$, and flickering is controlled by $A$. Both are interpretable and neither needs a lookahead buffer.

Overlapping windows make consecutive likelihoods correlated, so $\gamma$ is calibrated empirically rather than taken from theory.

For crossing labels, we mark the first $D$ seconds after each annotated onset as $X$, sweeping $D$ from 3 to 10 seconds. A variant also labels a short pre-onset margin as $X$. This tests whether the transition evidence begins before the annotated onset, as Xu et al. suggest.

Research Program

We will build the pipeline from the encoder in Cho et al.'s benchmark protocol and train it in four configurations. These are two-class unweighted, two-class balanced, three-class balanced, and three-class balanced with the filter's prior correction. We will also train an end-to-end variant, in which a sequence loss on the filtered posterior is backpropagated into the encoder. This addresses the limitation of external smoothers noted for Mezzina et al.

Analysis centers on delay-versus-false-alarm curves rather than single operating points. We also count flicker events, meaning alarm on/off toggles per hour. We profile per-step CPU latency and, if available, latency on a low-power ARM board. As an optional generality check, we will apply the same causal filter to sleep staging on Sleep-EDF, with N1 playing the role of the scarce transition state. SleePyCo, a transformer model that sees ten 30-second epochs of context at once, reports 84.6% accuracy there (SleePyCo). The check asks how much of that context a causal filter can replace.

Baselines

The naive reference is the ResNet-short + LSTM detector from Cho et al., thresholded window by window with no smoothing. On bipolar TUSZ it reports AUROC 0.92 and AUPRC 0.91. We will retrain it on our exact splits. We will report its delay at matched false-alarm rates, because its published numbers are ranking metrics and not onset delays. Beating it means lower median onset delay at every false-alarm rate between 0.1 and 2 per hour.

The strongest practical competitor is the same detector with tuned causal post-processing. This covers the k-of-n rule, an exponential moving average, and threshold moving. Each is given the same validation budget as our $h$, $D$ and $\gamma$, for example the same number of configurations searched. It is dangerous because, for a binary detector, moving the threshold already performs prior correction at decision time. We beat it only if the delay-versus-false-alarm curve lies strictly below it with non-overlapping patient-level bootstrap intervals.

The strongest published method on onset latency is Xu et al.'s soft-label multiscale 3D-CNN with linear-regression smoothing and accumulative alarms. It reports 94 of 99 CHB-MIT seizures detected within the crossing period, an average latency of 2.3 s, and 0.08 false detections per hour. On SWEC-ETHZ it reports a latency of 4.7 s at 0.08/h (Deep Learning for Short-Latency Epileptic Seizure Detection with Probabilistic Classification). We will compare under its patient-specific leave-one-seizure-out protocol on both datasets, using its reported numbers and a reimplementation run on the same hardware for latency profiling. Within that protocol, matching 2.3 s within half a second at no more than 0.08/h, while using a far cheaper encoder, counts as success. Beating 2.3 s would be a strong result we do not presume.

The ablations isolate the key ingredient. The first is a two-state filter, which removes the crossing state. The second is three-class training without dividing out the training prior. The third is balanced training with no filter. The fourth uses Xu-style linear soft labels on the same raw encoder in place of our three-state targets. If the two-state filter matches the three-state one, the crossing state is not doing the work, and the claim reduces to "causal change detection on a small CNN."

Why not just…?

Why not just tune the threshold and add a k-of-n smoothing rule to an existing detector? This is the most serious threat, because threshold moving and our prior correction act on the same decision. The difference is that a k-of-n rule throws away the graded strength of evidence and waits a fixed count of windows. The filter weighs each window by how strongly it favors the transition. The matched-tuning-budget comparison in Baselines settles this directly. If the curves coincide, we will report that the gain is engineering, not modeling.

Why not just use focal loss or class weighting with Xu-style soft labels? Reweighting raises gradient on rare windows, but it distorts the output probabilities by an unknown amount, so they can no longer be combined with an onset rate. Xu et al. needed per-patient threshold tuning to compensate. The soft-label ablation on the same encoder shows whether the three-state likelihood view adds anything beyond better gradients.

Why not just keep Xu et al.'s accumulative decision rule but swap in a lighter encoder? Their rule integrates over a fixed 5-second buffer, which caps how early a strong onset can trigger an alarm. Its threshold is also empirical rather than tied to a false-alarm target. We include this hybrid as a baseline so that the encoder and the decision rule are varied separately.

Why not just use HMM Viterbi smoothing as in Mezzina et al.? Viterbi decoding chooses the best path over future frames as well, so in streaming use it either waits or degrades to forward filtering, which is our method. The forward-only recursion is what remains when lookahead is forbidden.

Proposed Experiments and Decisive Checks

The main experiment runs cross-patient on TUSZ under Cho et al.'s 4-second, 1-second-stride protocol. It reports onset delay, sensitivity, MARGIN at ±3 s and ±5 s, flicker events per hour, and per-step CPU latency, all at false-alarm rates from 0.1 to 2 per hour. The second experiment runs patient-specific on CHB-MIT and SWEC-ETHZ, matching Xu et al.'s protocol so that their reported figures are directly comparable.

Three results would decide the proposal. The three-state filter must beat the tuned smoothing baseline on delay at matched false alarms on TUSZ. The two-state ablation must be measurably slower, which shows that the transition state carries early evidence. Total per-step latency must stay within the same order as the 0.009 s raw-CNN figure.

If the first check fails, the idea is not worth pursuing further. If only the second fails, we will report causal change detection as the useful part and drop the transition-state claim.