Sleep and DREEMs: An Overview of Healthy Sleep and Computational Approach to Deep Sleep Prediction
Disclaimer: All work is for PSYCH135:Sleep and Dreams at Stanford University, and is not commercially targeted.
By: Alice Yang, Khaled Jedoui, Zhuoer Gu
- Introduction — Have you heard about healthy sleep schedules?
Often, when asked about their hobbies, people will jokingly respond “sleeping.” However, this is not inaccurate — Sleep is a biological behavior which takes up a significant part of our daily life. Sleeping each day is crucial for recovering from expended energy loss. Biologically, we all know that we need to sleep, but, often, we can learn how to sleep. Healthy sleep includes both getting enough sleep everyday and keeping to a regular sleep schedule. In this post, we walk you through an introduction to sleep, including a few key concepts and definitions. Then, for fun, we introduce a few misconceptions about sleep. Finally, we introduce technologies which measure and track our sleep, and introduce machine learning models we train on sleep data.
Sleep Rhythms
The first step towards having a healthy sleep is to understand how our sleep works. Our sleep cycle has rhythms, namely homeostatic and circadian sleep rhythms. The circadian sleep rhythm includes the biological clock, and the circadian rhythm is affected by alternation of days and nights due to lighting. As an example, jet lag is a circadian factor that affects our sleep phases. As for homeostatic factors of sleep timing, we are concerned about physiological equilibrium of our sleeps. In particular, our sleepiness peaks twice a day and that coincides with when body temperature is the lowest, which is around 2 hours before wake-up time.
Sleep Cycles
After learning the regularity of our sleeps from day to day, we now learn about how sleep works on one night. In terms of sleep cycle, our brain state can be categorized into 1 of 3 states: awakeness, NREM (non-rapid eye movement) sleep, and REM (rapid eye movement) sleep. These states can be distinguished more clearly from brain waves in each state[3]. We can further divide NREM sleep into four stages, labelled as 1 to 4, where each of them is distinguishable by their wave types. Some interesting facts about these sleep stages are that: stage 2 sleep counts for 75% of our sleep; stage 3 and 4 are the deepest stages of sleep; and dreams mostly occur in REM sleep. As a result, REM sleep is when the strange behaviors associated with sleep, such as sleep paralysis happen, because all our muscles besides that of eye and heart are relaxed during REM sleep.
Sleep Misconceptions
Many of us have heard misconceptions about sleep. We often hear claims that, snoring is common and, thus, normal. In actuality, our sleep should be quiet — it is actually snoring that is abnormal! Snoring indicates difficulty breathing through the air-way, which could be an indicator of a serious health condition. Another misconception we often hear people say that ‘if you are tired enough from exercise, the sleep at night is deep and sound’. This is not actually true, since excessive exercise right before sleep may hinder us from falling asleep. One final misconception we are told is that the best sleep is one with a lot of deep sleep and without dreams. However, the fact is that we dream every night, and deep sleep does not count for most of our sleep.
Sleep Debt
While we all know plentiful sleep is necessary for a flourishing life, sleep deprivation is very common among us. We may think a night of lack of sleep helps us finish some work, but in the long run lack of sleep brings troubles such as reduced concentration, unsatisfying social engagement, and poor academic or work performance. Unsurprisingly, lack of sleep is also implicitly linked to depressive thoughts.
For many students, one common scenario of sleep deprivation is the all-nighter. Initially after pulling an all-nighter, we may find it pleasantly surprising and strange that we feel energetic, rather than tired, for several hours after pulling the all-nighter. However, as time goes on, we may be thinking or reacting to others significantly slower, or even have headaches, informally acknowledged as “crashing” from an all-nighter. As a result, we are often so exhausted that we nap for many hours in deep sleep. What’s worse is that when we wake from this century-long nap, we may still feel drained. If we keep on napping during daytime to recover from this disrupted schedule caused by one all-nighter, the usual circadian sleep rhythm at night will probably be affected. This is an example of excessive time in bed, another unhealthy sleep behavior, which may cause sleep problems in developing irregular sleep rhythm. From this example, we introduce the concept of sleep debt, which is defined as the total amount of sleep we lack relative to the amount of sleep we need every day. After the deprivation of sleep from an all-nighter, we usually need more sleep to compensate. We can generalize our sleep demand as saying “the less we sleep, the more sleep we need; and vice versa.” As sleep debt accumulates, we develop an inability to concentrate, reduced agility to the environment, and general drowsiness. Not only is this an annoyance on a day-to-day basis, but these consequences due to lack of sleep may be dangerous to our own lives. According to National Highway Traffic Safety Administration[2], tens of thousands of people are injured in accidents from drowsy driving, and lack of sleep results in upwards of 800 fatalities a year. Therefore, we should keep in mind that “drowsiness is red alert!”
Sleep Disorders
To maintain healthy sleep, we should also pay attention to our sleep quality besides getting plenty of sleep. To improve our sleep quality, we should know about the factors that affect the quality. Noise, light, circadian factors (such as jet lag), and anxiety are some basic factors that affect our quality of sleep [7]. To further explain, since darkness stimulates melatonin that is usually released in circadian wake-sleep rhythm, too much light will disrupt normal biological clocks. Jet lag can disrupt a normal 24-hour wake-sleep cycle during adaptation to the new time zone. Besides these circadian factors, shifting moods such as increases in anxiety can cause insomnia, a kind of sleep disorder.
There are various types of sleep disorders, but fortunately many of them can be significantly treated through proper treatments. Therefore, awareness of sleep problems and the resources we have to deal with them could help us suffer less from sleep disorders. Here, we give a brief overview on three common types of sleep disorders: insomnia, obstructive sleep apnea, and narcolepsy.
Insomnia is a sleep disorder of people primarily defined by a difficulty falling asleep or staying asleep. Insomnia can cause fatigue, attention or memory impairment, mood disturbance, decreased motivation, and daytime sleepiness. It is usually a symptom, which can develop into a chronic illness. However, it is often treated with Cognitive Behavioral Therapy approaches, such as stimulus control, sleep restriction, and scheduled thinking time.
As we learnt in the misconception at the beginning, snoring is an abnormal sleep behavior. Snoring is a feature of the sleep disorder Obstructive Sleep Apnea (OSA). OSA causes breathing pause of at least 10 seconds during sleep, and it occurs because the air-way is blocked. OSA features morning headaches, unrefreshing sleep, obesity, night sweats and snoring. This disorder can be dangerous because our brain prioritizes sleeping over breathing. Thus, OSA increases the risk of sudden death and car accidents. However, OSA can be treated with surgeries or Continuous Positive Airway Pressure(CPAP), which was modified from a vacuum.
Another sleep disorder we introduce here is narcolepsy, a disorder that is notably defined by falling asleep at unexpected and unpredictable times, going straight into a dream state, cataplexy, sleep paralysis, hypnagogic hallucinations among other phenomena. Narcolepsy occurs due to a lack of chemical peptide that binds receptors in the brain.While genetics is one cause of narcolepsy, it is not the sole reason for occurrence. Environmental factors usually contribute heavily to the disorder. Luckily, narcolepsy could be prevented by vaccination.
2. Training Models on DREEM Data
Given the importance of sleep on health and prevalence of sleep disorders, it should come as no surprise that there are a range of technologies to monitor and assist with quality of sleep. Consumer Sleep Technologies (CSTs) are non-prescription devices which claim to assist with “sleep-monitoring, tracking, or sleep-related interventions.” These devices usually gather user data and display them in some format to the user. These devices increases accessibility and accessibility of the individual’s sleep information to the general public. For example, a study showed that data from hypnogram have been . However, there is a common criticism of scientific evidence of lack of scientific evidence of these devices actually enhancing sleep. [5] Therefore, in our project, we decided to analyze data from the DREEM commercial sleep technology gathered by such a device, to help detect and improve periods of deep sleep.
The DREEM device records factors of sleep when worn on the head at night. The device consists of three parts: EEG electrodes, an accelerometer and a pulse oximeter [1]. As a result, it records metrics such as respiration rate, heart rate, and sleep phase, and provides the user with a hypnogram graphic of sleep data. Through an online analysis, the device anticipates times for sound stimulation at appropriate times to aid user sleep. From the output of the DREEM device, we are able to identify different patterns of brain wave oscillations. In particular, we focus on deep sleep.
Deep sleep, which appears in the first few hours of sleep, is characterized by slow oscillations in EEG measurements, particularly waves with high amplitude and low frequency. Deep sleep was found to be improved by the external inducing of slow oscillation waves, whether through visual, magnetic, or auditory methods.
Framework:
We provide a machine learning framework that takes 10 seconds of EEG measurements made by the DREEM device as input and attempts to predict whether a person will be in a deep sleep state in the next second.
Dataset:
- Our training dataset consists of 261634 data points. Each datapoint consists of the number, mean amplitude and mean duration of previous slow oscillations, amplitude and duration of the current sleep oscillation, sleep stage, time elapsed since falling asleep, time spent in different stages so far (deep, light, rem, wake) and 125Hz frequency EEG signals. Figure X shows examples of data points. Overall, our dataset is represented by a 261634x1261 matrix.
We preprocess our dataset by partitioning each data point into two parts: - EEG vector: a 1250-dimensional vector recording 10 seconds of brain activity.
- Sleep Conditions Vector: a 11-dimensional vector containing features other than EEG data.
We label each data point one of 3 classes: no slow oscillation starting in the following second, a slow oscillation of low amplitude starting in the following second and a slow oscillation of high amplitude starting in the following second.
We provide the following data files to the user:
- mlp-eeg-data: a 261634x1250 matrix encoding 10 seconds of 125Hz EEG data. We use this file to train a multi-layer perceptron model.
- mlp-eeg-pca-data: We apply PCA [cite] to the mlp-eeg-data in order to reduce the number of dimensions in our data. This helps with reducing the signal redundancy while increasing training efficiency.
- Seq-eeg-data: We partition our 261634x1250 matrix into a 261634x10x125 tensor. We basically encode each second as a 125-dimensional vector. This dataset is used for sequence models.
We provide preprocessing scripts in our framework to get these data files. Original data could be find on the challenge’s website. You can emailus at thekej@stanford.edu to get the preprocessed datasets.
Baseline models
We propose 3 baseline models. All code is provided online on https://github.com/thekej/sleep_predictor.git. We provide a pipeline where the user chooses the model type, number and size of hidden layers, number of classes and many other hyper/parameters. All default parameters used are the default parameters in our implementation.
- Multi-Layer Perceptron: A multilayer logistic regressor with intermediate layers, called hidden layers, that has a nonlinear activation function (RELU). We train a 2-layer MLP with a hidden size of 256 as our baseline model.
- LSTM Recurrent Neural Network: Long short-term memory is an artificial recurrent neural network architecture used generally for sequence tasks. As LSTMs are very efficient in processing sequential data, we partition our EEG data into a sequence of 10 vectors each representing measurements taken in one second. We also use the sleep conditions vector as initial hidden state to our model.
- 1D Convolutional Neural Network: Typically used for sequence tasks like sound generation or machine translation , 1D CNNs represent a good alternative to RNN models. We adapt such a model to our EEG data.
Results:
- We partition the provided train set into a training set and a validation set. We use a 90/10% split and evaluate our model on the validation every epoch. We train our models for 10 epochs, i.e. — over 24 hours. Furthermore, we evaluate our models using the test set provided by the challenge.
For each of the three baseline models we report the following results (validation and training accuracy):
- [Baseline Model: Val Accuracy — Test Accuracy]
- 2-layer MLP: 44% — 43.7%
- LSTM: 48.94% — 48%
- 1D CNN: 47.9–47.05%
Our best performing model, the LSTM-based model, achieves a performance accuracy of 48%, which is close to the best performing models in the challenge (around 53%). Even given these results, we insist that our models can perform as well as the best model entries in the challenge, given a parameter search is done. We decide not to continue with hyperparameter optimization, as the goal of this project is not to beat the challenge but to spread awareness of healthy sleep habits and the dangers of sleep deprivation to the CS/AI community.
III. And that’s a wrap
With our foray into using machine learning to analyze sleep tracking device data, the purpose of this post has been to engage both the sleep and computer science research communities. We believe that a computational approach to sleep stage prediction would benefit the sleep community and open doors to new interesting research problems. Continuing on, we provide our framework publicly to whoever is interested in continuing exploration of such a task (refer to Github link above).
We hope that you have enjoyed reading our explanations and learned about 1) the importance of keeping a healthy sleep schedule and 2) the range of technologies available for assisting high-quality sleep.
Cited:
[2] https://www.nhtsa.gov/risky-driving/drowsy-driving
[4] https://support.dreem.com/hc/en-us/articles/360018243411-The-hypnogram-your-night-stage-after-stage
[5] https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5940440/
[6] https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2542492/
[7] https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4608916/
[8] http://www.fortykay.com/2011/08/23/drowsiness-is-red-alert/
NOTE:
- Length of Medium post determined by optimum engagement: https://hackernoon.com/how-long-should-your-medium-posts-be-dbf34be6507d