Sleep staging method and storage medium

By combining the KGNN module with the LSTM network, a dynamic graph structure and multi-level feature fusion are constructed, which solves the problems of central rate variability feature correlation and noise influence in existing sleep staging methods, and achieves more accurate sleep staging.

CN121570136APending Publication Date: 2026-02-27ARMY ENG UNIV OF PLA
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202512053199.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-31
Publication Date
2026-02-27

AI Technical Summary

Technical Problem

Existing sleep staging methods struggle to capture the complex physiological relationships between heart rate variability features and are unable to resist the influence of time-varying noise in the original heart rate signal, resulting in insufficient accuracy in sleep staging.

Method used

By combining the KGNN module with the LSTM long short-term memory neural network, a dynamic graph structure is constructed to capture the complex physiological relationships between heart rate variability features. Furthermore, through multi-level feature fusion and temporal modeling, spatial relationship representation and time series modeling are enhanced, thus resisting the influence of time-varying noise.

Benefits of technology

It improves the accuracy and robustness of sleep staging, enabling more precise capture of the causal relationship between heart rate and sleep stages, and provides a more reliable and efficient single-lead heart rate signal sleep monitoring solution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121570136A_ABST
    Figure CN121570136A_ABST
Patent Text Reader

Abstract

The invention discloses a sleep staging method and a storage medium, and belongs to the technical field of sleep staging, and the method comprises the following steps: inputting heart rate data into a pre-constructed sleep staging model according to a time sequence, and sequentially outputting sleep staging results; the sleep staging model comprises a KGNN module, a Sleep MLSTM module, a Sleep SLSTM module and an output module; the KGNN module calculates a context vector according to the heart rate data; the SleepMLSTM module calculates the hidden state of the last time step according to the heart rate data, and adds the hidden state with the context vector to serve as the final output feature of the SleepMLSTM module; the SleepSLSTM module takes the final output feature as an input to generate an output feature; and splicing the final output features of the SleepMLSTM module and the output features of the SleepSLSTM module, and inputting the spliced features into an output module to generate a sleep staging result. The method can solve the problems that an existing sleep staging method is difficult to capture complex physiological correlation between heart rate variability characteristics and is difficult to resist the influence of time-varying noise of original heart rate signals.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of sleep staging technology, specifically relating to a sleep staging method and a storage medium. Background Technology

[0002] Currently, polysomnography (PSG) remains the recognized standard for sleep staging. By recording multiple bodily characteristics such as brain mapping, electrooculography (EOG), muscle activity, and respiratory signals, it is the gold standard for sleep measurement. It offers good reliability and accuracy in providing sleep data. However, it still has several shortcomings: In terms of equipment, signal acquisition involves multiple electrodes connected to an electroencephalogram (EEG) machine via wires, resulting in a bulky, complex, and expensive instrument; in terms of measurement, it requires travel to specialized institutions, and the heavy instruments, numerous sensors, and low comfort level, along with the need for professionally trained personnel, all contribute to this; and in terms of subjects, the presence of poor sleep patterns or measurement in unfamiliar environments can significantly reduce the quality of PSG data.

[0003] When sleep structure is disrupted, heart rate fluctuations exhibit characteristic changes, such as accelerated heart rate fluctuations during wakefulness and a steady decline in heart rate during deep sleep. These abnormal signals can disrupt the integrity of the sleep cycle, leading to abnormal sleep stage transitions. Therefore, heart rate signals provided by wearable devices such as smartwatches offer a new technological approach for sleep staging. Compared to the invasive detection method of traditional polysomnography (PSG) that requires attached electrodes, heart rate acquisition schemes based on photoplethysmography (PPG) technology can achieve continuous monitoring throughout the night simply through skin contact with the wrist.

[0004] Sleep staging, a core technology for assessing sleep quality and neurophysiological state, has always faced the challenge of a weak correlation between physiological signals and sleep stages in its automated detection methods. Previous studies, while attempting to directly input heart rate signals into deep learning models, have overlooked two key scientific issues: first, the nonlinear, time-varying coupling relationship between heart rate and sleep stages makes it difficult for traditional end-to-end modeling to capture its implicit causal relationship; second, raw heart rate signals collected by wearable devices generally contain time-varying noise such as motion artifacts and respiratory interference, easily leading to feature space shifts in direct modeling. These limitations severely restrict the practical application value of wearable technology in sleep medicine. Summary of the Invention

[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide a sleep staging method and storage medium, which solves the problems that existing sleep staging methods have difficulty capturing the complex physiological correlation between heart rate variability features and are difficult to resist the influence of time-varying noise in the original heart rate signal.

[0006] To solve the above-mentioned technical problems, the present invention is implemented using the following technical solution:

[0007] In a first aspect, the present invention provides a sleep staging method, comprising: acquiring heart rate data during sleep and pre-dividing the heart rate data into multiple time windows; inputting the heart rate data of the multiple time windows into a pre-constructed sleep staging model in chronological order, and sequentially outputting the sleep staging results of each time window; wherein the sleep staging model includes: a KGNN module, a SleepMLSTM module, a SleepSLSTM module, and an output module; the KGNN module calculates a context vector that integrates entities and relations based on the heart rate data of the current time window; the SleepMLSTM module calculates a context vector that integrates entities and relations based on the heart rate data of the current time window; the SleepMLSTM module calculates a context vector that integrates entities and relations based on the heart rate data of the current time window; the SleepMLSTM module calculates a context vector that integrates entities and relations based on the heart rate data of the current time window. The hidden state of the SleepMLSTM module at the last time step is calculated, and the hidden state of the SleepMLSTM module at the last time step is added to the context vector to obtain the final output feature of the SleepMLSTM module. The SleepSLSTM module takes the final output feature of the SleepMLSTM module as input to generate the output feature of the SleepSLSTM module. The final output feature of the SleepMLSTM module and the output feature of the SleepSLSTM module are concatenated and input into the output module to generate the sleep staging result of the current time window.

[0008] The aforementioned sleep staging method and the construction process of the sleep staging model, the KGNN module preprocessing includes: dividing each subject's heart rate-sleep label sequence throughout the night into multiple segments according to fixed time windows; the heart rate value at the last time step of the heart rate sequence in each time window is taken as a heart rate entity; each heart rate entity corresponds to a sleep stage label, and each sleep stage label is taken as a sleep stage entity, wherein the sleep stages include Wake stage, N1 stage, N2 stage, N3 stage, and REM stage, and the sleep stage labels include label 0, label 1, label 2, label 3, and label 5; W The N1 phase corresponds to label 0, the N2 phase to label 1, the N3 phase to label 2, and the REM phase to label 5. A correspondence relationship is defined, which indicates that the heart rate value of the heart rate sequence in each time window corresponds to the sleep stage of that time window. Using all heart rate entities and all sleep stage entities as nodes, the heart rate entities and sleep stage label entities are connected by the defined correspondence relationship within the same time window. Temporal relationships are added between heart rate entities in adjacent time windows to continuously model sleep stages, resulting in a knowledge graph for KGNN.

[0009] The aforementioned sleep staging method uses the KGNN module to calculate a context vector that fuses entities and relationships based on heart rate data within the current time window, including:

[0010] Based on a pre-trained KGNN module and a fixed knowledge graph after training, the following processing is performed on heart rate data from multiple time windows:

[0011] Create a corresponding heart rate entity node for the heart rate data of each time window; connect the created heart rate entity node to the basic knowledge graph to establish candidate relationships with sleep stage label entities and temporal relationships of adjacent time windows; iteratively fuse entity features and relationship information through the multi-layer message passing mechanism of the KGNN module; and calculate a context vector that fuses entities and relationships.

[0012] The aforementioned sleep staging method, wherein the SleepMLSTM module calculates the hidden state of the last time step of the SleepMLSTM module based on the heart rate data of the current time window, includes: inputting the heart rate data of the current time window into the SleepMLSTM module, sequentially calculating the final hidden state of each time step of the final LSTM layer within the current time window, and obtaining the final hidden state of the current time window of the final LSTM layer: ;

[0013] In the formula, L is the number of LSTM layers in the SleepMLSTM module; This represents the final hidden state of each time step in the final LSTM layer within the current time window; This is the last time step of the current time window;

[0014] Calculate the value attention features at each time step within the current time window, including calculating the value attention features of the current time window at time t, which includes:

[0015] Based on the final hidden state of the LSTM layer at time t Calculate the query at time t respectively ,key Sum Vector, the formula for calculation is:

[0016] ,

[0017] ,

[0018] ,

[0019] In the formula, , The last time step is The set of time steps for the current time window; , and These are the preset queries. ,key Sum Vector weight matrix; T is the transpose operation;

[0020] Calculate the excitation effect at time t based on the query vector and key vector respectively. and inhibition effect The calculation formula is:

[0021] ,

[0022] ,

[0023] In the formula, The preset excitation effect weight matrix, The preset inhibition effect weight matrix

[0024] Based on the attention value at time t The calculation formula is:

[0025] ,

[0026] In the formula, The preset size of the hidden layer;

[0027] Attention feature of the value at time t The calculation formula is:

[0028] ,

[0029] In the formula, This is a dot product operation;

[0030] Combine the attention features of each time step within the current time window into the final value attention feature in chronological order. The attention feature is the value at time t. It is a time step value attention feature;

[0031] The final hidden state of the current time window of the final LSTM layer. and final value attention features Element-wise summation is used as the candidate output for the current time window of the SleepMLSTM module. The calculation formula is:

[0032] ,

[0033] ,

[0034] In the formula, Attention features are the values ​​at each time step within the current time window;

[0035] Candidate outputs for the current time window of the SleepMLSTM module In the SleepMLSTM module, the hidden state at the last time step is... .

[0036] The aforementioned sleep staging method, wherein adding the hidden state of the SleepMLSTM module at the last time step to the context vector as the final output feature of the SleepMLSTM module, includes:

[0037] The final output characteristics of the SleepMLSTM module in the current time window The calculation formula is:

[0038] ,

[0039] In the formula, The hidden state of the SleepMLSTM module at the last time step; This is the context vector output by the KGNN module.

[0040] In the aforementioned sleep staging method, the SleepSLSTM module takes the final output features of the SleepMLSTM module as input to generate the output of the SleepSLSTM module, including:

[0041] Obtain the final output features of the SleepMLSTM module in the current time window. As input to the SleepSLSTM model in the current time window And the hidden state of the SleepSLSTM model in the previous time window. Cell state in the previous time window using the SleepSLSTM model The SleepSLSTM model in the intermediate state of the previous time window The normalized state of the SleepSLSTM module in the previous time window ;

[0042] Based on the input of the SleepSLSTM model in the current time window The hidden state of the SleepSLSTM model in the previous time window Calculate the input gate of the SleepSLSTM module in the current time window. Forgotten Gate intermediate state and output gate The calculation formula is:

[0043] ,

[0044] ,

[0045] ,

[0046] ,

[0047] In the formula, These are the input weight matrices for the input gate, forget gate, intermediate state, and output gate of the preset SleepSLSTM model, respectively. These are the preset cyclic weight matrices for the input gate, forget gate, intermediate state, and output gate, respectively. These are the bias terms for the preset input gate, forget gate, intermediate state, and output gate, respectively; The sigmoid function is used; tanh() is the hyperbolic tangent activation function.

[0048] Based on the input gate of the SleepSLSTM module in the current time window Forgotten Gate and intermediate state Calculate the stability factor of the SleepSLSTM module in the current time window. Stabilization input gate and stabilization forgetting gate The calculation formula is:

[0049] ,

[0050] ,

[0051] ,

[0052] In the formula, This is the stability factor of the SleepSLSTM module in the previous time window;

[0053] Based on the stability factor of the SleepSLSTM module in the current time window Stabilization input gate and stabilization forgetting gate And the cell state of the SleepSLSTM module in the previous time window. Calculate the cell state of the SleepSLSTM module in the current time window. The calculation formula is:

[0054] ;

[0055] Based on the SleepSLSTM module's stabilization forget gate in the current time window The normalized state in the previous time window Cell state in the current time window and the output gate in the current time window Calculate the normalized state of the SleepSLSTM module in the current time window. and hidden state The calculation formula is:

[0056] ,

[0057] ,

[0058] Output the hidden state of the SleepSLSTM module in the current time window. This serves as the output feature of the SleepSLSTM module within the current time window.

[0059] The aforementioned sleep staging method, wherein the final output features of the SleepMLSTM module and the output features of the SleepSLSTM module are concatenated and input into the output module to generate the output sleep staging result, includes:

[0060] The output module includes a first fully connected layer and a second fully connected layer;

[0061] The final output features of the SleepMLSTM module in the current time window The hidden state of the SleepSLSTM model in the current time window After concatenation, the input is given to the first fully connected layer, activated by ReLU, and then output. ;

[0062] The output of the first fully connected layer Output after the first Dropout layer ;

[0063] The output of the first Dropout layer The output of the second Dropout layer after the second fully connected layer. ;

[0064] The output of the second Dropout layer After Softmax activation, a probability vector is output. For the heart rate data in the current time window, the column index with the highest probability in the corresponding row of the probability vector is found, and the column index is mapped to the corresponding sleep stage label, which is then output as the sleep staging result.

[0065] The aforementioned sleep staging method is characterized in that the process of training the sleep staging model includes: the sleep staging model outputs probability vectors for five sleep stages; a weighted cross-entropy loss is calculated based on the probability vectors, and higher weights are assigned to a minority of classes based on the square root reciprocal of the sample size of each class; backpropagation is performed to calculate the gradient based on the weighted cross-entropy loss calculation result, and gradient clipping is applied to limit the gradient norm within a preset threshold; and the AdamW optimizer is used to update the parameters based on the calculated gradient.

[0066] In the aforementioned sleep staging method, the weighted cross-entropy loss function is calculated using the following formula in the t*th iteration: ,

[0067] In the formula, The parameters in the (t*-1)th iteration , This represents the set of all learnable parameters in the sleep staging model. After training, all learnable parameters are fixed and used as preset parameters for the pre-built sleep staging model. The weight of category c, There are a total of 5 categories c, and the number of samples in each of the 5 categories is as follows: ; The training sample size is defined as the heart rate data of one subject within one time window. Index for sleep stages; For the one-hot encoding of the true label, if the true class of sample n is c, then ,otherwise ; Predict the probability that sample n belongs to class c for the model.

[0068] In a second aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that the program, when executed by a processor, implements the steps of the method described in the first aspect.

[0069] Compared with the prior art, the beneficial effects achieved by the present invention are as follows:

[0070] The sleep staging method of this invention combines KGNN and LSTM (Long Short-Term Memory Neural Network) for sleep staging. KGNN can construct a dynamic graph structure from raw heart rate data, capture the complex physiological correlations between heart rate variability features, and enhance the spatial relationship representation. LSTM, on the other hand, performs time series modeling on this basis, effectively learning the transition patterns of sleep stages and the circadian rhythm throughout the night. The combination of multi-level feature fusion and time series modeling enables the sleep staging method of this invention to more accurately capture the causal relationship between heart rate and sleep stages, resist the influence of time-varying noise in the raw heart rate signal, accurately and effectively extract features, and improve the accuracy of sleep staging.

[0071] Specifically, the SleepXLSTM model used in this invention's sleep staging method is an improvement upon the classic XLSTM architecture, featuring three enhancements to improve sleep staging performance based on a single heart rate signal. First, a Knowledge Graph Neural Network (KGNN) module is introduced, embedding prior knowledge of sleep labels corresponding to heart rate values ​​as relationships, enhancing the model's understanding of physiological signals and improving its generalization ability with small sample sizes. Second, excitation and inhibition effects are added to the original attention mechanism. The excitation effect measures the reinforcing effect of the current state on historical information, while the inhibition effect measures the weakening effect. The combination of excitation and inhibition effects enhances high-frequency features related to sleep states, enabling the model to more accurately focus on heart rate features at key time points. Finally, by constructing a cascaded architecture of SleepMLSTM+KGNN and SleepSLSTM, the complementary nature of knowledge-driven learning and stable model memory is achieved. These improvements collectively enable the SleepXLSTM model to achieve higher accuracy and robustness in sleep staging tasks, providing a more reliable and efficient solution for sleep monitoring based on single-lead heart rate signals. Attached Figure Description

[0072] Figure 1 This is a schematic flowchart of a sleep staging model for a sleep staging method according to Embodiment 1 of the present invention;

[0073] Figure 2 This is a schematic diagram of the training process of the KGNN module of a sleep staging method according to Embodiment 1 of the present invention;

[0074] Figure 3 This is a schematic diagram of the SleepMLSTM module architecture of a sleep staging method according to Embodiment 1 of the present invention;

[0075] Figure 4 This is a schematic diagram showing the test set heart rate signal, real sleep label and predicted sleep label corresponding to a sleep staging method according to Embodiment 1 of the present invention;

[0076] Figure 5 This is a schematic diagram of the test set classification confusion matrix of a sleep staging method according to Embodiment 1 of the present invention;

[0077] Figure 6 This is a schematic diagram illustrating the performance evaluation of the SleepXLSTM model for a sleep staging method according to Embodiment 1 of the present invention.

[0078] Figure 7 A comparison chart of the Kappa index for five sleep staging models. Detailed Implementation

[0079] The technical solution of the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments and specific features in the embodiments are detailed descriptions of the technical solution of the present application, rather than limitations thereof. In the absence of conflict, the embodiments and technical features in the embodiments can be combined with each other.

[0080] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.

[0081] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0082] Example 1:

[0083] This embodiment introduces a sleep staging method, such as... Figure 1 As shown, it includes:

[0084] Acquire heart rate data during sleep and pre-divide the heart rate data into multiple time windows;

[0085] Heart rate data from multiple time windows are input into a pre-built sleep staging model in chronological order, and the sleep staging results for each time window are output sequentially.

[0086] The sleep staging model includes: a KGNN module, a SleepMLSTM module, a SleepSLSTM module, and an output module;

[0087] The KGNN module calculates a context vector that integrates entities and relationships based on the heart rate data of the current time window.

[0088] The SleepMLSTM module calculates the hidden state of the last time step of the SleepMLSTM module based on the heart rate data of the current time window, and merges the hidden state of the last time step of the SleepMLSTM module with the hidden state of the last hidden layer as the final output feature of the SleepMLSTM module.

[0089] The SleepMLSTM module calculates the hidden state of the last time step of the SleepMLSTM module based on the heart rate data of the current time window, and adds the hidden state of the last time step of the SleepMLSTM module to the context vector as the final output feature of the SleepMLSTM module.

[0090] The SleepSLSTM module takes the final output features of the SleepMLSTM module as input to generate the output features of the SleepSLSTM module.

[0091] The final output features of the SleepMLSTM module and the output features of the SleepSLSTM module are concatenated and then input into the output module to generate the sleep staging result for the current time window.

[0092] The process of building and training a sleep staging model includes:

[0093] S0: Data preprocessing and dataset partitioning

[0094] The model's public dataset consists of motion and heart rate data from a wrist-worn wearable device and labeled sleep data from polysomnography (PSG). This public dataset contains both types of data collected simultaneously.

[0095] Wrist-worn activity recorder data: wrist acceleration in g, recorded simultaneously from the subject's wrist-worn device, and heart rate in bpm, measured by photoplethysmography.

[0096] Polysomnography (PSG): Based on internationally accepted standards, the entire night's recording is divided into sleep stages in 30-second intervals. Sleep stages include wakefulness, N1, N2, N3, and REM sleep. It is used as the gold standard label for training and validating automatic sleep staging algorithms.

[0097] Each type of data recorded from the wrist-worn device corresponds one-to-one with the sleep markers from the polysomnography (PSG), making this dataset a standard dataset for developing and validating sleep staging algorithms based on wrist-worn devices. The data from the wrist-worn device serves as input, and the precise PSG markers serve as the target, allowing for the training and testing of machine learning models.

[0098] S00: Obtaining Raw Data: In this embodiment, a Min-Max linear transformation is used for heart rate data to eliminate dimensional differences. Let the original heart rate sequence be... Normalization Elements in the original heart rate sequence X After normalization elements The calculation formula is:

[0099]

[0100] in, and This parameter represents the extreme value of the training set, and is used in the test set to avoid data leakage.

[0101] S01: In this embodiment, the ordinal coding of sleep tags is based on the sleep staging rules given by the American Academy of Sleep Medicine (AASM), clearly defining the original sleep staging categories and fixed ordinal relationships in the AASM standard:

[0102] The AASM defines five primitive sleep stages as follows: C1 represents wakefulness (Category 0); C2 represents light sleep (Non-REM stage 1, Category 1, Category 1, Category 2); C3 represents intermediate sleep (Non-REM stage 2, Category 2, Category 2, Category 3); C4 represents deep sleep (Non-REM stage 3, Category 3, Category 3, Category 5); and C5 represents REM sleep (Category 5, Category 5).

[0103] The fixed numerical relationship among the five primitive sleep stages is determined by sleep depth and physiological logic:

[0104] From "awake → light sleep → medium sleep → deep sleep", the sleep depth increases, and the physiological signal characteristics such as EEG and EOG show a clear gradual change pattern. Although the REM stage is not related to sleep depth, it always occurs after N3 in the sleep cycle, and the physiological characteristics of muscle relaxation and rapid eye movement in the REM stage have a clear ordering relationship with other stages. Based on the sleep cycle sequence and model learning logic, it is necessary to retain the ordinal difference with other stages, so C5=5 is set.

[0105] S02: Construct an injective mapping that preserves the ordinal number based on LabelEncoder

[0106] To convert categorical labels into numerical values ​​that are easier for the model to input, a one-to-one injective mapping needs to be constructed between each heart rate data point and a sleep label, while preserving the ordinal relationship from step S01. A one-to-one injective mapping means that one original category corresponds to only one ordinal code, and one ordinal code corresponds to only one original category. This ensures that one heart rate data point corresponds to only one ordinal code, avoiding label ambiguity. If both W and N1 are encoded as 0, the model cannot distinguish between wakefulness and light sleep. The five stages of AASM are mutually exclusive and complete, satisfying the input conditions for the injective mapping.

[0107] The default LabelEncoder encodes in alphabetical order of class names. For example, it might encode N1→0, N2→1, N3→2, REM→3, W→5, which disrupts the original ordinal relationship of W < N1. Therefore, it is necessary to customize the mapping order rather than the default logic, and LabelEncoder supports specifying the class order to achieve an injective mapping of ordinal relationships.

[0108] S03: Stratified sampling by class

[0109] To avoid sampling bias, such as when the proportion of a certain class of samples is imbalanced in the dataset, it is necessary to perform stratified random partitioning on the samples in the encoded dataset to obtain the training set and the test set. The specific operations are as follows:

[0110] Count the number of samples of each class in the original dataset and set the global sampling ratio. Independently perform Bernoulli sampling on each class of samples according to the set global sampling ratio to obtain the training set and test set of each class of samples. Combine the training sets and test sets of each class of samples to obtain the global training set and test set.

[0111] Stratified sampling by class essentially splits the original dataset into 5 independent sub-datasets corresponding to 5 classes, samples them separately, and then combines them. This method forces the class distributions of the training set and the test set to be isomorphic to the original data, ensuring that the test set is a microcosm of the original data. The generalization performance of the model on the test set can truly reflect its performance in the actual scenario, avoiding sampling bias.

[0112] S04: Verify the isomorphism of the full class distribution

[0113] Calculate the class distribution ratios of the original dataset, the training set, and the test set, and verify the isomorphism of the distributions of the three sets. Distribution isomorphism is the criterion for sampling rationality. The verification method can be through chi-square tests, respectively testing whether there are significant differences in the class distributions between the training set and the test set and the original data, or using a bar chart of class ratios for visual comparison.

[0114] Finally, an unambiguous, ordinal relationship-preserving, and distribution-isomorphic heart rate-sleep label sequence for each subject throughout the night is obtained as the training set and the test set, providing a reliable data basis for the training and evaluation of the subsequent sleep staging model.

[0115] The preprocessing of the KGNN module includes:

[0116] Divide the heart rate-sleep label sequence of each subject throughout the night into multiple segments according to a fixed time window. In this embodiment, the fixed time window is 30 seconds;

[0117] The heart rate value at the last time step of the heart rate sequence in each time window is treated as a heart rate entity; each heart rate entity corresponds to a sleep stage label, and each sleep stage label is treated as a sleep stage entity. The sleep stages include Wake, N1, N2, N3 and REM sleep, and the sleep stage labels include label 0, label 1, label 2, label 3 and label 5; Wake corresponds to label 0, N1 corresponds to label 1, N2 corresponds to label 2, N3 corresponds to label 3 and REM sleep corresponds to label 5.

[0118] Define a correspondence relationship, which means that the heart rate value of the heart rate sequence in each time window at the last time step corresponds to the sleep stage of that time window;

[0119] Using all heart rate entities and all sleep stage entities as nodes, heart rate entities and sleep stage label entities are connected by a defined correspondence within the same time window. Temporal relationships are added between heart rate entities in adjacent time windows to enable continuous modeling of sleep stages, resulting in a basic knowledge graph for KGNN.

[0120] During the training of the KGNN module, the basic knowledge graph is updated with each iteration until a fixed basic knowledge graph is obtained after training.

[0121] S1: Heart Rate-Sleep Stage Relationship Model Based on Knowledge Graph Neural Network (KGNN)

[0122] Based on knowledge graphs, entities and relations within the current time window are embedded into a continuous vector space. Information fusion and reasoning are then performed using a neural network structure. During the forward propagation of the KGNN, the entity embedding vector and relation embedding vector are concatenated, and then transformed through linear layers to generate a context vector that fuses entities and relations. This context vector is subsequently added to the hidden state of the last time step of the SleepMLSTM, thus influencing the final prediction result. This step aims to capture complex interactions and implicit associations between entities, extracting and enhancing high-order semantic information from the knowledge graph. The KGNN architecture, such as... Figure 2 As shown, the graph structure represents different heart rates corresponding to different sleep stage labels, the text structure represents heart rate values ​​corresponding to sleep stage values, and the Entity represents embedded entities. Operations, Relation is a relation embedding operate.

[0123] like Figure 2 As shown, heart rate fluctuations and sleep stage labels are modeled using a knowledge graph neural network (KGNN), generating context vectors that include entity relationships between heart rate and sleep stage labels. Specifically, these include:

[0124] Step 1-1, entity embedding;

[0125] Steps 1-2, relation embedding;

[0126] Steps 1-3: Linear transformation and feature fusion;

[0127] Step 1-1, entity embedding, includes:

[0128] Heart rate entity embedding: Map each heart rate entity to an h-dimensional vector through a linear layer.

[0129] Sleep stage entity embedding: Map each sleep label to an h-dimensional vector.

[0130] Heart rate entity embedding, including:

[0131] The value of the last time step of an input heart rate time series. Define it as an entity;

[0132] Through a linear transformation, the entity is mapped to an h-dimensional continuous vector space, yielding the entity embedding result; the entity embedding result e serves as the entity. The basic feature representations are input into subsequent KGNN layers for interaction with relation vectors and neighbor information aggregation operations, and are ultimately used for the sleep staging task.

[0133] Specifically, it includes:

[0134] Suppose the input is the heart rate data of the current time window. , express Batch represents a batch size, and the batch size B set during training is the number of subjects in the current iteration. The batch size set during training does not need to be consistent with the number of samples input in actual use. During training, B batches of heart rate data for the current time window are input each time. When using the trained SleepXLSTM model for sleep staging, the SleepXLSTM model accepts input of any batch size for prediction, which means it can perform sleep staging on the heart rate data of one or more people. Timesteps represents time steps, and Features represents features. A feature of 1 indicates heart rate data. This is the last time step of the current time window; the Knowledge Graph Neural Network (KGNN) maps entities in the knowledge graph, i.e., heart rate data, to a high-dimensional vector space by defining a linear layer. The entity embedding operation is set as follows: , For the preset weight matrix, , For the preset paranoia matrix, , and It is obtained by optimizing KGNN during training through backpropagation and gradient descent. In this embodiment, the hidden layer size is preset. Entity embedding The operation preserves the basic features of the entity and provides a foundation for subsequent feature fusion. and The linear transformation of the entity embeddings maps the entity heart rate values ​​to a more informative distributed representation for subsequent sleep staging tasks. The linear transformation expression for entity embeddings is:

[0135] ,

[0136] In the formula, This represents the heart rate at the last time step within the current time window. , The basic features of entity embedding output, T is the transpose operation; and The last time step is usually considered to contain the final state or latest information of the sequence and is the endpoint of the dynamic evolution of the sequence. In LSTM, the last hidden state carries the contextual information of the sequence.

[0137] Relation embedding in steps 1-2:

[0138] Assign a relation vector to the correspondence relationship and the temporal relationship respectively to obtain the correspondence relationship vector and the temporal relationship vector; the correspondence relationship indicates that the heart rate value of the heart rate sequence in the last time step of each time window corresponds to the sleep stage of that time window; the temporal relationship indicates the temporal connection between entities;

[0139] Specifically, it includes:

[0140] KGNN integrates relationships from knowledge graphs through embedding layers. , each relationship Mapping to the same vector space as the heart rate data, this relational embedding operation is defined as follows: This ensures that entities and relationships can perform direct vector operations within the same space. The operation expression is:

[0141] ,

[0142] In the formula, For the relationship, Initialization passed Normal distribution is generated; in this embodiment, This refers to a correspondence or a temporal relationship; for The vector after .

[0143] Steps 1-3 perform feature fusion and linear concatenation on the entity embeddings and relation embeddings mentioned above:

[0144] For each entity in the graph, its neighbor information is aggregated through multiple rounds of iteration. KGNN concatenates the embedding vectors of entities and relations and performs feature fusion through a linear transformation layer, ultimately outputting a context vector that can jointly represent the entity and its associated context.

[0145] KGNN uses a linear layer pair and The embedding vectors are subjected to linear transformation and feature fusion; this operation is set as follows: . Operation expression:

[0146] ,

[0147] ,

[0148] In the formula, Depend on and After splicing, the result is Repeat the calculation. The combined embedding is obtained for the second time. , for Weight, , for Bias term, , and It is obtained by optimizing KGNN during training through backpropagation and gradient descent. For context vectors, .

[0149] After training, when using the KGNN module, a context vector fusing entities and relationships is calculated based on heart rate data from multiple time windows, including:

[0150] Based on a pre-trained KGNN module and a fixed knowledge graph after training, the following processing is performed on heart rate data from multiple time windows:

[0151] Create a corresponding heart rate entity node for the heart rate data of each time window; connect the created heart rate entity node to the basic knowledge graph to establish candidate relationships with sleep stage label entities and temporal relationships of adjacent time windows; iteratively fuse entity features and relationship information through the multi-layer message passing mechanism of the KGNN module; and calculate a context vector that fuses entities and relationships.

[0152] S2: SleepMLSTM module based on excitation-inhibition dual-effect regulator

[0153] The SleepMLSTM module, based on an excitation-inhibition dual-effect regulator, models heart rate data and sleep stage labels. It performs time-step operations between heart rate and sleep stage labels, uses an attention mechanism to extract data features, and finally adds the output of the KGNN module to the final output features of the SleepMLSTM module. Specifically, this includes:

[0154] Step 2-1, time step calculation;

[0155] Step 2-2, Attention Mechanism;

[0156] Steps 2-3: Feature fusion of KGNN and SleepMLSTM;

[0157] Step 2, regarding the extraction of heart rate features, proposes an excitation-inhibition dual-effect regulatory factor in the SleepMLSTM module. This factor can enhance key temporal features of the model while filtering out noise-induced motion artifacts from the signal data for feature extraction. Specifically, it includes:

[0158] Traditional XLSTM (Extended Long Short-Term Memory) neural networks consist of SLSTM (Scalar LSTM) and MLSTM (Matrix LSTM). This embodiment improves upon the MLSTM structure within XLSTM, retaining the original gating and attention mechanisms, and proposes an improved MLSTM module: SleepMLSTM, which incorporates a dual attention mechanism and fuses it with the output features of KGNN.

[0159] In this embodiment, the input weights for the input gate, forget gate, cell state, and output gate of an LSTM layer are defined as follows: Each input weight is passed through Initialize using a uniform distribution, with the corresponding loop weights for each gate as follows: The bias term is: Each loop weight and each pass bias term is initialized with zero. Generate. Query using a dual attention mechanism. ,key Sum The vector weight matrices are respectively , and , Weight matrix Through respectively Initialize using a uniform distribution; the excitation effect weight matrix is: The inhibition effect weight matrix is The excitation effect weights and inhibition effect weights are generated using standard normal distributions.

[0160] Each weight matrix and bias term is fixed after being optimized by backpropagation and gradient descent during training by the SleepMLSTM module. When using the trained SleepMLSTM module for inference, this set of fixed parameters obtained during training is used. In other words, when using the trained SleepMLSTM module for inference, each weight and bias term is a preset parameter.

[0161] Step 2-1, time step calculation.

[0162] Input the heart rate data of the current time window into the SleepMLSTM module, and calculate the final hidden state of each time step of the final LSTM layer within the current time window in sequence:

[0163] The input gate of an LSTM layer in the SleepMLSTM module at time t. Forgotten Gate Cell state candidate values Output gate Cell state Hidden state The calculation formula is as follows:

[0164] ,

[0165] ,

[0166] ,

[0167] ,

[0168] ,

[0169] ,

[0170] In the formula, The input weights are for the input gate, forget gate, cell state, and output gate. The loop weights are for the input gate, forget gate, cell state, and output gate. These are the bias terms for the input gate, forget gate, cell state, and output gate. The sigmoid function is used; tanh() is the hyperbolic tangent activation function. This is a dot product operation; As the input of an LSTM layer at time t of the SleepMLSTM module, in this embodiment, This represents the heart rate value at time t within the current time window. This represents the hidden state of an LSTM layer in the SleepMLSTM module at time t-1.

[0171] Time series data is processed using the SleepMLSTM module, with L LSTM layers passing the hidden state layer by layer. and cell state The connection was established, and the final hidden state of the LSTM layer at time t was... .

[0172] Calculate the final hidden state of the final LSTM layer at each time step within the current time window to obtain the final hidden state of the final LSTM layer in the current time window:

[0173] ;

[0174] In the formula, L is the number of LSTM layers in the SleepMLSTM module; This represents the final hidden state of each time step in the final LSTM layer within the current time window; This is the last time step of the current time window;

[0175] Step 2-2, Attention Dual Mechanism.

[0176] Calculate the attention features at each time step within the current time window:

[0177] The final hidden state of the LSTM layer at time t is , , The last time step is The set of time steps for the current time window.

[0178] Query at time t ,key Sum The formula for calculating vectors is:

[0179] , ,

[0180] , ,

[0181] , ,

[0182] In the formula, T is the transpose operation;

[0183] Excitation effect at time t and inhibition effect The calculation formula is:

[0184] , ,

[0185] , ,

[0186] As can be seen from the formula, the excitation effect and the inhibition effect are obtained by multiplying the query vector and the key vector with the corresponding excitation / inhibition weight matrix, respectively. This separate calculation method enables the model to independently learn what should be emphasized and what should be ignored.

[0187] Attention value at time t The calculation formula is:

[0188] ,

[0189] In the formula, The preset size of the hidden layer; This represents the difference between the excitation effect and the inhibition effect, resulting in a net excitation value. This difference is then scaled and normalized using softmax to obtain the final attention value. This design allows the attention mechanism to not only positively enhance certain features but also weaken unnecessary information through the inhibition effect, thereby improving the model's ability to capture key features.

[0190] Attention feature of the value at time t The calculation formula is:

[0191] ,

[0192] In the formula, This is a dot product operation;

[0193] Attention feature of the value at time t A value attention feature is a time step; the value attention features of each time step within the current time window are combined in chronological order to form the final value attention feature. ;

[0194] The final hidden state of the current time window of the final LSTM layer. and final value attention features Element-wise summation is used as the candidate output for the current time window of the SleepMLSTM module. The calculation formula is:

[0195] ,

[0196] In the formula, , ;

[0197] In this embodiment, the SleepMLSTM module calculates the query, key, and value vectors in the first-layer attention mechanism. In the second-layer attention mechanism, it calculates the excitation and inhibition effects using the query and key vectors, respectively, and then calculates the attention value using the excitation and inhibition effects. Based on the attention value and value vector, it calculates the value attention feature. This calculation process is repeated to obtain the final value attention feature for the entire time window. Finally, the final value attention feature is added to the final hidden state of the current time window of the final LSTM layer to obtain the candidate output of the SleepMLSTM module for the current time window. This is done to enhance or suppress the expression of specific features.

[0198] The attention mechanism in this embodiment is called dual because it simultaneously introduces both an excitatory effect and an inhibitory effect. Traditional attention mechanisms typically use only one attention weight matrix to emphasize certain features. Here, however, two independent weight systems—an excitatory weight matrix and an inhibitory weight matrix—are used to calculate the excitatory and inhibitory effects separately, and their difference is used as input for calculating the attention value. The SleepMLSTM module, through the combination of excitatory and inhibitory effects, can not only enhance certain features but also suppress certain irrelevant or interfering features, thereby achieving feature modulation.

[0199] Steps 2-3: Feature fusion of KGNN and SleepMLSTM.

[0200] Candidate outputs for the current time window of the SleepMLSTM module In the SleepMLSTM module, the hidden state at the last time step is... , Combined with the context vector output by KGNN , The hidden state of the SleepMLSTM module at the last time step is added to the context vector of the KGNN module to obtain the final output feature of the SleepMLSTM module for the current time window. The calculation formula is:

[0201] .

[0202] The architecture of the proposed SleepMLSTM can be found in [link to architecture]. Figure 3 The SleepMLSTM model in this embodiment improves upon the traditional attention mechanism by introducing two parameters, excitation and inhibition, to perform secondary feature extraction for the attention mechanism.

[0203] S3: Constructing the SleepSLSTM model, specifically including:

[0204] The final output features of the SleepMLSTM module in the current time window As the input of the SleepSLSTM module in the current time window :

[0205] (1) Time step calculation. The input weight matrices of the SleepSLSTM module's input gate, forget gate, intermediate states, and output gate are as follows: The input weight matrices for the input gate, forget gate, intermediate states, and output gate are respectively passed through... With uniform initialization, the cyclic weight matrices for the input gate, forget gate, intermediate states, and output gate are as follows: The bias terms for the input gate, forget gate, intermediate states, and output gate are: Each loop weight and each pass bias term is initialized with zero. generate.

[0206] Each weight matrix and bias term is fixed after being optimized by backpropagation and gradient descent during training by the SleepSLSTM module. When using the trained SleepSLSTM module for inference, this set of fixed parameters obtained during training is used. In other words, when using the trained SleepSLSTM module for inference, each weight and bias term is a preset parameter.

[0207] The input gate of the SleepSLSTM model at the current time window Forgotten Gate intermediate state and output gate The calculation formula is as follows:

[0208] ,

[0209] ,

[0210] ,

[0211] ,

[0212] In the formula, This is the input to the SleepSLSTM module within the current time window; This represents the hidden state of the SleepSLSTM module in the previous time window. The function is a sigmoid function, with an output range of (0,1); the SleepSLSTM module represents the intermediate state within the current time window. It generates candidate information, which is computed independently of the input gate, provides additional information processing channels, enhances the expressive power of the model, and the activation function tanh compresses the value to (-1,1), providing nonlinearity;

[0213] (2) Stability gating and state transitions. Define the stability factor. To ensure positive values, used for logarithmic field transformations, and to stabilize the input gate. and stabilization forgetting gate Cell state update Normalized state Hidden state output ;

[0214] The stability factor of the SleepSLSTM module in the current time window Stabilization input gate and stabilization forgetting gate The calculation formula is as follows:

[0215] ,

[0216] ,

[0217] ,

[0218] In the formula, This is the stability factor of the SleepSLSTM module in the previous time window;

[0219] (3) Cell state of the SleepSLSTM module in the current time window The updated calculation formula is as follows:

[0220] ,

[0221] In the formula, Stabilize the forget gate for the SleepSLSTM module within the current time window; This serves as the input gate for stabilizing the SleepSLSTM module within the current time window. This is a dot product operation; The cell state of the SleepSLSTM module in the previous time window; This represents the intermediate state of the SleepSLSTM module within the current time window. The difference between the SleepSLSTM module's cell state within the current time window and that of a traditional LSTM is that it uses a stabilized gating system instead of the original gating system.

[0222] (4) Normalized state of the SleepSLSTM module in the current time window and hidden state The calculation formula is as follows:

[0223] ,

[0224] ,

[0225] In the formula, the normalized state of the SleepSLSTM module in the current time window Used to eliminate cellular state Amplitude drift; The SleepSLSTM module's normalized state in the previous time window; the SleepSLSTM output's hidden state in the current time window. , As the output of the current time window; The normalized cell state is activated by the hyperbolic tangent activation function;

[0226] Compared to traditional LSTM, SleepSLSTM adds an independent information processing channel to the intermediate states, introduces a gating mechanism to the logarithmic domain operations through a stabilizing factor, and eliminates amplitude drift of the cell state through a normalized state. By introducing a stabilizing factor and a normalized state, SleepSLSTM effectively solves the numerical stability problem of traditional LSTM in deep training and long sequence processing, while maintaining the sequence modeling capability of LSTM.

[0227] The calculation process of the SleepSLSTM module is as follows:

[0228] Obtain the final output features of the SleepMLSTM module in the current time window. As input to the SleepSLSTM model in the current time window The hidden state of the SleepSLSTM model in the previous time window Cell state in the previous time window using the SleepSLSTM model The SleepSLSTM model in the intermediate state of the previous time window ;

[0229] Calculate the input gate of the SleepSLSTM module in the current time window. Forgotten Gate and intermediate state ;

[0230] Calculate the stability factor of the SleepSLSTM module in the current time window. Stabilization input gate and stabilization forgetting gate ;

[0231] Calculate the cell state of the SleepSLSTM module in the current time window. ;

[0232] Calculate the normalized state of the SleepSLSTM module in the current time window. and hidden state Output the hidden state of the SleepSLSTM module in the current time window. As the output feature of the SleepSLSTM module in the current time window;

[0233] The SleepXLSTM model proposed in this embodiment includes a KGNN module, a SleepMLSTM module, and a SleepSLSTM module. The SleepMLSTM module is formed by linearly concatenating and fusing features of KGNN and MLSTM, and then formed by feature concatenation and linear fusion of SleepSLSTM, thus forming the SleepXLSTM model, which realizes automatic sleep staging based on a single heart rate signal.

[0234] S4: The output module performs feature fusion, specifically including:

[0235] The output module includes a first fully connected layer and a second fully connected layer;

[0236] The final output features of the SleepMLSTM module in the current time window The hidden state of the SleepSLSTM model in the current time window After concatenation, the input is given to the first fully connected layer, activated by ReLU, and then output. ;

[0237] The output of the first fully connected layer Output after the first Dropout layer ;

[0238] The output of the first Dropout layer The output of the second Dropout layer after the second fully connected layer. ;

[0239] The output of the second Dropout layer After Softmax activation, a probability vector is output. For the heart rate data in the current time window, the column index with the highest probability in the corresponding row of the probability vector is found, and this column index is mapped to the corresponding sleep stage label, which is then output as the sleep staging result. Specifically, this includes:

[0240] (1) The first fully connected layer. The classification weight matrix of the first fully connected layer is defined as follows: It is generated using the KaiMing normal distribution, and the bias term of the first fully connected layer is... The bias term is initialized to a zero vector;

[0241] Let the input of the first fully connected layer be... The final output features of the SleepMLSTM module and the output of the SleepSLSTM module The result obtained by piecing together: , , , ;

[0242] Output of the first fully connected layer , , The calculation formula is:

[0243] ,

[0244] In the formula, ReLU is the ReLU activation function; This is the input to the first fully connected layer; This is the classification weight matrix for the first fully connected layer; This is the bias term for the first fully connected layer;

[0245] To prevent overfitting, the output of the first fully connected layer is... The output after the first Dropout layer is represented as ,in ,

[0246] ,

[0247] ,

[0248] In the formula, For discard rate;

[0249] (2) The second fully connected layer. The classification weight matrix of the second fully connected layer is defined as follows: Through Generated uniformly, the bias term of the second fully connected layer is output as follows. After the calculation formula of the second fully connected layer, the output probability vector is obtained. ,in ,

[0250] ,

[0251] ,

[0252] In the formula, The output of the second fully connected layer's Dropout layer , .

[0253] Find the column index with the highest probability in the corresponding row of the probability vector of each subject's current time window, and map the column index to the corresponding sleep stage label, which is then output as the sleep stage result of each subject's current time window.

[0254] The process of inputting heart rate data for a time window and outputting sleep staging results through the SleepXLSTM model is repeated until the sleep staging of the heart rate data for each subject throughout the night is completed, which is considered as completing one iteration.

[0255] During the training of the SleepXLSTM model, a network overfitting prevention method based on the weighted cross-entropy loss function is introduced, including:

[0256] This network-based overfitting prevention method, based on the weighted cross-entropy loss function, mitigates the long-tail distribution bias of sleep stage data through adaptive weight allocation using the inverse square root of the class sample size. It combines the AdamW optimizer to decouple weight decay and gradient update paths to enhance model generalization performance, and is further supplemented by a global gradient norm constraint (threshold). This method suppresses gradient explosion in deep recursive architectures, improving the adaptability of sleep staging tasks while ensuring convergence. The training steps include:

[0257] The SleepMLSTM module outputs probability vectors for five sleep stages;

[0258] The weighted cross-entropy loss is calculated based on the probability vector, and higher weights are assigned to the minority classes based on the reciprocal of the square root of the sample size of each class to alleviate the long-tail distribution problem of the data.

[0259] Based on the weighted cross-entropy loss calculation results, backpropagation is performed to calculate the gradient, and gradient clipping is applied to limit the gradient norm within a preset threshold to prevent gradient explosion in deep networks.

[0260] The AdamW optimizer updates parameters based on the computed gradients. The AdamW optimizer enhances the generalization performance of the model by decoupling the weight decay term from the adaptive gradient term.

[0261] The entire training process employs a multi-layered anti-overfitting mechanism consisting of Dropout, weighted loss, gradient clipping, and AdamW to ensure that the model can fully learn temporal features and maintain good generalization ability in the sleep staging task.

[0262] The training process specifically includes:

[0263] The formula for calculating the weighted cross-entropy loss function in the t*th iteration is:

[0264] ,

[0265] In the formula, The parameters in the (t*-1)th iteration , This represents the set of all learnable parameters in the sleep staging model. After training, all learnable parameters are fixed and used as preset parameters for the pre-built sleep staging model. In this embodiment, the preset parameters include the KGNN module, the SleepMLSTM module, each weight matrix, and each bias term. The weight of category c, There are a total of 5 categories c, and the number of samples in each of the 5 categories is as follows: ; The training sample size is defined as the heart rate data of one subject within one time window. Index for sleep stages; For the one-hot encoding of the true label, if the true class of sample n is c, then ,otherwise ; Predict the probability that sample n belongs to class c for the model;

[0266] The AdamW optimizer is calculated as follows:

[0267] Parameter initialization:

[0268] The preset learning rate; The preset stability coefficient; The preset attenuation index; and These are the preset momentum values ​​and decay exponents, respectively. Momentum value , Learning rate Stability coefficient Initialize the first-order moment. Initialize the second moment ;

[0269] Steps for the t*th iteration:

[0270] Calculate the gradient: ,

[0271] The gradients of all parameters are calculated based on the weighted cross-entropy loss. The gradient including all parameters;

[0272] Update the first-order moment estimate: , The first moment estimate of the gradient;

[0273] Update the second-order moment estimate: , This is the second moment estimate of the gradient;

[0274] Deviation correction: , ,

[0275] Parameter update: ,

[0276] Gradient norm calculation:

[0277] Let the gradient vector of all parameters in the t*th iteration be... The total number of model parameters is P; , This is a transpose operation;

[0278] L2 norm: In the formula, Let be the gradient of the u-th parameter;

[0279] Cutting conditions:

[0280] When gradient hour, If the preset gradient threshold is not met, then gradient clipping is performed:

[0281] ,

[0282] In the formula, The gradient after gradient clipping;

[0283] In this embodiment, =1, hour, This makes the gradient less than a preset gradient threshold, that is... .

[0284] The SleepXLSTM model of this invention prevents overfitting during training by using two fully connected Dropout layers, handles class imbalance by using weighted cross-entropy, achieves good optimization performance by using AdamW, and ensures training stability by using gradient clipping.

[0285] Evaluation metrics for the SleepXLSTM model:

[0286] This invention employs multi-level quantitative metrics to evaluate classification performance, including Global Accuracy (ACC), Class-Weighted F1 Score, and Normalized Confusion Entropy (NCE), expressed as:

[0287] ,

[0288] In the formula, For indicator functions, and These are the predicted label and the true label, respectively, reflecting the overall classification accuracy, but they are sensitive to class imbalance.

[0289] ,

[0290] ,

[0291] In the formula, , , For category The number of test samples is limited, and a weighting strategy is used to assign higher weights to the majority class, which is suitable for the long-tail distribution characteristics of clinical data.

[0292] ,

[0293] In the formula, This represents the number of samples where the true class a is predicted as b, quantifying the degree of confusion in model misclassification. , (Indicates no confusion).

[0294] This index system constructs an orthogonal evaluation space from two dimensions: classification accuracy and robustness. It is defined to strictly satisfy scale invariance (NCE normalization), and all calculations are based on nonparametric estimation to avoid bias in distribution assumptions.

[0295] Model Comparison:

[0296] like Figure 5 and Figure 6 As shown, the SleepXLSTM model exhibits significant differences across different sleep stages, measured by three metrics: precision, recall, and F1 score. Recall measures the proportion of correctly identified positive samples from all actual positive samples; F1 score is the harmonic mean of precision and recall, used to comprehensively evaluate the model's precision and recall capabilities. The model classifies... (N2 stage) and categories The recognition ability is most outstanding in the REM stage, and the recall rate is highest in the N2 and REM stages. The F1 score is also the highest in the N2 and REM stages. Figure 5 As shown, this may be related to the large sample sizes in both the N2 and REM stages. However, as... Figure 6 As shown, category 0 ( The recall rates for categories 1 and 2 (N1 stage) were relatively low, especially for the Wake stage, where there was a slight imbalance between precision and recall, indicating that there is still room for optimization in the model's feature capture of the end-of-sleep stage. Notably, while category 3 (N3 stage) had a high recall rate, its precision was the lowest, suggesting a tendency to misclassify other stages as light sleep, possibly related to the poor representation of low-frequency features. For a visualization of heart rate, normalized (Min-Max) signal, true sleep labels, and predicted sleep labels, see [link to visualization]. Figure 3 See the automatic sleep staging confusion matrix. Figure 4 See model classification performance evaluation. Figure 5 and Figure 6 .

[0297] like Figure 4 As shown, the first sub-image from top to bottom, "Raw Heart Rate Signal," displays a portion of the input data—unmodified time-series heart rate data directly collected from the sensor. It contains all the initial physiological fluctuations, but also includes noise and interference. The second sub-image, "Heart Rate Data Preprocessing," shows the signal after normalization. It can be seen that the signal retains its basic characteristics, but the heart rate values ​​are normalized to between 0 and 1 for easier model calculation. The third sub-image, "True Sleep Stages," shows the objective and true sleep stage segmentation results determined by the "gold standard" of polysomnography (PSG), serving as the target for the SleepXLSTM model to learn. The fourth sub-image, "Predicted Sleep Stages," shows the predicted results output by the SleepXLSTM model. The fourth sub-image shows occasional, subtle deviations between these predicted labels and the true labels. The reasons for this can be mainly attributed to several factors. First, there is the physiological ambiguity of sleep stage transitions. For example, the transition from N1 (light sleep) to N2 involves a continuous spectrum of physiological signal changes, rather than an instantaneous switch. The millisecond-level lag or lead that the model captures during this transition is consistent with physiological patterns. Second, there is individual specificity. The correspondence between heart rate and sleep stage is unique for each person. Models trained on population data may exhibit adaptation bias when dealing with individual cases.

[0298] The SleepXLSTM model proposed in this invention, compared with traditional methods, achieves staging results highly similar to those of professional PSG equipment that requires attaching numerous electrodes, using only the single feature of the heart rate signal. It is noteworthy that, for most of the time in the figure, the red prediction line and the blue true line almost overlap, indicating that the SleepXLSTM model has the following advantages:

[0299] 1) Accurately captures macroscopic sleep structure. The cyclical alternation pattern of wakefulness, light sleep, deep sleep, and REM sleep is fully predicted.

[0300] 2) Core sleep stages were identified. The accuracy rate was particularly high in identifying the N3 and REM sleep stages, which are crucial for health and are therefore of decisive significance for sleep quality assessment.

[0301] 3) The algorithm has good robustness. Even when the signal still has slight fluctuations after preprocessing, the model can still make stable and continuous predictions without frequent erroneous jumps.

[0302] The SleepXLSTM proposed in this invention exhibits state-of-the-art performance in automatic sleep staging. This embodiment includes experiments comparing the performance of four existing automatic sleep staging methods based on heart rate signals: Logistic Regression, K-Nearest Neighbors (KNN), Random Forest, and Neural Net, with the performance of the proposed SleepXLSTM. All methods were set with the same parameters. The results are summarized in the table below:

[0303] Table 1. Performance comparison of five sleep staging methods

[0304]

[0305] Comparing the method of this invention with other methods, the accuracy rates of Wake, NREM (N1, N2, and N3), and REM show that the method of this invention has a significant accuracy advantage. To illustrate classification consistency, which refers to the degree of consistency in the results obtained when different evaluation models classify the same group of objects, this invention calculates the Cohen's Kappa index. The formula for calculating the Kappa coefficient of the Cohen's Kappa index is as follows:

[0306] ,

[0307] In the formula, The observed actual consistency ratio, The expected proportion of coincidental consistency.

[0308] The Kappa coefficient takes into account the factor of accidental consistency. Figure 7 These are the Kappa coefficient results obtained through comparison. The above results demonstrate that the model algorithm of this invention can accurately identify sleep stages and has high reliability.

[0309] This invention aims to achieve automatic sleep staging based on SleepXLSTM for extracting heart rate signal features. The network is a five-level (Wake, N1, N2, N3, REM) classifier. Experiments show that SleepXLSTM exhibits state-of-the-art automatic sleep staging performance.

[0310] The sleep staging model of this invention can be integrated into a flexible biosensor platform, successfully achieving an intelligent upgrade of non-contact wristband devices. This device, through single physiological signal analysis, overcomes the physical limitations of traditional contact electrodes, significantly improving user compliance while maintaining medical-grade monitoring accuracy. Of particular note is its non-invasive design, which allows for continuous collection of physiological parameters during infant sleep, effectively overcoming the technical bottleneck of traditional polysomnography (PSG) being easily interfered with by limb movement, thus building a safe and reliable long-term sleep monitoring system for children in critical developmental periods.

[0311] From a public health perspective, the widespread adoption of this technology will complement existing sleep health management models. By building a cloud-based sleep quality assessment platform, dynamic tracking of residents' sleep parameters and early warning of abnormal fluctuations can be achieved. Notably, the accumulated long-term sleep big data not only provides a scientific basis for individualized sleep intervention programs but also reveals the potential link between environmental factors, lifestyle, and sleep disorders through group sleep characteristic analysis. This end-to-end management paradigm of "prevention-monitoring-intervention" is expected to reduce the diagnosis and treatment costs of conditions such as chronic insomnia and circadian rhythm disorders. Crucially, this highly sensitive identification capability enables community healthcare institutions to conduct large-scale sleep disorder screenings using low-cost wearable devices, demonstrating significant application value, particularly in the early detection of sleep apnea syndrome (SAS) in the elderly.

[0312] Example 2:

[0313] Based on the same inventive concept as Embodiment 1, this embodiment introduces a storage medium storing a computer program thereon, characterized in that the program, when executed by a processor, implements the steps of the method described in the first aspect.

[0314] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0315] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0316] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0317] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0318] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for sleep staging, characterized in that, include: Acquire heart rate data during sleep and pre-divide the heart rate data into multiple time windows; Heart rate data from multiple time windows are input into a pre-built sleep staging model in chronological order, and the sleep staging results for each time window are output sequentially. The sleep staging model includes: a KGNN module, a SleepMLSTM module, a SleepSLSTM module, and an output module; The KGNN module calculates a context vector that integrates entities and relationships based on heart rate data from multiple time windows. The SleepMLSTM module calculates the hidden state of the last time step of the SleepMLSTM module based on the heart rate data of the current time window, and adds the hidden state of the last time step of the SleepMLSTM module to the context vector as the final output feature of the SleepMLSTM module. The SleepSLSTM module takes the final output features of the SleepMLSTM module as input to generate the output features of the SleepSLSTM module. The final output features of the SleepMLSTM module and the output features of the SleepSLSTM module are concatenated and then input into the output module to generate the sleep staging result for the current time window.

2. The sleep staging method according to claim 1, characterized in that, In the process of constructing the sleep staging model, the KGNN module preprocessing includes: Each subject's heart rate-sleep tag sequence throughout the night was divided into multiple segments according to fixed time windows; The heart rate value at the last time step of the heart rate sequence in each time window is treated as a heart rate entity; each heart rate entity corresponds to a sleep stage label, and each sleep stage label is treated as a sleep stage entity. The sleep stages include Wake, N1, N2, N3 and REM sleep, and the sleep stage labels include label 0, label 1, label 2, label 3 and label 5; Wake corresponds to label 0, N1 corresponds to label 1, N2 corresponds to label 2, N3 corresponds to label 3 and REM sleep corresponds to label 5. Define a correspondence relationship, which means that the heart rate value of the heart rate sequence in each time window at the last time step corresponds to the sleep stage of that time window; Using all heart rate entities and all sleep stage entities as nodes, heart rate entities and sleep stage label entities are connected by a defined correspondence within the same time window. Temporal relationships are added between heart rate entities in adjacent time windows to enable continuous modeling of sleep stages, resulting in a basic knowledge graph for KGNN.

3. The sleep staging method according to claim 2, characterized in that, The KGNN module calculates a context vector that fuses entities and relationships based on heart rate data from multiple time windows, including: Based on a pre-trained KGNN module and a fixed knowledge graph after training, the following processing is performed on heart rate data from multiple time windows: Create a corresponding heart rate entity node for the heart rate data of each time window; connect the created heart rate entity node to the basic knowledge graph to establish candidate relationships with sleep stage label entities and temporal relationships of adjacent time windows; iteratively fuse entity features and relationship information through the multi-layer message passing mechanism of the KGNN module; and calculate a context vector that fuses entities and relationships.

4. The sleep staging method according to claim 1, characterized in that, The SleepMLSTM module calculates the hidden state of the last time step of the SleepMLSTM module based on the heart rate data of the current time window, including: Input the heart rate data of the current time window into the SleepMLSTM module, and calculate the final hidden state of the final LSTM layer at each time step within the current time window in turn, to obtain the final hidden state of the final LSTM layer for the current time window: ; In the formula, L is the number of LSTM layers in the SleepMLSTM module; This represents the final hidden state of each time step in the final LSTM layer within the current time window; This is the last time step of the current time window; Calculate the value attention features at each time step within the current time window, including calculating the value attention features of the current time window at time t, which includes: Based on the final hidden state of the LSTM layer at time t Calculate the query at time t respectively ,key Sum Vector, the formula for calculation is: , , , In the formula, , The last time step is The set of time steps for the current time window; , and These are the preset queries. ,key Sum Vector weight matrix; T is the transpose operation; Calculate the excitation effect at time t based on the query vector and key vector respectively. and inhibition effect The calculation formula is: , , In the formula, The preset excitation effect weight matrix, The preset inhibition effect weight matrix Based on the attention value at time t The calculation formula is: , In the formula, The preset size of the hidden layer; Attention feature of the value at time t The calculation formula is: , In the formula, This is a dot product operation; Combine the attention features of each time step within the current time window into the final value attention feature in chronological order. The attention feature is the value at time t. It is a time step value attention feature; The final hidden state of the current time window of the final LSTM layer. and final value attention features Element-wise summation is used as the candidate output for the current time window of the SleepMLSTM module. The calculation formula is: , , In the formula, Attention features are the values ​​at each time step within the current time window; Candidate outputs for the current time window of the SleepMLSTM module In the SleepMLSTM module, the hidden state at the last time step is... .

5. The sleep staging method according to claim 4, characterized in that, The step of adding the hidden state of the last time step of the SleepMLSTM module to the context vector to obtain the final output feature of the SleepMLSTM module includes: The final output characteristics of the SleepMLSTM module in the current time window The calculation formula is: , In the formula, The hidden state of the SleepMLSTM module at the last time step; This is the context vector output by the KGNN module.

6. The sleep staging method according to claim 5, characterized in that, The SleepSLSTM module takes the final output features of the SleepMLSTM module as input to generate the output of the SleepSLSTM module, including: Obtain the final output features of the SleepMLSTM module in the current time window. As input to the SleepSLSTM model in the current time window And the hidden state of the SleepSLSTM model in the previous time window. Cell state in the previous time window using the SleepSLSTM model The SleepSLSTM model in the intermediate state of the previous time window The normalized state of the SleepSLSTM module in the previous time window ; Based on the input of the SleepSLSTM model in the current time window The hidden state of the SleepSLSTM model in the previous time window Calculate the input gate of the SleepSLSTM module in the current time window. Forgotten Gate intermediate state and output gate The calculation formula is: , , , , In the formula, These are the input weight matrices for the input gate, forget gate, intermediate state, and output gate of the preset SleepSLSTM model, respectively. These are the preset cyclic weight matrices for the input gate, forget gate, intermediate state, and output gate, respectively. These are the bias terms for the preset input gate, forget gate, intermediate state, and output gate, respectively; The sigmoid function is used; tanh() is the hyperbolic tangent activation function. Based on the input gate of the SleepSLSTM module in the current time window Forgotten Gate and intermediate state Calculate the stability factor of the SleepSLSTM module in the current time window. Stabilization input gate and stabilization forgetting gate The calculation formula is: , , , In the formula, This is the stability factor of the SleepSLSTM module in the previous time window; Based on the stability factor of the SleepSLSTM module in the current time window Stabilization input gate and stabilization forgetting gate And the cell state of the SleepSLSTM module in the previous time window. Calculate the cell state of the SleepSLSTM module in the current time window. The calculation formula is: ; Based on the SleepSLSTM module's stabilization forget gate in the current time window The normalized state in the previous time window Cell state in the current time window and the output gate in the current time window Calculate the normalized state of the SleepSLSTM module in the current time window. and hidden state The calculation formula is: , , Output the hidden state of the SleepSLSTM module in the current time window. This serves as the output feature of the SleepSLSTM module within the current time window.

7. The sleep staging method according to claim 6, characterized in that, The process of concatenating the final output features of the SleepMLSTM module and the output features of the SleepSLSTM module and inputting them into the output module to generate the output sleep staging result includes: The output module includes a first fully connected layer and a second fully connected layer; The final output features of the SleepMLSTM module in the current time window The hidden state of the SleepSLSTM module in the current time window After concatenation, the input is given to the first fully connected layer, activated by ReLU, and then output. ; The output of the first fully connected layer Output after the first Dropout layer ; The output of the first Dropout layer The output of the second Dropout layer after the second fully connected layer. ; The output of the second Dropout layer After Softmax activation, a probability vector is output. For the heart rate data in the current time window, the column index with the highest probability in the corresponding row of the probability vector is found, and the column index is mapped to the corresponding sleep stage label, which is then output as the sleep staging result.

8. The sleep staging method according to claim 7, characterized in that, The training process of the sleep staging model includes: The sleep staging model outputs probability vectors for five sleep stages; The weighted cross-entropy loss is calculated based on the probability vector, and higher weights are assigned to the minority classes based on the reciprocal of the square root of the sample size of each class. Based on the weighted cross-entropy loss calculation results, backpropagation is performed to calculate the gradient, and gradient clipping is applied to restrict the gradient norm within a preset threshold. The AdamW optimizer is used to update the parameters based on the calculated gradients.

9. The sleep staging method according to claim 8, characterized in that, In the t*th iteration, the weighted cross-entropy loss function is calculated as follows: , In the formula, The parameters in the (t*-1)th iteration , This represents the set of all learnable parameters in the sleep staging model. After training, all learnable parameters are fixed and used as preset parameters for the pre-built sleep staging model. The weight of category c, There are a total of 5 categories c, and the number of samples in each of the 5 categories is as follows: ; The training sample size is defined as the heart rate data of one subject within one time window. Index for sleep stages; For the one-hot encoding of the true label, if the true class of sample n is c, then ,otherwise ; Predict the probability that sample n belongs to class c for the model.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps of the method of claim 1.

Citation Information

Cited By

  • Sleep stage detection method and device, electronic equipment and storage medium

    CN122132931A