Postprocessing-Enhanced Machine Learning for Reliable Real-Time Sleep Staging in Closed-Loop Neuromodulation
Discuss this preprint
Start a discussion What are Sciety discussions?Listed in
This article is not in any list yet, why not save it to one of your lists.Abstract
Real-time sleep stage classification is important for closed-loop neuromodulation at certain stages during sleep, yet current models often yield noisy and unstable outputs that risk false triggers. These fluctuations, especially near stage boundaries, can compromise the safety and reliability of stimulation. Existing methods frequently rely on model-specific architectures or require extensive tuning to maximize precision, which limits their generalizability and hinders deployment in real-time systems. To address this, we propose a lightweight, classifier-independent post-processing pipeline that stabilizes predictions without modifying the underlying classifier. Our method first applies temporal smoothing to predicted sleep-stage probabilities, followed by conservative control logic to enhance stimulation precision. We evaluate four smoothing techniques: Moving Average (MA), Exponential Smoothing (ES), Kalman Filtering (KF), and a novel Weighted Exponential Smoothing (WES), on a 29-subject open-source sleep dataset. To capture the trade-offs between stability and responsiveness, we introduce new real-time evaluation metrics. We identify an optimal smoothing intensity range and assess three control strategies: probability thresholding, naïve waiting, and entropy constraint, as well as a hybrid method combining high confidence and low uncertainty. Smoothing improves generalization and robustness: under both low and high synthetic noise ( σ > 0.2), smoothed outputs retain 10–15% higher precision and recall across all stages. Control logic further enhances reliability: our hybrid method achieves 80% (Wake), 96% (N2), 98% (N3), and 86% (REM) precision. Finally, we introduce a stage-transition constraint matrix to suppress biologically implausible transitions (e.g., REM→ N3), to further stabilize outputs during evidence accumulation, with potential applications in objective sleep quality assessment. To our knowledge, this is the first study to systematically characterize real-time trade-offs between smoothing, latency, and control logic in sleep staging. Overall, our generalizable framework is expected to improve safety, interpretability, and deployment feasibility of real-time sleep classification for both clinical and wearable closed-loop neuromodulation systems.