Stanford-STAGES / stanford-stages

Automated sleep staging scoring and narcolepsy identification
76 stars 26 forks source link

Query Epoching Process #8

Closed agpr141 closed 4 years ago

agpr141 commented 5 years ago

Hi I am trying out Stanford Stages code for the automated scoring, and am after some clarification on the Epoching of the data.

Can you please point to the parts of the code which divides the data into Epochs and explain how the calculation for epoch removal is made? I think it is within info_hypnodensity / class Hypnodensity/ def trim (line 250). From what I understand, the modulus of the raw data length and resampled data length*30 is calculated. This is then removed from the end of the signal, making the data length exactly divisible into 30second epochs. I would appreciate if you can confirm I have understood this correctly.

Additionally, even though throughout the file it states that the epochs are defaulted and calculated as 30s long, on the hypnogram/hypnodensity they are given as 15s. Where is the disconnect between these two occurring?

Thankyou!

informaton commented 5 years ago

Good questions. Generally speaking, sleep studies are visually scored for sleep stage on consecutive, 30 s intervals or epochs. This 30 s epoch is the accepted convention for most sleep scoring, though it is not based on anything physiological.

In developing the hypnodensity models for diagnosing narcolepsy, we examined the probability of a sleep stage at higher resolutions (e.g. 5, 10, and 15 s), however these still needed to be compared to the gold standard sleep stage scoring that is done by visual inspection of the polysomnography results by a trained technician on a 30 s epoch.

A time resolution of 15 s is used in the final models presented with this version of the program (i.e. the ones available for download using the links in the readme file).

Thus, there is the hypnodensity and the hypnogram which are given in 15 s epochs. The hypnodensity is a probability matrix with rows representing 15 s epochs, and columns representing the probability of wake, sleep stages 1-4, and rapid eye movement (REM) sleep. The hypnogram, here, is a vector of sleep stages which is determined by evaluating the hypnodensity and taking the sleep stage with the highest probability or likelihood at each row (i.e. every 15 s). *Technically speaking the hypnogram is the plot of this vector.

It is possible to change the duration of the hypnodensity output epoch size by adjusting the segment size of the data that is evaluated. However, since the model was trained using 15 s, it is not recommended. Still, for the curious, the 'segsize' variable is listed in the inf_config.py file with the correct value of 60. Segments are 0.25 s in duration, so this results in hypnodensity epochs of 15 s (60*0.25 s) which is the correct duration for these models.

Hope that helps some.