Finding Patterns in Seizure Data

Dominique Eden
Brain Waves
Published in
6 min readNov 26, 2021

How we use circular statistics to help warn people with epilepsy of their risk of experiencing a seizure

The challenges of uncontrolled seizures

Around one third of people with epilepsy aren’t able to control seizures with medication or treatment. For these people, not knowing when a seizure will occur makes even mundane, day-to-day tasks profoundly difficult. Pouring a hot cup of coffee, planning a grocery shop, or cooking an evening meal are just some examples that would require careful consideration.

In 2016, the Epilepsy Foundation released a survey asking people living with epilepsy what aspects were most burdensome. Over 70% of the respondents agreed that unpredictability of seizures was having the most negative impact on their lives.

So, if seizures can’t be controlled, is there a way they could be managed? In short, yes — there is.

Being able to forecast seizures, hours to days in advance, would give someone the opportunity to manage, plan, and respond appropriately.

Providing people with a system that forewarns the risk of experiencing a seizure would relieve some of the uncertainty associated with epilepsy.

For instance, knowing that one might have a high risk of a seizure in the afternoon could mean a change of plans to the grocery store.

But aren’t seizures meant to be random?

Seizures are often thought of, and described as, random. Why? Well, seizures do appear to behave randomly if one was to look across a population. However this is a misconception. Our research has found that seizures are not unpredictable in nature, but in fact, are regular in their occurrence when looking within individuals.

We found that seizures follow rather predictable cycles, recurring at specific times of the day, week, month, and/or anything in between.

What’s even more impressive is that detecting these seizure cycles doesn’t require specialised equipment or invasive surgery — just a record of times when the seizures occurred.

Many people with epilepsy use anything from pen and paper, to calendars, and Excel spreadsheets to record the times at which their seizures have occurred. This was a chief motivator for early developments of the Seer app. Collecting long-term data of seizure events from an electronic diary has allowed us to spend time developing methods for identifying event-based seizure cycles.

So, how do we forecast seizures?

Detecting a user’s seizure cycle or cycles

The method we currently use to determine users’ seizure cycle or cycles (most people’s seizures are modulated by more than one cycle) could be summarised as testing cycles with varying periods, and selecting cycles with the strongest alignment to the user’s seizure times.

We start by testing an array of cycles against the user’s data, e.g. cycle periods from 6, 12, 18, 24 hours, up to 3 months. To do so, we calculate the phase of each seizure with respect to a given cycle period. The resulting vector length is then calculated for each cycle period. This is called the r-length. The r-length is normalised between 0 and 1, where an r-length of 1 indicates perfect alignment of seizures (i.e. a unimodal distribution), and an r-length of 0 indicates no alignment (i.e. a uniform distribution).

Let’s use an example using mock seizure times, in place of seizure times which would typically be logged by a user from the Seer app. Here’s a list of seizure times formatted as Unix timestamps (in milliseconds):

We convert these timestamps to days since epoch as a convenient point of reference. Testing against the following cycle lengths (in days):

We can calculate r-lengths and phases (angles) using the following function:

Using matplotlib to plot the result r-lengths for the tested cycles, we’d see:

From this we select the strongest cycle periods indicated by cycle periods with peak r-length. In this example, the mock user has a strong cycle at 24 hours, 36 hours, and at 3 days. Typically, a user will have two or three cycles significant enough to model the behaviour of their seizures.

Determining a user’s probability of a seizure

Sine waves are constructed using the period from each of the selected cycles. Seizures are then mapped to the phase of each period and a histogram is computed using about 20 bins.

Seizures are then fit to a von Mises distribution (similar to a Gaussian distribution but using polar coordinates), where the peak of the distribution — or probability — indicates when a seizure is most likely to occur, and the trough indicates when seizure is least likely to occur. Odds probability is then used to combine the von Mises distributions.

The result? Here’s a plot generated from the mock user’s data, displaying combined likelihood with a 24 hour cycle and 3 day cycle detected, and projected 60-days into the future.

The probability of a user experiencing a seizure using mock data, projected 60 days into the future.

How did we go? Well, if we use the same forecast, project it into the past, and map the mock user’s seizure times, we see good alignment just by visual inspection (see below). Most seizures have occurred at, or very close to, the peak of seizure probability.

The probability of a user experiencing a seizure, projected 60 days into the past. The user’s mock data is indicated by the red triangles, which by visual inspection, show very close alignment to peak probability.

Despite the fact that this is mock data, the method has very promising results for real data too.

Optimising to define a user’s seizure risk

An optimisation step is applied to provide the user with three levels of risk: high, medium, and low. As a general rule, we opt to have a higher percentage of seizures in high risk, and a higher proportion of time in low risk.

Why don’t we use Machine Learning?

At some point you may have wondered why we don’t use an out-of-the-box machine learning approach. First and foremost, the statistical method explained above straight up outperforms machine learning models thus far. Another reason, is that machine learning is not suited to just a few data points which is important considering new users and those that may only experience a handful of seizures a year will not have extensive data sets. Finally, being that each model is patient-specific, one model per user and frequent retraining become computationally expensive.

This isn’t to say however that there is no room for machine learning at all. More recently, we have integrated heart rate from wearable devices to improve forecasting performance, with neural networks showing promise.

How this helps people

We’re now at a stage where seizures logged by users in the Seer app can be used to detect user-specific seizure cycles and probability, and seizure risk can be determined and displayed back in the app.

We hope that by alleviating the uncertainty of seizures for those living with epilepsy, we can improve the lives of people with epilepsy.

Want to learn more? Check out our research publications page for some academic deep-dives into these topics.

This blog series may contain “work in progress” technological developments and it is meant to be a developer focused forum. As such, posts here are not intended to make any claims relating to clinical safety / efficacy of already cleared medical devices at Seer. The discussion is general in nature and does not include any personally identifiable or health information.

--

--

Dominique Eden
Brain Waves

Machine Learning / Research Engineer at Seer Medical