top of page

Variational Autoencoder for Interpretable Seizure Onset Phase Detection in Epilepsy

Drug-resistant focal epilepsy affects about one-third of epilepsy patients and causes persistent seizures despite treatment. There are a few treatment options for these patients, including neuromodulation and resective surgery.


In resective surgery, determining the exact origin of seizures in the brain is a crucial step that must be performed in every patient individually. The primary technique used to do so is electroencephalography (EEG) analysis, a monitoring technique where electrodes are placed on the scalp to record electrical activity.


However, this non-invasive technique is often not enough to determine the exact area to resect with the required precision. In those cases, an invasive recording technique, stereo electroencephalography (SEEG), is used, where the electrodes are implanted deep within the brain.


Because this technique is invasive and requires recording multiple seizures, a patient’s SEEG session can last several days, producing large amounts of data to review. Identifying the electrical patterns that initiate a seizure in those recordings is time-consuming and susceptible to interobserver variability, even between clinicians.


Such clinical situations create the need for an automatic, yet transparent AI tool that can assist them in the process.


Artificial Intelligence Can Offer Aid in SEEG Review


In this post, we introduce a deep learning framework designed to assist clinicians in annotating the precise onset of seizure activity. Our system uses a type of generative network called Variational Autoencoder (VAE) to automatically analyze SEEG recordings.


A key concept of our approach is that the VAE offers an element of interpretability, the ability of the model to base its decisions on ascertainable features, like a human would.


The process begins by breaking down the raw SEEG recordings from each electrode into two-second segments, which become the input of our VAE model. The architecture of a VAE consists of two main neural network components: an encoder and a decoder.


The encoder’s task is to learn a compressed representation of the input data. It takes the two-second SEEG segment and identifies its more relevant features, allowing it to express the same information in a much lower-dimensional form, known as the latent space. The decoder performs the opposite function, using the representation in the latent space, it learns to reconstruct the original signal.


During training, the VAE learns to perform these tasks with minimal reconstruction error. At the same time, we couple this process with a linear classifier that learns from the latent space directly. Its task is to categorize the latent representations into three classes: interictal activity, active seizure (or ictal) activity, and a key pattern known as Low Voltage Fast Activity (LVFA). The latter is particularly important since its presence is a known biomarker for seizure genesis, which occurs at the SOZ, the area of the brain where seizures originate.


The addition of this classifier encourages the VAE to learn the features that can best separate the signals into the three classes.


How Do We Actually Annotate SEEG Channels?


So far, our system identifies seizure activity in two-second segments. However, to provide meaningful annotations, we need to use the signal of the whole SEEG channel.


We accomplish this by combining the probabilities of each of the segments of the channel in a post-processing algorithm. The algorithm applies exponential smoothing to the probability signal generated by all the segments and computes its Area Under the Curve (AUC).


This way, the more consecutive ictal/LVFA segments found in the channel, the larger the AUC will be. Additionally, it prevents the system from marking isolated fluctuations in electrical activity, such as interictal spikes. We consider the presence of ictal/LVFA activity in the channel when the AUC goes over a tunable threshold, marking the exact time when that event occurs.


SEEG Channels
Figure 1: Overview of the proposed methodology. A: SEEG channels are annotated and split into segments of interictal, ictal and LVFA classes, which are used to train the VAE and obtain reconstructions and class probabilities per segment. B: A postprocessing algorithm is used to convert segment probabilities of SEEG channels into markers.

Validation Through Cross-Patient Testing


To ensure that the model could generalize to new patients, we used a 5-fold cross-validation strategy.


This technique splits the 37 subjects into five groups, ensuring no overlap. For each round, the VAE is trained with four groups, leaving one for validation. This validation group is then further split into two independent groups: a development group where we tune the threshold for the post-processing algorithm, and a test group where we evaluate the full system. Since all groups are independent, we evaluate the full system twice, swapping the roles of the test and development sets. This subject-wise approach guarantees that the model is always evaluated on data from patients it has never seen before during training.


Our system manages to detect ictal onsets across all channels with an average recall of 86%, with an F1-score of 85%. Additionally, when we take into consideration only the channels that clinicians indicated as being part of the SOZ, the average recall rises to 91%. This behavior is expected, since ictal patterns are easier to recognize in the SOZ. When it comes to LVFA detection, the average recall and F1-score were 74%.


Ictal and LVFA detection
Figure 3: A: Metrics for the ictal detection, evaluated on all channels per subject. Individual points indicate performance on each subject. B: Metrics for the LVFA detection. C: Histogram of the time lag, in seconds, between the real and predicted ictal annotations of the whole dataset, clipped to 50 seconds before and after the real marker. D: Histogram of the time lag, in seconds, between the real and predicted LVFA annotations of the whole dataset, clipped to 15 seconds before and after the real marker.

What Features is The Model Using to Generate Predictions?


One of the most relevant aspects of our full system is the interpretation of the latent space. We achieve this in two steps:


  • Firstly, we extract the weights of the linear classifier (one weight per latent dimension and class), with high positive weights indicating relevance towards the class and high negative weights indicating relevance against the class.

  • Second, we compute the values of different SEEG features, such as mean amplitude and spectral power, of the segments and correlate them with the values of each latent dimension for the same segment after passing it through the encoder.


We show that the internal latent space of the VAE correlates with physiological (and clinically meaningful) signal features observed in SEEG.


For example, when we analyze the weights of each latent dimension by the linear classifier for the ictal class, we find that dimensions given a high positive weight are directly correlated with the mean amplitude of the SEEG segments, as well as power in the alpha and low-beta frequency bands. Conversely, high negative weights are anticorrelated to these same features. The LVFA class shows the opposite pattern, with high weights being correlated with the energy ratio, defined as the power at beta and gamma bands divided by the power at theta and alpha bands. Finally, the system gives the interictal class high importance to dimensions directly correlated with spectral flatness, indicating the absence of a dominant frequency.


These examples show that the model is not just finding statistical patterns; it is learning to identify similar electrographic patterns that a human expert would look for. This transparency is essential for applying AI systems in clinical settings.


Analysis of the VAE-based classification
Figure 5: Interpretability analysis of the VAE-based classification. A: Heatmap of normalized classifier weights for each latent dimension and class (ictal, interictal, LVFA), along with the Spearman correlations between each latent dimension and several SEEG features. The color scales indicate the direction and magnitude of the weights or correlations. B: Scatter plots compare each dimension’s classifier weight (x-axis) to its correlation with selected features (yaxis), illustrating how strongly certain latent dimensions align with known signal characteristics.

Conclusion: Toward Explainable AI for Seizure Localization


This work shows that deep learning can go beyond black-box prediction to offer meaningful clinical insights.


By combining accurate detection with interpretable latent features, our framework could reduce the workload of clinicians while building their trust in AI-assisted diagnosis. To sum up, it represents a step toward faster, more precise, and explainable seizure localization for patients with drug-resistant epilepsy.


References:

Parisa Mohammadzadeh and Surena Nazarbaghi. The prevalence of drug-resistant-epilepsy and its associated factors in patients with epilepsy. Clinical Neurology and Neurosurgery, 213:107086, 2022.

Jean Isnard et al. French guidelines on stereoelectroencephalography (SEEG). Neurophysiologie clinique = Clinical neurophysiology, 48(1):5–13, Feb 2018. Copyright © 2017 Elsevier Masson SAS. All rights reserved

H. E. Ronner, S. C. Ponten, C. J. Stam, and B. M. J. Uitdehaag. Inter-observer variability of the eeg diagnosis of seizures in comatose patients. Seizure, 18(4):257–263, May 2009. Epub 2008 Nov 28.

Stanislas Lagarde, Sinziana Buzori, Agn`es Trebuchon, Romain Carron, Didier Scavarda, Mathieu Milh, Aileen McGonigal, and Fabrice Bartolomei. The repertoire of seizure on- set patterns in human focal epilepsies: Determinants and prognostic values. Epilepsia, 60(1):85–95, January 2019. Epub 2018-11-13.

Diederik P Kingma and Max Welling. Auto-encoding variational bayes, 2013

John M. Bernabei, Adam Li, Andrew Y. Revell, Rachel J. Smith, Kristin M. Gunnarsdottir, Ian Z. Ong, Kathryn A. Davis, Nishant Sinha, Sridevi Sarma, and Brian Litt. ”hup ieeg epilepsy dataset”, 2022.

Comments


Commenting on this post isn't available anymore. Contact the site owner for more info.
bottom of page