Fixed-length sleep staging sequence global correction method based on dynamic programming
By constructing a dual cost function and a valid transition matrix through dynamic programming, the problems of cascading errors, length incompatibility, and insufficient robustness in the smooth correction of sleep stage sequences are solved, thus achieving efficient and accurate sleep quality assessment.
Patent Information
- Application Number
- CN202512029190.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-30
- Publication Date
- 2026-02-27
AI Technical Summary
Existing sleep staging sequence smoothing correction techniques suffer from problems such as cascading errors, sequence length incompatibility, lack of cost trade-offs, and insufficient robustness, which affect the accuracy and efficiency of sleep quality assessment.
Using dynamic programming, a dual cost function and a valid transition matrix are constructed. By using state matching cost and transition validity cost, a global cumulative cost model is built to generate a globally optimal corrected sequence, ensuring that the corrected sequence conforms to physiological rules and closely resembles the original annotation.
It achieves globally optimal correction, avoids cascading errors, adapts to clinical standards, improves correction efficiency, reduces erroneous corrections, enhances robustness, and ensures the accuracy of sleep quality assessment.
Smart Images

Figure CN121580210A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of biomedical engineering and signal processing, and discloses a global correction method for a fixed-length sleep staging sequence based on dynamic programming. BACKGROUND
[0002] The current sleep staging sequence smoothing correction technology has the following problems, which limit the clinical applicability and correction effect: 1. Chain error risk: using local segment-by-segment verification logic, correcting the current abnormal segment easily causes new illegal transitions in the following, which needs to be iterated repeatedly, and the efficiency is low and it is difficult to ensure global compliance; 2. Sequence length incompatibility: the legal path is completed by inserting / deleting fixed time windows (epochs), which causes the corrected sequence to deviate from the clinical standard of 30 seconds / epoch, and additional calibration is needed, increasing the processing complexity; 3. Lack of trade-off: only physiological rule compliance is considered, original label closeness is ignored, and a unified correction weight is used for different sleep states, which easily miscorrects important states such as N3 and REM, affecting the accuracy of sleep quality evaluation; 4. Lack of robustness: for low signal-to-noise ratio data (such as motion artifact interference EEG), local correction easily accumulates errors, and there is a lack of optimal path screening mechanism from a global perspective. SUMMARY
[0003] In order to solve the above problems, the application provides a global correction method for a fixed-length sleep staging sequence based on dynamic programming, comprising the following steps: Define an original sleep staging sequence, which is divided into several continuous fixed time windows with 30 seconds as the fixed time window, and the target generates a corrected sequence, the number of fixed time windows of the corrected sequence is consistent with the original sequence, only the sleep state value of each fixed time window is corrected, and no fixed time window is added or deleted; Set a sleep state coding rule, which corresponds five sleep states of wakefulness, light sleep 1, light sleep 2, deep sleep, and rapid eye movement sleep to unique digital codes respectively; Construct a legal transition matrix based on sleep physiological rules, which is used to determine whether the transition between any two sleep states is legal, and if the previous state can be legally transferred to the current state, it is marked as legal, otherwise it is marked as illegal; Define a double cost function, including state matching cost and transition legality cost, wherein the state matching cost is used to measure the closeness between the selected sleep state and the original sequence corresponding to the fixed time window label state, and the transition legality cost is used to constrain the physiological compliance of sleep state transition; A dynamic programming cumulative cost model is constructed, each fixed time window is taken as a stage, five sleep states are taken as optional nodes of each stage, and the minimum cumulative cost of selecting a current state in the ith fixed time window is calculated, which is the minimum value in the sum of the cumulative cost of all optional predecessor states of the previous fixed time window, the transition legality cost from the predecessor state to the current state, and the state matching cost of the current state; The dynamic programming table is initialized, according to the physiological law that a human being falls asleep from being awake, the state of the first fixed time window is forcibly set as the awake state, the cumulative cost corresponding to the state is set as 0, and the cumulative cost corresponding to the rest sleep states is set as infinity. The second to the last fixed time window is traversed, for each of the five optional sleep states of each fixed time window, the total cost of each state and all predecessor sleep states is calculated, the minimum value of the total cost is selected to update the cumulative cost of the current state, and the predecessor state corresponding to the minimum value is recorded; Starting from the last fixed time window, the optimal sleep state of each fixed time window is determined in reverse based on the recorded predecessor state, and finally a globally optimal correction sequence is generated.
[0004] Preferably, the specific rules of the legal transition matrix are: the awake state can only be transferred to the awake state or the light sleep 1 period; the light sleep 1 period can be transferred to the awake state, the light sleep 1 period or the light sleep 2 period; the light sleep 2 period can be transferred to the awake state, the light sleep 1 period, the light sleep 2 period, the deep sleep period or the rapid eye movement sleep period; the deep sleep period can only be transferred to the light sleep 2 period or the deep sleep period; and the rapid eye movement sleep period can be transferred to the awake state, the light sleep 2 period or the rapid eye movement sleep period.
[0005] Preferably, the setting rules of the state matching cost are: if the currently selected sleep state is consistent with the labeled state of the corresponding fixed time window of the original sequence, the state matching cost is 0; if the currently selected sleep state is the awake state or the light sleep 1 period and is inconsistent with the original labeled state, the state matching cost is 1; if the currently selected sleep state is the light sleep 2 period and is inconsistent with the original labeled state, the state matching cost is 2; and if the currently selected sleep state is the deep sleep period or the rapid eye movement sleep period and is inconsistent with the original labeled state, the state matching cost is 3.
[0006] Preferably, the setting rules of the transition legality cost are: if the transition from the previous state to the current state is determined to be legal according to the legal transition matrix, the transition legality cost is 0; and if it is determined to be illegal, the transition legality cost is set as a maximum value 1000.
[0007] Preferably, the total cost in step 7 is calculated as the sum of the accumulated cost of the previous fixed time window predecessor state, the transition legality cost from the predecessor state to the current state, and the state matching cost of the current state.
[0008] Preferably, the specific process of backtracking in step 8 is as follows: first, determine the sleep state with the minimum accumulated cost in the last fixed time window, and take it as the last state of the corrected sequence; then, take the predecessor state corresponding to this state as the optimal state of the second-to-last fixed time window, and proceed in reverse order until the state of the first fixed time window is determined, forming a complete corrected sequence.
[0009] Preferably, when the dynamic programming table is initialized, a predecessor state table is also constructed simultaneously, which is used to record the optimal predecessor state corresponding to each sleep state in each fixed time window. All initial record values are set to -1.
[0010] Preferably, the corrected sequence can be directly connected to the AASM clinical sleep evaluation standard and the existing sleep analysis system without the need for additional length calibration operations.
[0011] Preferably, the method is suitable for wearable sleep monitoring devices based on frontal single-channel electroencephalogram and 6-axis inertial measurement unit.
[0012] Preferably, the method is connected to the signal processing module of the wearable sleep monitoring device, receives the original sleep staging sequence output by the device, and after global correction processing, feeds back the corrected sequence to the device for subsequent sleep quality evaluation.
[0013] Compared with the prior art, the present application has the following advantages: 1. Global optimization, avoiding chain errors, through the global cost accumulation mechanism, the subsequent illegal transition caused by local correction is avoided in advance, without iteration, the correction efficiency is significantly improved (for example, the original sequence [Wake, N3, REM] can be directly optimized to [Wake, N1, N2] without illegal transition); 2. Fixed length, adaptation to clinical standards, strictly maintaining 30 seconds / epoch length, the corrected sequence can be directly connected to the AASM clinical standard and the existing sleep analysis system without additional calibration, reducing the difficulty of device integration; 3. Precise correction, ensuring evaluation accuracy, setting high matching cost for important states such as N3 and REM, reducing false correction, clinical tests show that the N3 state correction accuracy is significantly higher than that of traditional methods, and the sleep quality evaluation error is controlled at a low level; 4. Strong robustness, adaptation to low-quality data, for low signal-to-noise ratio data such as motion artifacts, the global cost model can select the optimal compliant path, even if the local labeling error is large, it can still ensure that the sequence conforms to the sleep physiological cycle, and the illegal transition rate is greatly reduced. Attached Figure Description
[0014] Fig. 1 This is the overall flowchart of the present invention; Fig. 2 This is a flowchart illustrating the reverse tracing process of the present invention. Fig. 3 This is a flowchart illustrating the dynamic programming execution process of this invention. Fig. 4 The diagram below shows the design block of the dual cost function of this invention. Detailed Implementation
[0015] Please refer to Figs. 1 to 4 This invention addresses the core requirements of not adding or deleting epochs, only correcting states, globally conforming to physiological transition rules, and closely resembling the original annotations. It introduces the concept of dynamic programming (DP) to transform the sleep stage sequence correction into a multi-stage optimal path problem: taking each epoch as a stage and five sleep states as stage selectable nodes, a global cumulative cost model is constructed by defining a dual cost function of state matching cost + transition legality cost. The minimum cost path from the initial Wake state to the final epoch is then solved, and this path is the globally optimal correction sequence.
[0016] Key definitions and constraints:
[0017] Core cost function design: The cost function is the core innovation of this invention. Through differentiated weight design, it balances the dual objectives of physiological compliance and close resemblance to the original annotation. 1. State matching cost : The state k selected in the i-th epoch is compared with the original label The matching cost is adjusted by assigning differentiated weights based on the clinical importance of sleep states to avoid incorrectly correcting important states: When States[k] = sᵢ =0 (complete match, no cost); when And when they do not match, =1 (normal state, low correction cost); when And when they do not match, =2 (core transition state, moderate correction cost); when And when they do not match, =3 (Important functional state, high cost of correction).
[0018] 2. The cost of transferring legitimacy Forced avoidance of illegal physiological transfers; legal transfers have a cost of 0, illegal transfers are assigned a maximum value (1000), ensuring that there are no illegal transfers in the optimal path: =0, if = 1; = 1000, if = 0.
[0019] 3. Cumulative cost : The minimum cumulative cost from the 1st epoch to the i-th epoch when the k-th state is selected in the i-th epoch, calculated by: .
[0020] Dynamic programming execution flow: 1. DP table initialization: (The 1st epoch is Wake, and the cost is 0), The initial state is illegal, and the cost is infinite); Build the predecessor state table , record the minimum cost corresponding to the predecessor state.
[0021] 2. DP table filling: traverse the 2nd to nth epoch, for each epoch, calculate the total cost of the 5 kinds of optional states with all the predecessor states, select the minimum value to update , and record the optimal predecessor.
[0022] 3. Optimal path backtracking: starting from the nth epoch, trace back through the prev table to find the optimal state of each epoch, and finally generate the correction sequence .
Claims
1. A dynamic programming based global correction method for fixed length sleep staging sequence, characterized in that, The method comprises the following steps: defining an original sleep staging sequence, which is divided into a plurality of continuous fixed time windows with a fixed time window of 30 seconds, generating a target modified sequence, the number of fixed time windows of the modified sequence being consistent with that of the original sequence, and only modifying the sleep state value corresponding to each fixed time window without adding or deleting the fixed time window; setting a sleep state coding rule, in which five sleep states, i.e. wakefulness, light sleep stage 1, light sleep stage 2, deep sleep stage and rapid eye movement sleep stage, are respectively corresponding to unique digital codes; constructing a legal transition matrix based on sleep physiological rules, which is used to define whether the transition between any two sleep states is legal, and is marked as legal if the previous state can be legally transferred to the current state, otherwise is marked as illegal; defining a double cost function, including a state matching cost and a transition legality cost, wherein the state matching cost is used to measure the closeness between the selected sleep state and the labeled state of the corresponding fixed time window of the original sequence, and the transition legality cost is used to constrain the physiological compliance of sleep state transition; constructing a dynamic programming cumulative cost model, taking each fixed time window as a stage, and five sleep states as selectable nodes of each stage, calculating the minimum cumulative cost when the current state is selected in the ith fixed time window, and the cumulative cost is the minimum value in the sum of the cumulative cost of all selectable predecessor states of the previous fixed time window, the transition legality cost from the predecessor state to the current state and the state matching cost of the current state; initializing the dynamic programming table, according to the physiological law that human beings fall asleep from wakefulness, forcibly setting the state of the first fixed time window as the wakefulness state, setting the cumulative cost corresponding to the state as 0, and setting the cumulative cost corresponding to the remaining sleep states as infinity; iterating through the second to the last fixed time window, for each of the five selectable sleep states of each fixed time window, calculating the total cost corresponding to all predecessor sleep states, selecting the minimum value of the total cost to update the cumulative cost of the current state, and recording the predecessor state corresponding to the minimum value; starting from the last fixed time window, based on the recorded predecessor state, the optimal sleep state of each fixed time window is determined in reverse, and finally the globally optimal modified sequence is generated.
2. The method of claim 1, wherein, The specific rules of the legal transition matrix are as follows: the wakefulness state can only be transferred to the wakefulness state or the light sleep stage 1; the light sleep stage 1 can be transferred to the wakefulness state, the light sleep stage 1 or the light sleep stage 2; the light sleep stage 2 can be transferred to the wakefulness state, the light sleep stage 1, the light sleep stage 2, the deep sleep stage or the rapid eye movement sleep stage; the deep sleep stage can only be transferred to the light sleep stage 2 or the deep sleep stage; and the rapid eye movement sleep stage can be transferred to the wakefulness state, the light sleep stage 2 or the rapid eye movement sleep stage.
3. The method of claim 1, wherein, The setting rule of the state matching cost is: if the current selected sleep state is consistent with the labeled state of the original sequence corresponding to the fixed time window, the state matching cost is 0; if the current selected sleep state is the wake state or the light sleep 1 period and is inconsistent with the original labeled state, the state matching cost is 1; if the current selected sleep state is the light sleep 2 period and is inconsistent with the original labeled state, the state matching cost is 2; if the current selected sleep state is the deep sleep period or the rapid eye movement sleep period and is inconsistent with the original labeled state, the state matching cost is 3.
4. The method of claim 1, wherein, The setting rule of the transition legality cost is: if the transition from the previous state to the current state is determined to be legal according to the legal transition matrix, the transition legality cost is 0; if it is determined to be illegal, the transition legality cost is set to the maximum value 1000.
5. The method of claim 1, wherein, The calculation method of the total cost in step 7 is: the sum of the accumulated cost of the previous fixed time window precursor state, the transition legality cost of the precursor state to the current state and the state matching cost of the current state.
6. The method of claim 1, wherein, The specific process of the backward tracing in step 8 is: first, determine the sleep state with the minimum accumulated cost in the last fixed time window as the last state of the corrected sequence; then take the precursor state corresponding to the state as the optimal state of the second last fixed time window, and sequentially deduce forward until the state of the first fixed time window is determined, to form a complete corrected sequence.
7. The method of claim 1, wherein, When the dynamic programming table is initialized, the precursor state table is constructed synchronously, which is used to record the optimal precursor state corresponding to each sleep state in each fixed time window, and all the initial state recording values are set to -1.
8. The method of claim 1, wherein, The corrected sequence can be directly connected to the AASM clinical sleep evaluation standard and the existing sleep analysis system without additional length calibration operation.
9. The method of claim 1, wherein, The method is suitable for a wearable sleep monitoring device based on the forehead single-channel electroencephalogram and the 6-axis inertial measurement unit.
10. The method of claim 9, wherein, The method is connected with the signal processing module of the wearable sleep monitoring device, receives the original sleep staging sequence output by the device, and feeds back the corrected sequence after global correction processing to the device for subsequent sleep quality evaluation.