betaFeedback

WorksAgricultural and Biological Sciences

Duration-Aware World Models for Sleep Staging with Dwell-Time Constraints

Abstract

Closed-loop neuromodulation requires sleep staging that respects stage-specific minimum dwells: stimulation policies switch by sleep stage, and a policy change is permitted only after the current stage has persisted for its minimum duration. Discriminative classifiers fragment stage trajectories—for example, a 30 s Wake segment inside a 10 min N2 run—and even hidden semi-Markov smoothing leaves 11.3% of segments below the minimum dwell threshold. This paper presents a world model in which a recurrent state-space model (RSSM) learns dwell structure endogenously from EEG, via duration-aware latent sampling, a survival-curve dwell prior, and transition-matrix calibration, and a trajectory-level hard-constraint layer guarantees the minimum dwell at decoding. On SHHS-1 (200 subjects, 160/20/20, three repeated splits), the model reaches a test accuracy of 0.690 +/- 0.053 (95% CI over 3 folds) versus 0.641 +/- 0.042 for an identically split discriminative baseline, with macro-F1 +17.5 pp and better accuracy on all three folds. On Sleep-EDF the constraint layer cuts below-threshold segments from 71.8% to 0.1% with no accuracy loss (0.734 to 0.737), and an online locked scheduler reduces RL policy switches by 87% per night while keeping every policy run at least 90 s. To the best of the author's knowledge, this is the first system to couple learned dwell statistics with a decoding-time hard guarantee. Code and pretrained weights will be released.

Introduction

Real-time closed-loop neuromodulation systems modulate stimulation in response to the instantaneous sleep stage: different stages call for different stimulation policies, and an RL policy selected for a given stage is trained for that stage’s dynamics. The stage sequence produced by the sensing subsystem therefore acts as a switching signal. A key requirement in this setting is dwell-time stability: each stage must persist for a minimum duration before the system is allowed to switch policies; otherwise the controller chatters between policies on noisy boundaries. In practice, stage-specific minima differ: N2 is expected to last minutes, whereas N1 and REM transitions are shorter, and the operator needs a guarantee that no stage run falls below its minimum.

Current sleep staging systems are discriminative: they map each 30 s EEG epoch to a stage. State-of-the-art networks such as U-Time [1], DeepSleepNet [2] and SleepTransformer [3] achieve high epoch-wise accuracy, yet their output trajectories are fragmented, containing many 1–2 epoch runs that violate physiological and application-level dwell constraints. Post-processing with hidden Markov / semi-Markov models [4, 5] smooths the sequence without hard guarantees: it reduces violations but cannot eliminate them. The discriminative paradigm models each epoch in isolation (or with local context) and has no mechanism to represent or enforce how long a stage should persist.

Sleep is organized on two time scales. On the epoch scale (30 s), each window carries the physiological features that identify a stage, and discriminative networks excel there. On the structural scale (minutes to hours), stages persist for characteristic durations and recur in cycles; it is on this scale that the application-level requirement—a minimum dwell per stage—is defined. Discriminative staging models only the first scale and delegates the second to post-processing. The mismatch matters in closed-loop neuromodulation: switching a stimulation policy is an action taken on the structural scale, so the quantity that matters to the controller is the run-level structure of the stage sequence, not the epoch-level accuracy of its labels.

This paper instead builds on world models [6, 7, 8, 9]. A world model learns a latent dynamical system over the data; given a sleep night, it maintains a latent state that evolves over time and from which the stage and the EEG features can be reconstructed. Because the latent state is generative and temporal, it is well suited to representing dwell structure. A recurrent state-space model (RSSM) is extended with a duration-aware latent sampler: an explicit dwell counter and a continue/switch Bernoulli variable that decides whether the current stage persists or transitions. On top of this, two empirically fitted priors are added—the survival-curve dwell prior and the transition-matrix calibration—and a trajectory-level hard-constraint layer guarantees that every generated run is at least K[s]K[s] epochs for stage ss.

This paper makes three contributions.

  • A generative world model with endogenous dwell structure. The paper shows that a recurrent state-space model (RSSM) trained on EEG can stage sleep while learning dwell structure endogenously, and that under identical data splits it outperforms a discriminative baseline (test accuracy 0.690±0.0530.690 \pm0.053 vs 0.641±0.0420.641 \pm0.042; macro-F1 +17.5 pp; better on all 3 repeated splits).

  • Three progressive mechanisms and a hard constraint layer. Duration-aware latent sampling, a survival-curve dwell prior, and transition calibration bring the dreamed dwell distribution close to physiological statistics without loss of accuracy (val 0.714→0.7230.714 \to0.723); a trajectory-level hard constraint (latent forcing plus run merging) drives below-minimum-dwell segments from 71.8% to 0.1% on Sleep-EDF while accuracy improves from 0.734 to 0.737.

  • Causal online scheduling. An online locked scheduler reduces reinforcement-learning policy switches by 87% per night with every run at least 90 s, showing that the guarantee carries over from batch staging to a causal online controller.

Related Work

Discriminative sleep staging. Automatic sleep staging from single-channel EEG has been approached with convolutional networks [2, 10, 11], sequence models [3], and fully convolutional segmentation networks [1, 12]. These models are trained with per-epoch cross-entropy; temporal consistency is either ignored or handled by post-hoc smoothing (HMM/HSMM) [4, 5]. None of them learns a generative prior over stage runs, and none provides a guarantee on minimum dwell.

World models. World models learn predictive latent representations of environments [6]. The recurrent state-space model (RSSM) of PlaNet/Dreamer [7, 8] and its discrete successors [9, 13] learn a stochastic latent dynamics and train with KL balancing and latent imagination. Transformer world models [14] replace the recurrent core with a transformer. The use of an RSSM for EEG sleep staging has not, to the best of the author’s knowledge, been reported; the closest analogies are recent works using latent dynamics for physiological time series, which remain rare. Score-based generative staging [15] instead samples labels directly from data and, unlike the RSSM, offers no forward rollout in latent space.

Dwell constraints and sequence post-processing. HMM/HSMM approaches impose explicit state-duration models and can encode minimum-dwell as part of the duration distribution [4, 16]. However, the guarantee is probabilistic, and the duration model is a post-hoc prior decoupled from the feature extractor. Here the dwell structure is learned inside the latent dynamics, and the minimum is enforced as a hard constraint at decoding time; the constraint layer itself is model-agnostic: it applies to the output of any staging system, as demonstrated on discriminative outputs in § 4.6.

Method

Problem setting

A night is a sequence of 30 s EEG epochs. The input window is denoted xt∈R1×3000x_t \in\mathbb{R}^{1 \times3000} (single channel, 100 Hz) and the stage label yt∈{0,…,4}y_t \in\{0, \ldots, 4\} (Wake, N1, N2, N3, REM) following the Rechtschaffen–Kales and AASM conventions [17, 18]. A run (dwell) is a maximal contiguous block of identical stages; its length is the dwell L∈Z≥1L \in\mathbb{Z}_{\ge1} (in epochs). The application constraint is a vector K∈Z≥15K \in\mathbb{Z}_{\ge1}^{5}: every run of stage ss must satisfy L≥K[s]L \ge K[s]. In this paper K={2,2,6,4,4}K = \{2, 2, 6, 4, 4\} for Wake, N1, N2, N3, REM (30 s per epoch).

RSSM backbone

Figure 1 shows the architecture. At a high level, the pipeline reads each 30 s EEG window through an epoch encoder, evolves a latent state along a recurrent GRU core, and reads out both the stage and the band-energy reconstruction from that state; the emitted stage sts_t and its dwell counter dtd_t are fed back into the next step, so a whole night can be rolled out in latent space without observations. Three components are new to sleep staging and are highlighted in Figure 1: the duration-aware sampler that decides continue/switch, the empirical dwell priors (the survival-curve bias and the transition calibration), and the trajectory-level hard-constraint layer; the remaining components follow the standard RSSM design. The RSSM architecture of Hafner et al. [8] is adopted. An epoch encoder (a 1-D convolutional stack) maps xtx_t to an embedding ete_t. A GRU core maintains the recurrent state hth_t; the stochastic state ztz_t is sampled from a Gaussian posterior q(zt∣ht,et)q(z_t \mid h_t, e_t) during training and from the prior p(zt∣ht)p(z_t \mid h_t) when predicting. The stage logits are produced by a classifier over the concatenation [ht,zt,st][h_t, z_t, s_t] where sts_t is the one-hot stage. The model also reconstructs the EEG frequency-band energies (delta, theta, alpha, beta) from [ht,zt,st][h_t, z_t, s_t]; the reconstruction loss anchors the latent state to observable EEG content and prevents posterior collapse. Training uses KL balancing with free bits (0.5/0.2/0.3 for zz, continue, and switch), a linear KL warm-up over 15 epochs, and imagination (when the last LL steps of a sequence are predicted from the prior) ramped from 0 to 20 steps.

Duration-aware RSSM world model

Figure 1. Duration-aware RSSM world model. An epoch encoder maps each 30 s EEG window to an embedding; a GRU core evolves the latent state; the dwell-aware sampler decides continue/switch with a dwell counter dtd_t, guided by empirically fitted priors; the stage head and band-energy decoder read out the stage and the EEG spectrum. A hard dwell constraint guarantees every run is at least K[s]K[s] epochs. Final calibrated model: val/test accuracy 0.723/0.645 on SHHS-1.

Duration-aware latent sampling

Discriminative classifiers treat stages as independent categorical decisions. To represent dwell structure in the latent dynamics, the latent state is augmented with a dwell counter dt∈{0,…,Dmax⁡}d_t \in\{0,\ldots,D_{\max}\} that counts how long the current stage has persisted, and a Bernoulli continue variable ct∈{0,1}c_t \in\{0,1\} that decides whether the current stage persists (ct=1c_t = 1) or a switch is sampled from the stage-prior logits. At every latent step:

ht=GRU⁡([ht−1,zt−1,st−1,e(dt−1)]),μp,σp=pz(ht),μq,σq=qz(ht,et),log⁡p(ct)=cont⁡([ht,st−1,e(dt−1)]),log⁡p(st)=switch⁡([ht]),st=ctst−1+(1−ct)s~t,dt={dt−1+1if st=st−1,1otherwise.(1)\begin{aligned} h_t &= \operatorname{GRU}([h_{t-1}, z_{t-1}, s_{t-1}, e(d_{t-1})]), \\ \mu_p,\sigma_p &= p_z(h_t), \qquad\mu_q,\sigma_q = q_z(h_t,e_t), \\ \log p(c_t) &= \operatorname{cont}([h_t,s_{t-1},e(d_{t-1})]), \\ \log p(s_t) &= \operatorname{switch}([h_t]), \qquad s_t = c_t s_{t-1} + (1-c_t)\tilde{s}_t, \\ d_t &= \begin{cases} d_{t-1}+1 & \text{if } s_t=s_{t-1},\\ 1 & \text{otherwise.} \end{cases} \tag*{(1)} \end{aligned}

During training the continue/switch variables are trained with a soft mixture (the straight-through stage update keeps gradients flowing); during dreaming they are sampled hard. The classifier and decoder then operate on [ht,zt,st][h_t, z_t, s_t] as before. This adds the KL terms KLc\mathrm{KL}_c and KLt\mathrm{KL}_t for the continue and switch distributions, which are annealed with the same schedule as KLz\mathrm{KL}_z.

Empirical dwell prior

The model learns the dynamics from data, but the dwell distribution is heavy-tailed and the continue logit is weakly supervised (only through the switching boundaries). An empirical prior fitted from the training labels is therefore injected: for each stage ss, the survival function of real dwells Ss(d)=P(Ls≥d)S_s(d) = P(L_s \ge d) (Figure 2) is computed and the continue logit bias is set to

Empirical dwell survival curves

Figure 2. Empirical dwell survival curves Ss(d)=P(Ls≥d)S_s(d) = P(L_s \ge d) estimated from the 160 SHHS-1 training subjects; dashed vertical lines mark the application minima KsK_s. REM dwells are the most persistent (SREM(4)=0.71S_{\mathrm{REM}}(4) = 0.71), N1 decays fastest (SN1(20)≈0S_{\mathrm{N1}}(20) \approx0), and N2 carries a heavy tail (SN2(10)=0.28S_{\mathrm{N2}}(10) = 0.28). The continue-logit bias in Eq. (2) is computed from these curves, which is why the prior is non-symmetric across stages.

bs(d)=log⁡Ss(d+1)Ss(d)−Ss(d+1),d=1,…,Dmax⁡,(2)b_s(d) = \log\frac{S_s(d+1)}{S_s(d)-S_s(d+1)}, \qquad d = 1,\ldots,D_{\max}, \tag*{(2)}

which is the empirical log-odds of continuing given the current dwell. The bias is added to the continue logit at every latent step (log⁡p(ct)←log⁡p(ct)+bst−1(dt−1)\log p(c_t) \leftarrow\log p(c_t) + b_{s_{t-1}}(d_{t-1})). This is a zero-parameter injection: the network only learns the residual between the physiology and its own dynamics. A fixed penalty is also applied to the switch logits for N1 (−3.0-3.0) because N1 is rare (≈3.1%\approx3.1\% of epochs) and the model otherwise over-generates it.

Transition-matrix calibration

The switch distribution is also weakly supervised; the empirical transition-target distribution P^(t∣s)\hat{P}(t \mid s) is estimated from the training labels and used to calibrate the switch logits by

bias⁡(s,t)=log⁡P^(t∣s)1/4,(3)\operatorname{bias}(s,t) = \log\frac{\hat{P}(t \mid s)}{1/4}, \tag*{(3)}

i.e., the log ratio to a uniform target. This corrects systematic flow errors that a single scalar penalty cannot address, such as the over-transfer from N2 to REM, and restores the N3 frequency (N3 segments were being absorbed by REM in the dwell-prior variant).

Trajectory-level hard constraint

Two complementary layers enforce the minimum dwell K[s]K[s] at decoding time, without retraining:

  • Latent forcing: during dreaming, if the current stage ss has dwell d<K[s]d < K[s], the continue variable is forced to ct=1c_t = 1 (no switch is sampled). This guarantees, inside the latent trajectory, that every run is at least K[s]K[s].

  • Run merging (observation layer): for any produced sequence (argmax or dreamed), every run shorter than K[s]K[s] is merged into its adjacent run (in AASM style, the shorter run is relabeled to the stage of the longer neighboring run, or to the right neighbor on a tie). This is model-agnostic and can also be applied to discriminative outputs.

The latent forcing is exact for generated trajectories; the merging rule is exact for any trajectory of finite length and never creates new violations. Algorithm 1 summarizes the dreaming procedure with latent forcing.

Algorithm 1 Dream with hard dwell constraint

Require: initial latent state (h,z,s,d)(h, z, s, d); minimum dwells K[s]K[s]

Ensure: stages s1,…,sTs_1, \ldots, s_T with every run at least K[s]K[s] epochs

  1. for t=1…Tt = 1 \ldots T do

  2. update ht,zth_t, z_t via Eq. (1)

  3. if dt−1<K[s]d_{t-1} < K[s] then

  4. force ct=1c_t = 1 ▷ no switch is sampled

  5. else

  6. ct∼Bernoulli⁡(σ(cont⁡))c_t \sim\operatorname{Bernoulli}(\sigma(\operatorname{cont}))

  7. end if

  8. if ct=0c_t = 0 then

  9. st∼Cat⁡(switch⁡)s_t \sim\operatorname{Cat}(\operatorname{switch}); dt=1d_t = 1

  10. else

  11. st=st−1s_t = s_{t-1}; dt=dt−1+1d_t = d_{t-1} + 1

  12. end if

  13. end for

  14. return s1,…,sTs_1, \ldots, s_T

Training objective

Building on the variational auto-encoding objective [19], the full objective is

L=CE⁡(logits⁡,y)+λrecMSE⁡(r,E(x))+β(t)(KL⁡z+KL⁡c+KL⁡t)(4)L = \operatorname{CE}(\operatorname{logits}, y) + \lambda_{\mathrm{rec}}\operatorname{MSE}(r, E(x)) + \beta(t)\left(\operatorname{KL}_z + \operatorname{KL}_c + \operatorname{KL}_t\right) \tag*{(4)}

where the first term is the stage-classification cross-entropy, the second term is the band-energy reconstruction weighted by λrec=0.3\lambda_{\mathrm{rec}} = 0.3, β(t)\beta(t) is the annealed KL weight, and the KL terms use free bits. Class imbalance is handled with inverse-frequency class weights. Training uses Adam (lr = 10−310^{-3}, weight decay 10−410^{-4}, batch size 32, sequence length 100 epochs (50 min, stride 50), for 60 epochs with early stopping on validation accuracy.

Experiments

Data and preprocessing

SHHS-1 [20] is the first cohort of the Sleep Heart Health Study; the full cohort contains 5,793 recordings, of which the first 1,000 were converted locally (953 pass quality checks), and the first 200 subjects by ID are taken for this study. EEG (C3-A2, 125 Hz) is downsampled to 100 Hz by FFT resampling and z-scored per 30 s epoch. Labels follow five classes (Wake, N1, N2, N3, REM); stage distribution is highly imbalanced (N1 ≈\approx 3.1%). Subject-level splits: 160 train / 20 val / 20 test. For statistical rigor, the split is repeated 3 times with different random permutations (seeds 0–2), and means ±\pm 95% CI are reported (paired across models on the same folds). For cross-dataset evaluation of the constraint layer, Sleep-EDF is used (Expanded FPz-Cz, 32 held-out test nights) [21, 22].

Implementation

All world-model variants share the training protocol of § 3.7: sequence length 100, stride 50, batch 32, 60 epochs, warm-up 15, λrec=0.3\lambda_{\mathrm{rec}} = 0.3, free bits 0.5/0.2/0.3, and imagination ramped to 20. The discriminative baseline is a 1-D convolutional classifier (the same encoder as the world model plus a linear head) trained from scratch under the identical split and 60-epoch budget with sqrt-inverse-frequency class weights. Both models run on a single NVIDIA RTX 4060 Laptop GPU.

Training health and accuracy ablation

Table 1 reports the four-variant ablation. All three KL terms stay in a healthy regime (KLz∈[1.7,2.0]\mathrm{KL}_z \in[1.7, 2.0], KLc∈[0.15,0.19]\mathrm{KL}_c \in[0.15, 0.19], KLt∈[0.27,0.30]\mathrm{KL}_t \in[0.27, 0.30], reconstruction ≈0.25\approx0.25), in contrast to the collapsed training observed when the same architecture was trained on only 47 subjects of Sleep-EDF (not shown). The dwell mechanisms do not degrade accuracy; the final calibrated model reaches val 0.723 and test 0.645.

VersionParamsMechanismVal accTest acc
Base196,557band-energy RSSM baseline0.7140.635
+Dwell sampling227,103+ duration-aware sampling0.7130.633
+Dwell prior227,103+ dwell survival prior & N1 penalty0.7210.633
+Trans. calibration227,103+ transition-matrix calibration0.7230.645

Table 1. Ablation of the world-model mechanisms (val/test accuracy, SHHS 160/20/20, 60 epochs, identical budget).

Discriminative baseline under identical conditions

Table 2 compares the world model to the discriminative baseline under the identical subject split and training budget.

ModelVal accTest accF1κ\kappa
Calibrated RSSM (world model)0.7230.6450.6000.533
Discriminative baseline0.6240.5200.4010.322

Table 2. Single main split (seed-consistent with Table 1): world model vs discriminative baseline, same 160/20/20 split, same 60-epoch budget, both from scratch.

On this single split the world model outperforms the baseline by 12.5 pp in test accuracy and by 19.9 pp in macro-F1 (0.600 vs 0.401; the baseline’s N1 recall is only 0.043). Averaged over the 3 repeated splits (Table 3) the gap is +4.9 pp in accuracy and +17.5 pp in macro-F1: the world model is better on every fold (differences +1.1, +7.1, +6.4 pp). A paired tt-test gives t=2.59t = 2.59 (df=2df = 2, p≈0.12p \approx0.12); with three folds the test has limited power, but the direction is consistent and the F1 gap is large.

ModelTest accF1κ\kappa
Calibrated RSSM (world model)0.690 ± 0.0530.637 ± 0.0560.593 ± 0.070
Discriminative baseline0.641 ± 0.0420.462 ± 0.0850.468 ± 0.074
Paired diff (RSSM − base)+0.049, t=2.59t = 2.59 (p≈0.12p \approx0.12)——

Table 3. Repeated-split analysis (3 folds, mean ± 95% CI, paired on identical folds). The calibrated RSSM is early-stopped at 40 epochs (best validation at ≈ ep. 31) owing to its higher per-epoch cost, while the baseline trains for 60 epochs; both models are early-stopped on validation, and the main single-split comparison (Table 2) trains both for the full 60 epochs.

Dream quality: dwell distribution vs physiology

Because the model is generative, synthetic nights can be dreamed by unrolling the latent dynamics without observations. Table 4 reports the mean dwell (in epochs) of dreamed trajectories over 20 test subjects × 80 steps, pooled over 3 dream seeds for reproducibility, versus the real statistics of SHHS-1 (Figure 3). The last column reports the earth-mover distance (EMD) between the calibrated dreamed and real run-length distributions; REM is not evaluable because the 80-step real windows contain no REM runs in this subset. Run-length statistics and survival curves are truncated at Dmax⁡=60D_{\max} = 60 epochs (30 min), a horizon well beyond the longest physiological stage run.

Mean dreamed dwell per stage for Dwell, Prior, Calib, and real SHHS-1 statistics

Figure 3. Mean dreamed dwell per stage (Dwell/Prior/Calib) vs real SHHS-1 statistics (20 test subjects ×\times 80 steps, 3 dream seeds pooled). The dwell-prior variant lengthens the N2 right tail (P90 27 vs 14 real); the calibrated model restores the N3 frequency (N3 segments 51 →\to 105; REM share 33% →\to 17%) at the cost of fragmented Wake runs (mean 7.8 vs 15.1 real). Real REM dwell is not available in this subset.

Calibration corrects the N3/REM trade-off that the dwell prior introduces (N3 segments 51→105, REM share 33% → 17%) but fragments Wake runs (mean 7.8 vs 15.1 real). N1 remains over-generated (121 dreamed runs vs 15 real): N1 is rare and its EEG is close to Wake, so the model cannot separate it reliably; this is revisited in the Discussion.

Hard constraint vs soft post-processing

The constraint layer is evaluated on Sleep-EDF (32 test nights) where the argmax of the discriminative baseline (§ 4.4) is used as the base sequence (the constraint is model-agnostic). With K={2,2,6,4,4}K = \{2, 2, 6, 4, 4\}, Table 5 shows that the raw argmax violates the minimum dwell on 71.8% of runs, HSMM Viterbi smoothing [5] still leaves 11.3%, while the run-merging constraint reduces violations to 0.1% and improves accuracy (0.734 →\to 0.737). On dreamed SHHS-1 trajectories the latent forcing achieves 0 violations on all 5 stages. Figure 4 illustrates the effect on one test night: the raw argmax fragments the hypnogram with frequent 1–2 epoch runs, and the hard constraint restores a smooth, expert-like trajectory (below-KK: 30 →\to 0 runs on this segment; the expert labels themselves contain 2).

Sleep-stage trajectory showing expert labels, RSSM argmax, and hard dwell constraint

Figure 4. Sleep-stage trajectory on one Sleep-EDF test night (SC4001, 240 epochs): expert labels vs raw RSSM argmax (fragmented) vs the same output after the hard dwell constraint. The constraint removes all below-KK runs (30 → 0 on this segment) while preserving the macro structure.

MethodAccBelow-KK runsNote
Raw argmax (no constraint)0.73471.8%fragmented
HSMM Viterbi (soft)0.77111.3%still violates
Hard constraint0.7370.1%accuracy up

Table 5. Below-minimum-dwell (KK) segments on Sleep-EDF 32 test nights. Soft = HSMM Viterbi; hard = run-merging constraint.

Figure 5 complements Table 4 with the full dwell survival curves of the dreamed trajectories (3 dream seeds pooled): the model reproduces the fast N1 decay and the N2 heavy tail, while Wake runs remain over-generated and over-fragmented (Table 4). The transition-matrix calibration of § 3.5 is visualized in Figure 6: the calibrated transition frequencies move toward the empirical target at the main over-transfer bottlenecks (W→N1W \to N1 from 0.73 to 0.43, versus 0.49 empirically; N2→REMN2 \to REM from 0.42 to 0.22, versus 0.11), whereas the dwell-prior trajectories over-transfer into N1 and REM; a residual N3-row bias remains (N3→N2N3 \to N2 0.56 vs 0.90). The training health of the 60-epoch run discussed in § 4.3 is reported in Figure 7: the three KL terms anneal from a high start without collapsing, reconstruction error drops to ≈0.25\approx0.25, and validation accuracy converges smoothly.

StageDwellPriorCalibRealEMD
W4.25.97.815.17.3
N25.39.04.55.61.2
N37.75.39.26.33.0
REM6.410.48.4—n/a

Table 4. Mean dreamed dwell (epochs) vs real SHHS-1 statistics (20 test subjects ×\times 80 steps, 3 dream seeds pooled), plus the earth-mover distance (EMD, epochs) between the calibrated dreamed and real run-length distributions.

Dwell survival curves per stage for real versus dreamed trajectories

Figure 5. Dwell survival curves Ss(d)=P(Ls≥d)S_s(d) = P(L_s \ge d) per stage for the real SHHS-1 test labels (solid) versus unconstrained calibrated-model dreamed trajectories (dashed), over 20 test subjects ×\times 80 steps, 3 dream seeds pooled. The model matches the fast N1 decay and the N2 heavy tail; Wake runs remain over-generated and over-fragmented, the known failure mode quantified in Table 4.

Transition-matrix calibration

Figure 6. Transition-matrix calibration. From left to right: the empirical transition-target distribution P^(t∣s)\widehat{P}(t \mid s) estimated from the 160 SHHS-1 training labels (self-loops excluded, rows normalized); the switch frequencies observed in the dwell-prior dreamed trajectories (no calibration); and those in the calibrated trajectories (calibrated by Eq. (3)), all pooled over 3 dream seeds. Calibration corrects the main over-transfers of the dwell-prior variant (W→\toN1 0.73→\to0.43 vs 0.49 empirical; N2→\toREM 0.42→\to0.22 vs 0.11) at the cost of residual N3-row bias (N3→\toN2 0.56 vs 0.90).

Training health of the calibrated world model on SHHS-1

Figure 7. Training health of the calibrated world model on SHHS-1 (60 epochs, identical hyper-parameters as Table 1). (a) Latent-space KL terms KLz,KLc,KLt\mathrm{KL}_z,\mathrm{KL}_c,\mathrm{KL}_t anneal and stabilize in the healthy regime; (b) band-energy reconstruction and stage cross-entropy converge; (c) training and validation accuracy rise steadily, matching the reported val 0.723.

Closed-loop simulation

The online closed-loop controller is simulated on Sleep-EDF 32 nights: epochs arrive one at a time, and a causal locked scheduler commits to a stage only after its candidate has accumulated ≥K[cand]\ge K[\mathrm{cand}] epochs; once committed, the stage is locked for K[s]K[s] epochs before a switch is considered. Table 6 compares the resulting policy-switch statistics, and Algorithm 2 formalizes the scheduler. The locked scheduler reduces switches from 306 to 41.3 per night (−87%-87\%) with zero below-KK runs and every RL run at least 90 s (3 epochs), at a modest accuracy cost (0.734 →\to 0.687) that reflects the online, causally locked setting.

MethodSwitches/nightBelow-KKAccMin RL run
Raw argmax30671.8%0.734< 30 s freq.
HSMM Viterbi65.611.3%0.771—
Locked scheduler41.30.0%0.687≥90\ge90 s

Table 6. Online locked scheduling on Sleep-EDF 32 nights: the locked scheduler cuts policy switches by 87% with zero below-KK runs and every RL run ≥90\ge90 s.

Algorithm 2 Causal locked scheduling

Require: minimum dwells K[s]K[s]; candidate logits ℓt\ell_t at each epoch tt

Ensure: a causal stage sequence s1,…,sTs_1,\ldots,s_T whose every committed run is at least K[s]K[s] epochs

  1. s←None;c←0;d←0s \leftarrow\mathrm{None};\quad c \leftarrow0;\quad d \leftarrow0 ▷ committed stage, candidate count, locked count

  2. for t=1…Tt = 1\ldots T do

  3. cand←arg⁡max⁡sℓt\mathrm{cand} \leftarrow\arg\max_s \ell_t ▷ stage-wise posterior at epoch tt

  4. if s=Nones = \mathrm{None} then

  5. &nbsp;&nbsp;&nbsp;&nbsp;if cand≠prev\mathrm{cand} \ne\mathrm{prev} then

  6. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c←1c \leftarrow1

  7. &nbsp;&nbsp;&nbsp;&nbsp;else

  8. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c←c+1c \leftarrow c + 1

  9. &nbsp;&nbsp;&nbsp;&nbsp;end if

  10. &nbsp;&nbsp;&nbsp;&nbsp;prev←cand\mathrm{prev} \leftarrow\mathrm{cand}

  11. &nbsp;&nbsp;&nbsp;&nbsp;if c≥K[cand]c \ge K[\mathrm{cand}] then

  12. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commit: s←cand; d←0s \leftarrow\mathrm{cand};\ d \leftarrow0

  13. &nbsp;&nbsp;&nbsp;&nbsp;end if

  14. else

  15. &nbsp;&nbsp;&nbsp;&nbsp;d←d+1d \leftarrow d + 1

  16. &nbsp;&nbsp;&nbsp;&nbsp;if d≥K[s]d \ge K[s] and cand≠s\mathrm{cand} \ne s then

  17. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch: s←cand; d←0s \leftarrow\mathrm{cand};\ d \leftarrow0

  18. &nbsp;&nbsp;&nbsp;&nbsp;end if

  19. end if

  20. emit ss ▷ RL policy follows the locked stage

  21. end for

  22. return s1,…,sTs_1,\ldots,s_T

Discussion

Relation to published results. Published systems trained on the full SHHS-1 cohort reach higher epoch-wise accuracy: SleepTransformer [3] reports 87.7% accuracy and κ=0.828\kappa= 0.828 on 70%/30% subject splits over 5,791 subjects, and other sequence models report similar levels. The numbers reported here are not directly comparable, for three reasons: (i) data scale—those systems train on the full cohort (5,791 subjects, versus the 200 used here); (ii) training budget—SleepTransformer is trained with an extensive validation-driven early-stopping protocol, whereas the protocol used here trains for 60 epochs with early stopping (a substantially smaller budget); and (iii) model size—the RSSM used here is a lightweight GRU-based model with 227K parameters. This paper does not aim to compete on epoch-wise accuracy; the focus is on whether a generative world model can learn dwell structure and guarantee stage-specific minimum dwells at decoding time without retraining. Under identical splits and budgets the world model still outperforms its discriminative counterpart (Table 3), and the constraint layer is model-agnostic: it can be applied on top of any staging system, including those with higher epoch-wise accuracy.

Advantage over the baseline. Under identical data splits the largest gap is in macro-F1: the discriminative baseline collapses on the rare N1 class (recall 0.043), whereas the RSSM carries temporal and generative context that helps the rare and ambiguous classes, and the dwell mechanisms provide structural inductive bias. This is consistent with the failure mode reported in § 4.3: on 47 subjects of Sleep-EDF the same RSSM training collapsed, while 200 subjects of SHHS-1 train healthily; the base RSSM in Table 1 trains healthily as well, so the difference in training outcomes is driven by data scale.

Guarantees vs statistics. The hard constraint is exact at the trajectory level; the statistical distribution of dreamed dwells is right-shifted relative to physiology (a necessary consequence of imposing a minimum). For a closed-loop operator a guaranteed minimum is more useful than an exactly matched distribution; on the evaluated nights run merging even improves accuracy slightly (0.734 to 0.737, Table 5).

Limitations and generalization. Out-of-domain generalization remains the central limitation: the model is trained and evaluated on in-domain SHHS recordings only, and deployment on a new hospital, device, or unseen subject would require domain adaptation or subject-specific personalization, which this paper does not address. N1 remains over-generated in every reported setting (Table 4). The repeated-split CI is limited to 3 folds by RSSM training cost (≈5 h/fold); a larger number of folds would tighten the CI. Dream quality is evaluated by dwell statistics and run-length EMD (Table 4); spectral FID of dreamed EEG is left to future work.

Conclusion

The experiments show that a generative world model can stage sleep while learning dwell structure from data, without relying on post-hoc smoothing. Dreamed trajectories match physiological dwell statistics, a trajectory-level hard constraint reduces below-KK segments from 71.8% to 0.1%, and an online locked scheduler cuts policy switches by 87% per night (every run at least 90 s). Under identical data splits the world model also beats a discriminative baseline by a consistent margin (test accuracy 0.690 ±\pm 0.053 vs 0.641 ±\pm 0.042, macro-F1 +17.5 pp, better on all 3 repeated splits).

References

  1. [1]M. Perslev, M. H. Jensen, S. Darkner, P. J. Jennum, and C. Igel. U-time: A fully convolutional network for time series segmentation applied to sleep staging. In Advances in Neural Information Processing Systems (NeurIPS), 2019.arxiv.org/abs/1910.11162
  2. [2]A. Supratak, H. Dong, C. Wu, and Y. Guo. Deepsleepnet: A model for automatic sleep stage scoring based on raw single-channel EEG. IEEE Transactions on Neural Systems and Rehabilitation Engineering, 25(11):1998–2008, 2017.DOI
  3. [3]H. Phan, K. Mikkelsen, O. Y. Chen, P. Koch, A. Mertins, and M. De Vos. Sleeptransformer: Automatic sleep staging with interpretability and uncertainty quantification. IEEE Transactions on Biomedical Engineering, 69(8):2456–2467, 2022.DOI
  4. [4]L. R. Rabiner. A tutorial on hidden Markov models and selected applications in speech recognition. Proceedings of the IEEE, 77(2):257–286, 1989.
  5. [5]A. Flexer, G. Gruber, and G. Dorffner. A reliable probabilistic sleep stager based on a single EEG signal. Artificial Intelligence in Medicine, 33(3):199–207, 2005.pubmed.ncbi.nlm.nih.gov/15811785
  6. [6]D. Ha and J. Schmidhuber. World models. arXiv preprint arXiv:1803.10122, 2018.DOI
  7. [7]D. Hafner, T. Lillicrap, I. Fischer, R. Villegas, D. Ha, H. Lee, and J. Davidson. Learning latent dynamics for planning from pixels. In Proceedings of the 36th International Conference on Machine Learning (ICML), 2019.arxiv.org/abs/1811.04551
  8. [8]D. Hafner, T. Lillicrap, J. Ba, and M. Norouzi. Dream to control: Learning behaviors by latent imagination. In International Conference on Learning Representations (ICLR), 2020.arxiv.org/abs/1912.01603
  9. [9]D. Hafner, T. Lillicrap, M. Norouzi, and J. Ba. Mastering atari with discrete world models. In International Conference on Learning Representations (ICLR), 2021.arxiv.org/abs/2010.02193
  10. [10]A. Sors, S. Bonnet, S. Mirek, L. Vercueil, and J.-F. Payen. A convolutional neural network for sleep stage scoring from raw single-channel EEG. Biomedical Signal Processing and Control, 42:107–114, 2018.DOI
  11. [11]S. Chambon, M. N. Galtier, P. J. Arnal, G. Wainrib, and A. Gramfort. A deep learning architecture for temporal sleep stage classification using multivariate and multimodal time series. IEEE Transactions on Neural Systems and Rehabilitation Engineering, 26(4):758–769, 2018.DOI
  12. [12]M. Perslev, S. Darkner, L. Kempfner, M. Nikolic, P. J. Jennum, and C. Igel. U-Sleep: resilient high-frequency sleep staging. npj Digital Medicine, 4(1):72, 2021.DOI
  13. [13]D. Hafner, J. Pasukonis, J. Ba, and T. Lillicrap. Mastering diverse domains through world models. arXiv preprint arXiv:2301.04104, 2023.arxiv.org/abs/2301.04104
  14. [14]J. Robine, M. Hoffmann, T. Uelwer, and S. Harmeling. Transformer-based world models are happy with 100k interactions. arXiv preprint arXiv:2303.07109, 2023.arxiv.org/abs/2303.07109
  15. [15]H. van Gorp, M. M. van Gilst, P. Fonseca, F. B. van Meulen, J. P. van Dijk, S. Overeem, and R. J. G. van Sloun. A deep generative model for five-class sleep staging with arbitrary sensor input. arXiv preprint arXiv:2408.15253, 2024.DOI
  16. [16]S.-Z. Yu. Hidden semi-Markov models. Artificial Intelligence, 174(2):215–243, 2010.DOI
  17. [17]A. Rechtschaffen and A. Kales. A Manual of Standardized Terminology, Techniques and Scoring System for Sleep Stages of Human Subjects. Public Health Service, U.S. Government Printing Office, 1968.
  18. [18]R. B. Berry, R. Brooks, C. E. Gamaldo, S. M. Harding, R. M. Lloyd, C. L. Marcus, and B. V. Vaughn. The AASM Manual for the Scoring of Sleep and Associated Events. American Academy of Sleep Medicine, 2.4 edition, 2017.
  19. [19]D. P. Kingma and M. Welling. Auto-encoding variational bayes. In International Conference on Learning Representations, 2014.arxiv.org/abs/1312.6114
  20. [20]S. F. Quan, B. V. Howard, C. Iber, J. P. Kiley, F. J. Nieto, G. T. O’Connor, D. M. Rapoport, S. Redline, J. Robbins, J. M. Samet, et al. The sleep heart health study: Design, rationale, and methods. Sleep, 20(12):1077–1085, 1997.pubmed.ncbi.nlm.nih.gov/9493915
  21. [21]B. Kemp, A. H. Zwinderman, B. Tuk, H. A. C. Kamphuisen, and J. J. L. Oberyé. Analysis of a sleep-dependent neuronal feedback loop: The slow-wave microcontinuity of the EEG. IEEE Transactions on Biomedical Engineering, 47(9):1185–1194, 2000.pubmed.ncbi.nlm.nih.gov/11008419
  22. [22]A. L. Goldberger, L. A. Amaral, L. Glass, J. M. Hausdorff, P. C. Ivanov, R. G. Mark, J. E. Mietus, G. B. Moody, C.-K. Peng, and H. E. Stanley. Physiobank, phys iotoolkit, and physionet: Components of a new research resource for complex physiologic signals. Circulation, 101(23):e215–e220, 2000.

Paper details

vlnc:W_bydax5h2
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Agricultural and Biological Sciences

Not recorded for this paper

View statement
Looking for related papers…
Contents