Вы находитесь на странице: 1из 5

DEVELOPING AN ALGORITHM TO PREDICT SEIZURES

RMP 2015

Signal Processing: Engineering an Algorithm to Predict Epileptic Seizures Through


Contour Fitting
1

Gitanjali Multani,1 Abhejit Rajagopal2

Torrey Pines High School, 3710 Del Mar Heights Rd., San Diego, CA 92130
e-mail address: gita.pm1@gmail.com
2
Department of Electrical and Computer Engineering, University of California, Santa Barbara, 93106, USA
Anticipating seizures can save a copious number of lives that are lost due to the fatality of the condition.
Furthermore, prediction provides the opportunity to adaptively administer treatments that mitigate the
intensity of the seizure. Despite these desirable outcomes, predicting epileptic seizures is a conundrum that
has eluded researchers because of their characteristic unpredictability. We have delved into detecting
seizure transition periods through signal processing and an implementation of discrete mathematics.
Drawing inspiration from least squares regression, we present an algorithm that generates a parameterized
curve to contour fit electroencephalogram (EEG) data. During the onset of a seizure, a sensitivity analysis
demonstrates that the data gradually changes into a patterned plot. Quantifying this anomalous change, we
hope to achieve real-time detection of epileptic seizures.
Keywords: Electroencephalogram (EEG) data, contour fitting, least squares regression, epilepsy

I. INTRODUCTION
Approximately one to two percent of the population
suffers from seizures. Seizures are infamous for their
unpredictability, and this characteristic is the chief reason
why the disability associated with epilepsy causes severe
impacts to quality of life for patients and their caregivers
[1]. Regardless of the aftermath of a seizure, the sheer
uncertainty is enough to prevent victims from participating
in activities such as cooking. The potential lies in
eradicating this uncertainty and returning quality of life
back to the victims. Already, biomedical engineers have
developed responses such as electrical stimulation and
vagus nerve stimulation (see Appendix A) that assist
patients during the onset of a seizure, but would be better
served if tailored to the intensity of the seizure.
Studies conducted by researcher Jan Pieter Pijn conclude
that the brain registers any stressful situation the body is
undergoing, hence depicting a noticeable change in the
presence of pain [2]. Moreover, measurements of EEG data
show that normal brain dynamics involve a limited,
transient synchronization of disorganized neural activity
that evolves into a persistent highly synchronized state
during an epileptic seizure [3]. Thus, we hypothesize that
the transition period is gradual and will allow us to quantify
changes distinct to an epileptic seizure.
Unfortunately, little progress has been made in real-time
prediction of epileptic seizures because the algorithm is
responsible for issuing a decision based solely on the
signals it has received. This limitation not only hinders the
accuracy of the algorithm, but also makes it extremely
arduous to classify the seizure. For instance, it would be
desirable to only detect the seizures that result in
irreversible damage, but this could vary from patient to

patient, thus calling for a method that is patient-specific.


Additionally, signals transmitted from the brain tend to
include many arbitrary factors that translate into noisy
data and obstruct the signals of interest. If we are unable to
differentiate between the seizure indicators and the
overlapping noise, seizures could be incorrectly
determined, or worse, go completely unnoticed.
We propose an algorithm that addresses these problems
in two ways. First, shared characteristics will create a base
graph that will detect a wide variety of seizures. Second,
different classifications of seizures are detected based on
attributes unique to the type of seizure; so, short bursts and
spikes can be differentiated from large abnormal
epileptiform activity [3]. This paper will focus on the
beginning stages of the algorithm in hopes of eventually
accomplishing the abovementioned aspects of seizure
prediction. In our algorithm, we integrated the concept of
least squares regression, thereby formulating a contour fit
that is constructed based on the average vector direction
between clusters of points. Quantifying features from a
patients brain signals, such as frequency and amplitude, we
are able to calculate the error between the contour fit of
these graphs and the true polynomial that passes through it.
This error can then be used to determine the transition into
a synchronized brain state and aid us in distinguishing
divergent seizures.

II. PREDICTION ALGORITHM


Currently, the best seizure prediction method is able to
distinguish a seizure four seconds prior to its occurrence.
Selected highly experienced doctors have developed a keen
eye for seizures and are able to anticipate a seizure minutes
before its onset. Even so, the former provides only a
minimal window to administer treatment, and the latter

DEVELOPING AN ALGORITHM TO PREDICT SEIZURES

RMP 2015

FIG. 2 (2-D EEG data plot). A 2-dimensional representation of the


preprocessed electroencephalogram data with arbitrary axes and
(, ) coordinates plotted with respect to the independent variable,
time.

FIG. 3 (Averaged coordinates). The black points represent the


averaged data within their respective time intervals. Referring
back to FIG 2, there is a noticeable change in the distribution of
rainbow hues, which now distinguish the one hundred bins.

provides no guarantee. Thus, We tackle the endeavor of


offering a mathematical formula that combines the
advantages of both abovementioned techniques: accurately
detect a seizure minutes before its onset.
Each dataset was preprocessed and simplified down into
3-dimensional points (, , ). For the purpose of this
paper, each 3-dimensional projection will be shown on a 2dimensional plot with arbitrary axes, as shown in FIG. 2.
The quandary now enters as a multivariable problem, with
both and graphed as a function of time between a lapse
of zero and one. Additionally, the Euclidean distances
between pairs of points integrated vectors as a means to
obtain the direction in conjunction with the distance.
From the mathematical field of numerical analysis, we
initiated the implementation of interpolation, a manner of
constructing new data points within a range of a discrete set
of known data points. This allowed us to allocate clusters of
EEG data into bins based on relative intervals of time.
Subtracting the minimum value of time from the maximum
value of time and dividing by the desired number of bins,
we chose to fashion one hundred such bins between time
equals 0 and time equals 1, signifying that each bin had a
range of 0.01. FIG. 3 depicts the graph of the bins, minus
the black points, which will become explicable further in
this section. There is a slight but distinct different in the
rainbow gradient, which now associates each stretch of
time with a different hue. Within each bin, we averaged the
coordinate, time, and binary value, all of which were then
appended to their respective matrices. Henceforth, each
cluster was denoted by a single mean location, time value
and binary digit. This newly obtained data was graphed in
FIG. 3 and is represented by the black points. Interpolation
coupled with averaging

effectuated the elimination of excess noise and allowed us


to comfortably identify the collective trend of the points.
Now working solely with the averaged data, we took the
first derivative as well as the second derivative of and
with respect to time in order to quantify the changes
between the points. As opposed to Calculus I and II in
which the derivative is taken of a function, we encountered
the challenge of having to execute this same concept onto
individual points. Exercising discrete mathematics, we used
!"
forward difference (1) to calculate the first derivative
and

!"
!"

!"

, and central difference (2) to calculate the second

derivative

!!!
!"

and

!!!
!"

! =
! =

!!! !!!
(1)
2

!!! 2! + !!!
(2)
()!

With the first derivative, we found the average change in


slope, and with the second derivative, we found the average
change in curvature. Amalgamating both aspects, we
procured the degree to which the data was changing within
each interval of time. The subsequent challenge laid in a
visual representation of the knowledge we acquired.
Despite computing both derivatives, it could be easily
discerned that there did not exist a linear function that best
represented the data. Rather, we employed a quadratic
parameterization (3) that contour fitted a quadratic to the
averaged points, as portrayed by the blue line in FIG. 4.

DEVELOPING AN ALGORITHM TO PREDICT SEIZURES

FIG. 4 (Superimposed graph). For simplicity reasons, the number


of bins has been reduced to 20. The contour fit is the blue line
connecting the black points. Our estimated (, ) coordinates at
sampled times are plotted in purple and largely line up to our
estimated contour. The interpolated line is shown in white and is
noticeably following the same pattern as our predicted regression.

1
+ ! + !! ! (3)
2
However, if the contour line is a poor representation of
the data, then it can be of no further use. So, we tested its
accuracy by interpolating between the averaged points and
calculating the line that truly passed through each point. We
applied a linear interpolation function to the data and
graphed the resulting line in white as shown in FIG 4.
Interpolation of a curve is explained in the Weierstrass
Theorem, and the foundation of its drawbacks is outlined
by Runges phenomenon (see Appendix A). Based on the
interpolated line, we were able to visually observe how
close the regression came to mimicking the precise
function. Referring to FIG. 4, we determined how well the
blue line fit the black dots. Our initial prediction
hypothesized that our algorithm came fairly close to
achieving a high level of precision. To mathematically test
this, we conducted an error analysis. Employing what has
been coined as the nearest neighbor method, we found the
Euclidean distance between a sample point on the contour
line and its neighbor that lies on the interpolated line.
Testing eighteen different bin numbers ranging from five to
one hundred in intervals of five, we manually calculated the
mean error, allowing us to conclude the optimal number of
bins that gave rise to the smallest degree of error.

III. APPLICATION OF FINDINGS


With the elimination of the excess noise, we utilized the
averaged data to contour fit the overall trend of the plot as
well as to realize how close our algorithm came to creating

RMP 2015

FIG. 5 (Error Graph). The graph shows the mean error between
the contour fit and the interpolated line at various bins values. 35
bins cause the contour fit to loop over itself and confuse the
proceeding steps of the algorithm; 100 bins provide the optimal
balance and create the smallest mean error.

a polynomial representation of the data. Computing the first


and second derivative gave us the state transitions between
points as well as how quickly it transitions. Given a
particular time, we could now determine where on the
curve the (, ) coordinate should lie. However, our goal
was to predict the onset of a seizure, which involved
calculating the eventual direction of the regression based on
how much the slope and curvature changed. Our initial
error analysis demonstrated that our algorithm came
extremely close to computing the function that best fit the
data. In other words, the quadratic approximation was an
accurate representation of the interpolated line, which
explains why in FIG. 4, the blue line coincides with the
white line. With this information, we conducted a statistical
analysis to quantify the optimal number of bins that limited
the amount of looping in the regression line. Our results
indicated that one hundred bins our initial value ensued
in the smallest degree of error, which was 0.0000825. In
fact, the mean error amongst every tested bin value was less
than .01%, suggesting that our algorithm can fashion an
accurate regression line regardless of the number of bins.
FIG. 5 plots each bin value with its associated error.
This is significant for the subsequent step of testing,
which ascertains how well our algorithm is able to predict
the next brain state. We accomplished this by calculating
the error between where we predict the next point to be and
the actual value of the point. If this error, too, is negligible,
then we will have established a technique by which doctors
can look solely at the error charts of the patients brain
signals to determine whether or not a seizure will occur. It
has already been discussed that a brain in a normal state
will plot very chaotically and randomly; therefore, the
distance between the predicted point and its actual value

DEVELOPING AN ALGORITHM TO PREDICT SEIZURES


will have a greater error. However, during the onset of a
seizure, when the signals show a synchronized state of the
brain, the error will largely reduce and our predicted point
will have a much smaller distance to the true coordinates.
Unfortunately, our current method calls for twenty-four
hour supervision of the patient, which is why our hope is to
create a small implantable or wearable device, similar to
that of an insulin monitor, which will run our algorithm.
Additionally, using the information obtained from the error
analysis, we would like to observe the transition period in
the EEG data during which the errors gradually decrease.
Our preliminary results henceforth leads us to discovering
the revolutionary method of detecting a seizure minutes
before its onset.

IV. CONCLUSION
From the initial stages of this undertaking, our entire
method was based upon the idea behind least squares
regression. Interlacing this logic into the minutiae of our
algorithm, we applied Weierstrass Theorem to
parameterize the curve that connected each averaged data
point to its neighbors. Our method is particularly favorable
because it formulates a closed-loop as opposed to an open
loop, which permits the ability to adaptively dose the
patient. Consequently, advances in medical technology that
already allow seizure damage to be minimized could be
implemented even before a high intensity seizure transpires.
Moreover, our algorithm takes the unique approach of
functioning regardless of the pattern of EEG data. Rather, it
is able to map the gradual change in any brain signal and
issue a decision that can be analyzed by the naked eye. Our
eventual goal is to implement our algorithm in real-time.
This will replace the use of preprocessed data with brain
signals that are collected immediately from the patient.
Perhaps by quantifying the anomalies discussed at the
beginning of this paper, such as those in frequency and
amplitude, we will be able to differentiate between
classifications of seizures based on attributes unique to the
class. In this way, we aspire to develop upon our algorithm
to supply not only the occurrence of a seizure, but also the
intensity of it. This improved method will be a steppingstone to eradicating the uncertainty so prominent in the
lives of epilepsy patients.

RMP 2015
their continued support and friendship throughout this
exciting yet stressful experience.
1] R. S. Fisher, B. G. Vickrey, P. Gibson, B. Hermann, P.
Penovich, A. Scherer, and S. Walker, The impact of
epilepsy from the patients perspective I. Descriptions
and subjective perceptions, Epilepsy Research, pp.
3951.
[2] J. P. Pijn, J. V. Neerven, A. Noest, and F. H. L. D.
Silva, Chaos or noise in EEG signals; dependence on
state and brain site, Electroencephalography and
Clinical Neurophysiology, vol. 79, no. 5, pp. 371381,
1991.
[3] S. Ramgopal, S. Thome-Souza, M. Jackson, N. E.
Kadish, I. S. Fernndez, J. Klehm, W. Bosl, C.
Reinsberger, S. Schachter, and T. Loddenkemper,
Seizure detection, seizure prediction, and closed-loop
warning systems in epilepsy, Epilepsy & Behavior,
vol. 37, pp. 291307, 2014.
[4] R. S. Monderer, D. M. Harrison, and S. R. Haut,
Neurofeedback and epilepsy, Epilepsy & Behavior,
vol. 3, no. 3, pp. 214218, 2002.
[5] J. Fridley, J. G. Thomas, J. C. Navarro , and D.
Yoshor, Brain stimulation for the treatment of
epilepsy, Neurosurg Focus, pp. 8892, 2012.

APPENDIX
1.
a.

Medical Treatments

Biodfeedback: teaches the patient to control involuntary


biological processes and normalize EEG activity. The
patient initially wears sensory nodes around their body to
assist them in seeing and hearing various bodily
functions. After some training, they learn to control these
functions and eliminate the need for the nodes [4].
Vagus Nerve Stimulation (VNS): a small implantable
device generates electrical pulses to stimulate the vagus
nerve. The vagus nerve is one of twelve cranial nerves that
communicates via impulses to other parts of the brain as
well as to the head and neck [5].

ACKNOWLEDGEMENTS
I would like to thank Abhejit Rajagopal for the countless
hours he put in and emails he wrote into helping me
accomplish the six-week endeavor that was coding this
algorithm. I also owe special thanks to Nithin Govindarajan
for assisting me in understanding the derivations and
mathematics behind the concepts we implemented as well
as Raymond Valdes and Dr. Lina Kim for revising my
paper. Thank you to my wonderful collaborators, Samara
Shaz and Priyanka Multani, and my buddies at RMP for

Definitions

2.

Theorems

Weierstrass Approximation Theorem: there exists a


sequence of polynomials, ! , such that as goes to infinity,
! () approximates () arbitrarily close

lim ( max | ! | ) = 0

!! !!!!!

Runges Phenomenon: a problem of oscillation at the


edges of an interval that occurs when using polynomial

DEVELOPING AN ALGORITHM TO PREDICT SEIZURES


interpolation with polynomials of high degree over a set of
equispaced interpolation points.

RMP 2015
4.

Additional Graphs

lim ( max | ! | ) =

!! !!!!!!

3.

Derivations

Least Squares Regression:


! = ! +
!

(! )!
!!!

! =
!!

!!

= ! +

! = ! + !
FIG. 1 (3-D EEG data plot). A 3-dimensional representation of the
preprocessed electroencephalogram data with arbitrary axes and
( , , ) coordinates plotted with respect to the independent
variable, time.

!
!

(! + ! ) = (, )
!!!

! + ! ! + !
! ! ! + ! ! ! + ! + ! ! ! ! !
+ ! !
! ! ! + 2! 2! ! 2! + ! + ! !
!

!
!

! ) + (
!!!

2! ) + (
!!!

2! ! )
!!!

2! ) + ! + (

+(
!!!

! ! )
!!!

! ! + ! + ! + ! + ! ! + !

Вам также может понравиться