buzsakilab / buzcode

Code for internal lab sharing - polishing has started but is by no means complete
http://www.buzsakilab.com/
GNU General Public License v3.0
118 stars 128 forks source link

added option for sticky trigger to SleepScoreMaster #284

Closed dlevenstein closed 5 years ago

dlevenstein commented 5 years ago

This update adds the ability for SleepScoreMaster to use a "sticky" trigger for threshold crossings. With a sticky trigger, the signal (i.e. theta/broadbandSlowWave/EMG) has to go halfway between the threshold and the opposite peak to count as a threshold crossing. (see attached schematic)

The effect is to reduces "flickering" noise when one of the metrics barely crosses the threshold and then returns. Instead it must go all the way to the other mode of the distribution to count as a state change. This is especially useful in recordings in which NREM and WAKE/REM are not well separated, for example hippocampal recordings. And reduces flickering during drowsiness at the onset of NREM.

As of now, the default is 'stickytrigger',false. I plan to add a check box to TheStateEditor autoscoring so the user can directly compare the two trigger modes, and hopefully we come to a consensus for what the default should be if one is obviously better. (Note that we could make some metrics be sticky and others be straightforward threshold crossing).

@brendonw1 I'd love it if you could check this out if you have a recording for which the state scoring is particularly noisy. I found it improves some of the harder to score recordings in Andres' dataset. (also let me know if you find that it's introduced any bugs). Others who use TheStateEditor are of course also encouraged to check it out

img_0564

dlevenstein commented 5 years ago

(Note that right now it's very easy to compare by rescoring with the new trigger using SleepScoreMaster(basePath,'stickytrigger',true), as long as you don't have any manual threshold edits. If that's prohibitive, you can wait for TheStateEditor checkbox to compare with the easiest of ease)

brendonw1 commented 5 years ago

Right so like a hysteresis I checked it quickly, but I am further away these days from the recordings and don't have new ones that are bad and also un-scored - especially without manual editing. I may have one coming up from a collaborator - i've noticed some weirdness in their recordings so maybe I'll try it then. But I did try doing it both ways on a recording and no obvious problems, though some differences. I do think it'll be best to see what we think with stickiness toggle boxes on each of the three axes in the autoscore thing.

one question: if the user moves the threshold manually, what will it do?

dlevenstein commented 5 years ago

Yes!

With manual threshold adjusting it adjusts the center threshold, maintains the stickiness with respect to the new threshold and the peaks. Definitely need to give the option to try both so the user can find the cleanest scoring for their particular recording conditions. Will work on the toggle boxes, hopefully tomorrow.

On Jan 15, 2019, at 10:07 PM, Brendon Watson notifications@github.com wrote:

Right so like a hysteresis I checked it quickly, but I am further away these days from the recordings and don't have new ones that are bad and also un-scored - especially without manual editing. I may have one coming up from a collaborator - i've noticed some weirdness in their recordings so maybe I'll try it then. But I did try doing it both ways on a recording and no obvious problems, though some differences. I do think it'll be best to see what we think with stickiness toggle boxes on each of the three axes in the autoscore thing.

one question: if the user moves the threshold manually, what will it do?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

dlevenstein commented 5 years ago

OK!!! The checkboxes are in! You can check to "Sticky" trigger threshold crossing on EMG, SW, THETA independently.

screen shot 2019-01-16 at 4 01 26 pm

Here is an example of the wonders of sticky!

First, the original scoring:

screen shot 2019-01-16 at 4 05 15 pm

Now, with sticky SW threshold (notice the reduction in NREM/WAKE flickering at the onset of NREM)

screen shot 2019-01-16 at 4 05 27 pm

Now, with sticky EMG threshold (notice reduction in REM/WAKE flickering during REM)

screen shot 2019-01-16 at 4 05 35 pm

I'm going to pull this into dev (note, default behavior is still as before), and would love it if you see how it looks on your recordings when you get a chance. Very preliminary what I've found is that Sticky SW and EMG improves detection, while sticky TH actually makes it a little worse. If the consensus is that this improves scoring, I think we should make it default.

raswanson commented 5 years ago

Nice!!

On Jan 16, 2019, at 4:09 PM, Dan Levenstein notifications@github.com wrote:

OK!!! The checkboxes are in! You can check to "Sticky" trigger threshold crossing on EMG, SW, THETA independently. Very preliminary what I've found is that Sticky SW and EMG improves detection, while sticky TH actually makes it a little worse.

Here is an example of the wonders of sticky!

First, the original scoring: https://user-images.githubusercontent.com/7265688/51278440-97978300-19a8-11e9-89c8-ea1664fc59aa.png Now, with sticky SW threshold (notice the reduction in NREM/WAKE flickering at the onset of NREM) https://user-images.githubusercontent.com/7265688/51278459-a4b47200-19a8-11e9-9595-5cc0767fad9d.png Now, with sticky EMG threshold (notice reduction in REM/WAKE flickering during REM) https://user-images.githubusercontent.com/7265688/51278500-c4e43100-19a8-11e9-8369-3c8f7cf3835e.png I'm going to pull this into dev (note, default behavior is still as before), and would love it if you see how it looks on your recordings when you get a chance. If the consensus is that this improves scoring, I think we should make it default.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/buzsakilab/buzcode/pull/284#issuecomment-454942398, or mute the thread https://github.com/notifications/unsubscribe-auth/AWQufGTy4Vw1jMJO-EN3Mg-bq6CcdCTYks5vD5T8gaJpZM4aCK51.