Sleep staging method based on Markov chain dynamic loss

By using a Markov chain-based dynamic loss method, combined with CNN and BiLSTM networks, and dynamically adjusting the loss weights, the problem of class imbalance in sleep staging methods is solved, thus improving staging accuracy.

CN120884256BActive Publication Date: 2025-12-02CHANGCHUN UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511439285.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-10
Publication Date
2025-12-02
Estimated Expiration
2045-10-10

AI Technical Summary

Technical Problem

Existing automatic sleep staging methods lack consideration for the physiological transition patterns of sleep stages when facing the problem of category imbalance, resulting in insufficient staging accuracy.

Method used

We employ a Markov chain-based dynamic loss method, which calculates the Markov transition probability matrix and combines CNN and BiLSTM networks to dynamically adjust the loss weights, thereby enhancing the ability to recognize physiological transitions.

Benefits of technology

This improves the physiological interpretability of sleep staging models in understanding and predicting overall sleep structure, and enhances staging accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120884256B_ABST
    Figure CN120884256B_ABST
Patent Text Reader

Abstract

This disclosure relates to a sleep staging method based on Markov chain dynamic loss, belonging to the field of data processing. The method includes: preprocessing EEG signals to obtain training samples, constructing and training a sleep staging model, and using the trained model for sleep staging. Training includes: calculating a basic classification loss; when the training sample transitions to different sleep stages, obtaining the true physiological transition probability through a Markov transition probability matrix; if the probability is less than a threshold, calculating a loss weight factor for the training sample based on whether the model correctly predicted the current sleep stage; calculating the average value of the sequence perception loss based on the loss weight factor and the basic classification loss; calculating the gradient of the average value with respect to the sleep staging model parameters, and updating the model parameters of the sleep staging model. This disclosure improves the physiological interpretability of the sleep staging model in understanding and predicting the overall sleep structure, thereby improving the accuracy of sleep staging.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of data processing, and in particular to a sleep staging method based on Markov chain dynamic loss. Background Technology

[0002] Sleep staging is a crucial foundation for assessing individual sleep quality and diagnosing sleep disorders. Sleep staging refers to the process of dividing the sleep process into different stages based on changes in physiological signals such as electroencephalography (EEG), electrooculography (EOG), and electromyography (EMG). Typically, sleep staging is divided into five stages: wakefulness (W), rapid eye movement (REM) sleep, and three non-rapid eye movement (N1, N2, and N3) stages.

[0003] Traditional manual sleep staging relies on experts to make judgments based on polysomnography data, which is not only time-consuming and labor-intensive but also highly dependent on experience. Therefore, researching efficient and accurate automatic sleep staging methods is of great significance. In recent years, deep learning methods have been widely used in this task due to their powerful feature extraction capabilities.

[0004] Currently, automatic sleep staging methods suffer from low accuracy, often due to class imbalance. The significant differences in the proportion of different sleep stages (e.g., N1, REM) throughout the night lead to a highly uneven distribution of training samples. To alleviate this problem, existing techniques mainly fall into two categories: data-level and algorithm-level strategies. Data-level sleep staging methods, such as oversampling and undersampling, aim to directly adjust the dataset distribution, but may introduce noise or lose information. In algorithm-level sleep staging methods, cost-sensitive learning adjusts the focus by assigning different misclassification costs to different classes or samples. The most direct approach is static class-weighted cross-entropy loss, which pre-sets higher weights for minority classes. More advanced methods, such as class-aware loss or confidence-driven weight adjustment mechanisms, introduce sample discriminative information to achieve dynamic weighting, increasing attention to hard-to-classify samples.

[0005] While these strategies have improved the accuracy of sleep staging to some extent, their weight adjustments largely rely on static categorical attributes or prediction results, failing to incorporate the structural information inherent in the sleep sequence itself. Even dynamic weighting schemes rarely consider the physiological transition patterns between sleep stages. This makes sleep staging methods lack the ability to judge the rationality of contextual transitions, thus resulting in relatively low accuracy. Summary of the Invention

[0006] Therefore, it is necessary to provide a sleep staging method based on Markov chain dynamic loss to address the issue that the accuracy of sleep staging methods needs to be improved.

[0007] To solve the above problems, the present disclosure adopts the following technical solution:

[0008] This disclosure provides a sleep staging method based on Markov chain dynamic loss, including the following steps:

[0009] Step 1: Preprocess the EEG signal by dividing it into fixed-length, non-overlapping EEG signal segments, and then calculate the Markov transition probability matrix based on these segments. ;

[0010] Step 2: Construct a sleep staging model based on a CNN module and a BiLSTM network module. The input of the sleep staging model is a segment of EEG signal, and the output is the predicted probability distribution of sleep stages.

[0011] Step 3, training the sleep staging model, includes: inputting training samples into the sleep staging model, and calculating the basic classification loss based on the predicted probability distribution of the sleep staging model for each training sample and the actual sleep stage. When the first Manually labeled sleep stages of training samples and the Manually labeled sleep stages of the previous training sample for each training sample During different sleep stages, through Get from Transfer to True physiological transfer probability ,like If the value is less than the transition probability threshold, then the sleep stage model is used to determine whether the first stage was correctly predicted. The sleep stage of the training sample is calculated. Loss weight factor for each training sample Based on each training sample and Calculate the average value of the sequence sensing loss. ;calculate The gradient of the sleep staging model parameters is calculated, and the model parameters of the sleep staging model are updated accordingly.

[0012] Step 4: Obtain the EEG signal to be staged, use the trained sleep staging model to perform sleep staging, and select the sleep stage with the highest predicted probability in the predicted probability distribution output by the model as the sleep staging result.

[0013] In a preferred embodiment, the step of preprocessing the EEG signal and dividing the preprocessed EEG signal into non-overlapping EEG signal segments of fixed length includes: acquiring a single-channel EEG signal from a sleep monitoring instrument; performing bandpass filtering and notch filtering on the EEG signal to obtain a preprocessed EEG signal; uniformly resampling the preprocessed EEG signal to a fixed frequency; and dividing the resampled EEG signal into non-overlapping EEG signal segments of fixed length.

[0014] In a preferred embodiment, the step of calculating the Markov transition probability matrix based on EEG signal segments includes: associating each EEG signal segment obtained in step 1 with a sleep stage artificially labeled for that EEG signal segment. The sleep stage and its preceding EEG signal segment in time sequence are artificially labeled. Based on temporally adjacent EEG signal segments, statistics were compiled from the sleep stage. Transition to sleep stage Based on the frequency of the transitions, construct a Markov transition counting matrix and calculate the Markov transition probability matrix. ;in, and Both indicate the sleep stage. Indicates the first Each sleep stage Indicates the first Each sleep stage.

[0015] In a preferred embodiment, the calculation of the Markov transition probability matrix... The steps include: row-normalizing the transition count matrix to obtain the Markov transition probability matrix. , satisfy:

[0016] ;

[0017] in, Represents the Markov transition probability matrix In the transition counting matrix, the first Line 1 Column elements; This represents the Markov transition counting matrix from the sleep stage. Transition to sleep stage Frequency; This represents the Markov transition counting matrix from the sleep stage. The sum of the frequencies of each sleep stage.

[0018] In a preferred embodiment, the training sample is a labeled EEG signal segment, the label including the artificially labeled sleep stage of the EEG signal segment and the artificially labeled sleep stage of the preceding EEG signal segment in the time sequence of the EEG signal segment.

[0019] In a preferred embodiment, the basic classification loss The calculation formula is:

[0020] ;

[0021] in, Indicates the first The actual sleep stages of each training sample; Indicates the first The predicted probability distribution of each training sample; Category number indicating sleep stage; This represents the total number of categories of sleep stages; Indicates the first The training sample truly belongs to the first... Indicators of sleep stages; The model predicts the first The training sample belongs to the first... The probability of each sleep stage; Indicates assignment to the first Static class weights for each sleep stage.

[0022] In a preferred embodiment, the step of determining whether the sleep stage model correctly predicted the first sleep stage is... The sleep stage of the training sample is calculated. Loss weight factor for each training sample The specific steps include:

[0023] If the sleep stage model correctly predicts the first... Sleep stages of training samples Then the first Loss weight factor for each training sample The calculation formula is:

[0024] ;

[0025] If the sleep stage model incorrectly predicts the first... Sleep stages of training samples Then the first Loss weight factor for each training sample The calculation formula is:

[0026] ;

[0027] in, This represents the initial weight of the sample, with a value of 1; This represents a coefficient used to control the magnitude of the reward. This is the minimum weight lower limit set; This represents the function that takes the maximum value. This represents a coefficient used to control the severity of punishment.

[0028] In a preferred embodiment, the calculation of the loss weight factor for each training sample... The steps also include: if the true physiological transfer probability If the loss weight factor for each training sample is greater than or equal to the transition probability threshold, then... Equal to 1; if the first Manually labeled sleep stages of training samples and the Manually labeled sleep stages of the previous training sample for each training sample When they are the same sleep stage, then the first Loss weight factor for each training sample It equals 1.

[0029] In a preferred embodiment, the step of basing each training sample on... and Calculate the average value of the sequence sensing loss. Specifically, it includes:

[0030] Loss weight factor for each training sample Its basic classification loss Multiply by each training sample to obtain the sequence-aware loss, and calculate the average value of the sequence-aware loss. The The calculation formula is:

[0031] ;

[0032] in, This represents the total number of training samples; Indicates the first The actual sleep stages of each training sample; Indicates the first The predicted probability distribution of each training sample; Indicates the first The basic classification loss for each sample .

[0033] In a preferred embodiment, updating the model parameters of the sleep staging model specifically involves updating the model parameters of the sleep staging model using the Adam optimization algorithm with a learning rate of 0.0001.

[0034] The aforementioned sleep staging method based on Markov chain dynamic loss calculates the Markov transition probability matrix based on EEG signal segments and incorporates the Markov transition probability as a physiological prior into the loss function during model training. This allows the adjustment of loss weights to not only consider class imbalance but, more importantly, to perceive the context of the sleep sequence and the rationality of physiological transitions. Consequently, it enhances the sleep staging model's understanding of the overall sleep structure and the physiological interpretability of its predictions, thereby improving the accuracy of the sleep staging method. Attached Figure Description

[0035] Figure 1 This is a flowchart illustrating a method in one embodiment of the present disclosure;

[0036] Figure 2 This is a schematic diagram of the sleep staging model in one embodiment of the present disclosure. Detailed Implementation

[0037] The present disclosure will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present disclosure and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the present disclosure are shown in the drawings, not the entire structure.

[0038] While existing technologies, particularly dynamic weight adjustment strategies, have improved the accuracy of sleep staging due to class imbalance to some extent, their core flaw lies in their general neglect of the inherent structure and physiological transition patterns of sleep stages as time series. They fail to consider crucial sequence context information—whether the transition from the previous sleep stage to the current sleep stage conforms to a physiological probability pattern. This makes it difficult for sleep staging methods to effectively learn and reinforce physiologically important but infrequent transition paths, and also prevents them from differentiating between classification errors based on the physiological rationality of the transition. Therefore, this disclosure provides a sleep staging method based on Markov chain dynamic loss to further improve the accuracy of sleep staging.

[0039] See Figure 1 Sleep staging methods based on Markov chain dynamic loss include:

[0040] Step 1: Preprocess the EEG signal by dividing it into several fixed-length, non-overlapping EEG signal segments, and then calculate the Markov transition probability matrix based on these segments. ;

[0041] Step 2: Construct a sleep staging model based on a CNN module and a BiLSTM network module. The input of the sleep staging model is an EEG signal segment, and the output is a predicted probability distribution of sleep stages.

[0042] Step 3, train the sleep staging model, including: inputting training samples into the sleep staging model, and calculating the basic classification loss for each training sample based on the actual sleep stages and the predicted probability distribution of sleep stages. ; Calculate the loss weight factor for each training sample Based on each training sample and Calculate the average value of the sequence sensing loss. ;calculate The gradient of the sleep staging model parameters is calculated, and the model parameters are updated accordingly; the loss weight factor for each training sample is calculated. The steps include: when the first Manually labeled sleep stages of training samples And the manually labeled sleep stage of the previous training sample in its time sequence. During different sleep stages, through Get from Transfer to True physiological transfer probability ,like If the value is less than the transition probability threshold, then the sleep stage model is used to determine whether the first stage was correctly predicted. The sleep stage of the training sample is calculated. Loss weight factor for each training sample ;

[0043] Step 4: Obtain the EEG signal to be staged, use the trained sleep staging model to stage the EEG signal to be staged, and select the sleep stage with the highest predicted probability in the predicted probability distribution output by the trained sleep staging model as the sleep staging result of the EEG signal to be staged.

[0044] The above methods will be described in detail below.

[0045] Step 1: Establish a training sample library and calculate the Markov transition probability matrix. The specific process is as follows:

[0046] Step 1.1: Acquire raw EEG signals, which are single-channel EEG signals, i.e., acquire single-channel EEG signal records from the sleep monitoring device. Preprocess the raw EEG signals, including bandpass filtering and notch filtering. Specifically, perform bandpass filtering (e.g., 0.5-45 Hz bandpass filtering) to remove low-frequency drift and high-frequency noise, and perform notch filtering (e.g., 50 Hz notch filtering) to eliminate power frequency interference.

[0047] Step 1.2: Resample the preprocessed EEG signals to a fixed frequency, such as 100 Hz, and divide them into several fixed-length, non-overlapping EEG signal segments (e.g., every 30 seconds). Each EEG segment is referred to as an epoch. Each epoch serves as an independent sample for subsequent model training. In other words, all EEG signal segments obtained in Step 1.2 are used as training samples for training the sleep staging model in Step 3.

[0048] Step 1.3: Associate each EEG signal segment obtained in Step 1.2 with the manually labeled sleep stage of that EEG signal segment. And the sleep stage artificially labeled with the preceding EEG signal segment in its time sequence. .

[0049] Obtain manually labeled information. Associate each epoch obtained in step 1.2 with its manually labeled sleep stage. In this embodiment, as one example, there are 5 categories, including W, N1, N2, N3, and REM, i.e., 5 sleep stages. W is the first sleep stage, N1 is the second sleep stage, N2 is the third sleep stage, N3 is the fourth sleep stage, and REM is the fifth sleep stage. (In addition to the first epoch) the manually labeled sleep stages of the preceding epoch (in the same subject's time series) are additionally recorded. This serves as preliminary information required for subsequent dynamic loss calculations. Indicates the first The sleep stage is a segment of brainwave signals that is manually labeled, that is, the first... The actual sleep stage of a segment of EEG signal. Indicates the first The sleep stage preceding the first EEG signal segment in the time sequence, i.e., the first... The timing of each EEG signal segment corresponds to the actual sleep stage of the preceding EEG signal segment.

[0050] Each EEG signal segment serves as a training sample (referred to as a sample), thus completing the establishment of the training sample library.

[0051] Step 1.4: Statistically analyze the frequency of sleep stage transitions between EEG signal segments over time; that is, analyze the sleep stages based on temporally adjacent EEG signal segments. Transition to sleep stage Based on the frequency of the data, a Markov transition count matrix is ​​constructed, and then a Markov transition probability matrix is ​​calculated from the Markov transition count matrix. Understandably, for the transition probabilities in a Markov chain, a transition includes a transition to itself.

[0052] Sleep stages in the complete labeled sequence of all subjects in the statistical sample Shift to sleep stage To determine the frequency of sleep stages, a 5×5 transition counting matrix (Markov transition counting matrix) is constructed, with each of the 5 rows and 5 columns corresponding to one of the five sleep stages. The transition counting matrix is ​​then row-normalized to obtain the Markov transition probability matrix. ,matrix satisfy:

[0053]

[0054] in, and All of these represent sleep stages (which can be the same or different sleep stages). Indicates the first Each sleep stage Indicates the first In this embodiment, there are several sleep stages. and All values ​​are 1, 2, 3, 4, 5. This represents the transition count matrix from the sleep stage (which can be directly obtained from this matrix). Transition to sleep stage frequency, This represents the transition counting matrix in the Markov transition (which indicates the transition from the sleep stage). The sum of the frequencies of transitions to each sleep stage. The index is used to traverse all sleep stage indices. Represents the normalized Markov transition probability matrix In the transition counting matrix, the first Line 1 The elements of the column are understandable. The diagonal element corresponds to the sleep stage. Shift to its own sleep stage The situation.

[0055] In this embodiment, the Markov transition probability matrix A 5×5 matrix can be called a first-order Markov transition probability matrix. The first-order refers to the model's "memory rule," meaning that it only predicts the next stage based on the current stage.

[0056] Understandably, the Markov transition count matrix is ​​a square matrix; the Markov transition probability matrix describes the set of transition probabilities between each sleep stage.

[0057] Step 1.5: Calculate the Markov transition probability matrix obtained in Step 1.4. Specifically, prior physiological information about sleep stage transitions is saved and loaded for use during subsequent model training. This information is also embedded in the loss function as a basis for dynamic weight adjustment, thereby guiding the model to focus more on stage transitions that conform to physiological laws.

[0058] Step 2: Construct a CNN+BiLSTM (based on CNN and BiLSTM network modules) sleep staging model. The input of the sleep staging model is an EEG signal segment, and the output is a predicted probability distribution of sleep stages. The CNN module is used to extract sleep stage discriminative features from the EEG signal segments, and the BiLSTM network module is used to perform sequence modeling based on the sleep stage discriminative features.

[0059] The overall structure of the model is as follows: Figure 2 As shown, the sleep staging model includes a feature extraction module and a sequence modeling and classification module. The CNN module serves as the feature extraction module, while the sequence modeling and classification module includes a BiLSTM network module and fully connected layers. The fully connected layers are used to classify sleep stages based on the output of the BiLSTM network module.

[0060] The CNN module consists of four one-dimensional convolutional layers. The first convolutional layer has 64 kernels with a kernel size of 50 and a stride of 8. The relatively large kernels are designed to capture long time-window information in the low-frequency range. The second and third convolutional layers both use 128 kernels with a kernel size of 8 and a stride of 1, aiming to extract fine-grained features in the mid-to-high frequency range. The fourth convolutional layer has 64 kernels with a kernel size of 8 and a stride of 1. Each convolutional layer in the CNN is followed by batch normalization and the Leaky ReLU (Leaky Rectified Linear Unit) activation function to improve training stability and non-linear expressive power. Two max-pooling layers are embedded in the CNN: the first max-pooling layer (between the first and second convolutional layers) has a kernel size of 8 and a stride of 8 to significantly reduce the time dimension; the second max-pooling layer (after the fourth convolutional layer) has a kernel size of 4 and a stride of 4 to further compress the feature size. To prevent overfitting, a random deactivation layer with a deactivation probability of 0.5 is added between the first max pooling layer and the first max pooling layer.

[0061] The CNN module is used to extract temporal features from EEG signal segments, which serve as discriminative features for sleep stages. The extracted temporal features are input into a Bidirectional Long Short-Term Memory (BiLSTM) network module, which performs sequence modeling and outputs a temporal feature vector. The BiLSTM network module integrates contextual information from preceding and following moments through recurrent units in both forward and backward directions, more accurately modeling the temporal dependence of sleep stages and improving the discriminative performance of sleep stages. The sequence modeling and classification module flattens the temporal feature vector and inputs it into a fully connected layer for classification. The classifier in the fully connected layer uses a Softmax activation function to output the probability distribution of each sleep stage, thus obtaining a preliminary predicted probability distribution of each sleep stage, enabling the prediction of the sleep stage of the current EEG epoch.

[0062] Step 3: Train the sleep staging model constructed in Step 2 using the EEG signal fragments obtained in Step 1. In this step, the Markov transition probability matrix of sleep stages is introduced as a physiological prior, and the loss weight of each sample is dynamically adjusted, thereby enhancing the model's sensitivity to key transition events in the sleep stage sequence, improving the model's ability to identify rare but important state transitions, and effectively alleviating the class imbalance problem.

[0063] Step 3 includes:

[0064] Step 3.1: Input each epoch obtained in Step 1.2 (input size 1 channel × 3000 sampling points) into a Convolutional Neural Network (CNN) module to extract temporal features, which serve as discriminative features for sleep stages. The extracted temporal features are then input into a Bidirectional Long Short-Term Memory (BiLSTM) network for sequence modeling. The BiLSTM network outputs a temporal feature vector. This temporal feature vector is flattened and then input into a fully connected layer for classification. The classifier's final layer uses a Softmax activation function to output the probability distribution of each sleep stage, thus obtaining the preliminary predicted probability distribution of each sleep stage, i.e., the predicted probability distribution of each training sample. .

[0065] The training samples are labeled EEG signal segments. The labels include the manually labeled sleep stage of the EEG signal segment and the manually labeled sleep stage of the preceding EEG signal segment in the time sequence of the EEG signal segment. It is understood that for the first EEG signal segment among all the EEG signal segments of each subject, the label "the manually labeled sleep stage of the preceding EEG signal segment in the time sequence of the EEG signal segment" is assumed to be unavailable, or is assumed to still be its own sleep stage, and no limitation is made here.

[0066] Step 3.2: Predict the probability distribution for each sample in Step 3.1. and their corresponding actual sleep stages That's understandable. That is equivalent to Calculate the basic classification loss for each sample. The underlying loss is in the form of class-weighted cross-entropy, where each sleep stage... Assign a static class weight To alleviate the problem of data class imbalance, the specific calculation formula is as follows:

[0067]

[0068] in, and All indicate (the first) The basic classification loss for each training sample. Indicates the first The actual sleep stages of each training sample; Indicates the first The predicted probability distribution of each training sample; Indicates the first The basic classification loss for each sample ; Indicates the sample number; Category number indicating sleep stage; It represents the total number of categories of sleep stages; It is the first The sample truly belongs to the first... Sleep stages The indicator (1 in one-hot encoding, otherwise 0). Indicates that it belongs to the first The training sample belongs to the first... Sleep stages Not belonging to time The value is 0; The model predicts the first The training sample belongs to the first... Sleep stages The probability of, i.e., the probability of, the first The sample belongs to the first Sleep stages The initial predicted probability; Representative assigned to the first Sleep stages The static class weights are designed to increase the influence of minority classes in loss calculation.

[0069] Step 3.3: Utilize the current epoch (the epoch number) Manually labeled sleep stages (from 10 training samples) Manually labeled sleep stages relative to the previous training sample in time sequence ,when and When it is a different sleep stage, combine the Markov transition probability matrix loaded in step 1.5. The query yielded results from the sleep stage. Shift to sleep stage True physiological transfer probability :

[0070]

[0071] in, Represents the Markov transition probability matrix The records from the sleep stage Shift to sleep stage The probability value.

[0072] Step 3.4: Based on the actual physiological metastasis probability, determine the metastasis. If the transition is rare, then calculate the sample's loss weight factor based on whether the sleep staging model correctly predicted the current sleep stage. If it is not a rare shift, then the loss weighting factor for each sample is... In other words, if the actual physiological transfer probability... If the transition probability is greater than or equal to the threshold, then the first... Loss weight factor for each training sample Equal to 1; if the first Manually labeled sleep stages of training samples and the Manually labeled sleep stages of the previous training sample for each training sample If the sleep stages are the same, then there is no need to determine the relationship between the true physiological transition probability and the transition probability threshold; the first stage can be directly defined. Loss weight factor for each training sample It equals 1.

[0073] Specifically, based on transition probability And whether the model correctly predicted the sleep stage of the current sample, dynamically calculate the loss weight factor. Set a transition probability threshold. Transition probability threshold Used to distinguish common metastases ( ) and rare metastases ( < The specific strategy is as follows:

[0074] For rare transitions, use dynamic weighting factors. Calculate the loss weighting factor For common shifts, the loss weighting factor Keep it at 1, without dynamic adjustment. For the first training sample, the default value is set to 1. It equals 1.

[0075] For rare transitions, if the model correctly predicts the current sample (the first one)... Sleep stages of training samples If a low-conversion event is successfully captured, a "reward" is given for the loss, namely a dynamic weighting factor. It will be multiplied by a reward factor less than 1:

[0076]

[0077] in, This represents the initial weight, with an initial value of 1; This represents a coefficient used to control the magnitude of the reward. This reflects its rarity; A minimum weight lower bound (e.g., 0.1) is set to prevent gradient vanishing. This represents the function that takes the maximum value.

[0078] For rare transitions, if the model predicts incorrectly, it is considered a misjudgment of a key transition and requires a "penalty," namely a dynamic weighting factor. It will be multiplied by a factor greater than 1:

[0079]

[0080] in, This represents a coefficient used to control the severity of punishment.

[0081] Step 3.5: Adjust the loss weighting factor for each sample. Its basic classification loss Multiply by each sample to obtain the sequence sensing loss for each sample, and then calculate the average value of the sequence sensing loss. For those containing The average loss for a training batch of samples is defined as:

[0082]

[0083] Step 3.6: Calculate the average value of the sequence sensing loss. The gradients of the sleep staging model parameters are calculated, and the parameters are updated using the Adam optimization algorithm (Adaptive Moment Estimation) with a learning rate of 0.0001.

[0084] The model training process in step 3 continues until the preset termination conditions are met: reaching the maximum number of training epochs (100 epochs) or no significant performance improvement on the validation set for 10 consecutive epochs.

[0085] Step 4: Evaluate the performance of the model trained in Step 3 on independent test data; acquire the EEG signal to be staged, divide the EEG signal to be staged into several non-overlapping EEG signal segments of the same length as in Step 1, input the segments to be staged into the trained sleep staging model, obtain the output of the trained sleep staging model, select the sleep stage with the highest predicted probability in the predicted probability distribution of the trained sleep staging model as the sleep staging result of the EEG signal segment; splice the staging results of all EEG data segments in chronological order to obtain the sleep staging result of the EEG data to be predicted.

[0086] Step 4.1: After the training phase, evaluate the model's performance using the reserved test set. Evaluation metrics include overall accuracy, precision at each sleep stage, recall, F1 score, and Cohen's Kappa coefficient, which measure the model's classification ability, stability, and adaptability to imbalanced data from multiple dimensions.

[0087] Step 4.2: For the EEG signals to be staged, the acquired data is new, unlabeled single-channel EEG sleep data exported from the sleep monitoring instrument. A trained model is used for forward inference. Bandpass filtering and notch filtering are applied to the EEG signals to be staged to obtain preprocessed EEG signals. The preprocessed EEG signals are then uniformly resampled to a fixed frequency and divided into several fixed-length, non-overlapping EEG signal segments. The predicted probability distribution of sleep stages corresponding to each EEG signal segment is obtained. Finally, the stage with the highest predicted probability is taken as the sleep stage result for that EEG signal segment. These segments are then sequentially concatenated to obtain the sleep stage sequence for the entire night, i.e., the sleep stage results of the entire night's EEG signals, providing basic data support for subsequent clinical analysis or sleep structure assessment.

[0088] This disclosed sleep staging method based on Markov chain dynamic loss calculates the Markov transition probability matrix based on EEG signal segments and incorporates the Markov transition probabilities of sleep stages as physiological priors into the dynamic weighting mechanism of the loss function. This allows the loss weight adjustment to not only consider class imbalance but, more importantly, to perceive the context of the sleep sequence and the rationality of physiological transitions. This enables more effective modeling of key low-frequency physiological transitions, strengthens the sleep staging model's ability to identify and model physiologically reasonable stage transitions, improves the physiological interpretability of the sleep staging model in understanding and predicting the overall sleep structure, and enhances the accuracy of the sleep staging method.

[0089] Specifically, this disclosure further enhances the model's ability to identify and model physiologically reasonable stage transitions by adjusting the weights of training samples through rewards and penalties.

[0090] This disclosure provides a sleep staging system based on Markov chain dynamic loss, including:

[0091] The preprocessing module is used to preprocess the EEG signal, dividing the preprocessed EEG signal into fixed-length non-overlapping EEG signal segments, and calculating the Markov transition probability matrix based on the EEG signal segments. ;

[0092] The model building module is used to build a sleep staging model based on a CNN module and a BiLSTM network module. The input of the sleep staging model is an EEG signal segment, and the output is a predicted probability distribution of sleep stages. The CNN module is used to extract sleep stage discriminative features from the EEG signal segments, and the BiLSTM network module is used to perform sequence modeling based on the sleep stage discriminative features.

[0093] The training module, used to train the sleep staging model, includes: inputting training samples into the sleep staging model, and calculating the base classification loss for each training sample based on the actual sleep stages and the predicted probability distribution of sleep stages. ; Used to calculate the loss weight factor for each training sample ; used for each training sample and Calculate the average value of the sequence sensing loss. Used for calculation The gradient of the sleep staging model parameters is calculated, and the model parameters are updated accordingly; the loss weight factor used to calculate each training sample is also calculated. Includes: for use when the first Manually labeled sleep stages of training samples And the manually labeled sleep stage of the previous training sample in its time sequence. During different sleep stages, through Get from Transfer to True physiological transfer probability ,like If the value is less than the transition probability threshold, then the sleep stage model is used to determine whether the first stage was correctly predicted. The sleep stage of the training sample is calculated. Loss weight factor for each training sample ;

[0094] The prediction module is used to acquire the EEG signal to be staged, to perform sleep staging using a trained sleep staging model, and to select the sleep stage with the highest predicted probability from the predicted probability distribution output by the model as the sleep staging result.

[0095] In specific implementation, the sleep staging system based on Markov chain dynamic loss can refer to the sleep staging method based on Markov chain dynamic loss in any of the above embodiments to achieve sleep staging prediction. The specific implementation steps will not be repeated.

[0096] An electronic device can be implemented according to the method of this disclosure, the electronic device comprising: a memory; one or more processors; one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including instructions for executing a sleep staging method based on Markov chain dynamic loss according to any of the above embodiments.

[0097] This disclosure also provides a computer-readable storage medium including instructions that, when executed on a computer, cause the computer to perform the steps of the sleep staging method based on Markov chain dynamic loss as described in any of the above embodiments.

[0098] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0099] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this disclosure, and not to limit them; under the concept of this disclosure, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of this disclosure as described above, which are not provided in detail for the sake of brevity; although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this disclosure.

[0100] Although preferred embodiments of this disclosure have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of this disclosure. Clearly, those skilled in the art can make various alterations and modifications to this disclosure without departing from its spirit and scope. Thus, this disclosure also intends to include any such alterations and modifications that fall within the scope of the claims of this disclosure and their equivalents.

Claims

1. A sleep staging method based on Markov chain dynamic loss, characterized in that, Includes the following steps: Step 1: Preprocess the EEG signal by dividing it into fixed-length, non-overlapping EEG signal segments, and then calculate the Markov transition probability matrix based on these segments. ; Step 2: Construct a sleep staging model based on a CNN module and a BiLSTM network module. The input of the sleep staging model is a segment of EEG signal, and the output is the predicted probability distribution of sleep stages. Step 3, train the sleep staging model, including: inputting training samples into the sleep staging model, and calculating the basic classification loss for each training sample based on the actual sleep stages and the predicted probability distribution of sleep stages. ; Calculate the loss weight factor for each training sample Based on each training sample and Calculate the average value of the sequence sensing loss. ;calculate The gradient of the sleep staging model parameters is calculated, and the model parameters are updated accordingly; the loss weight factor for each training sample is calculated. The steps include: when the first Manually labeled sleep stages of training samples And the manually labeled sleep stage of the previous training sample in its time sequence. During different sleep stages, through Get from Transfer to True physiological transfer probability ,like If the value is less than the transition probability threshold, then the sleep stage model is used to determine whether the first stage was correctly predicted. The sleep stage of the training sample is calculated. Loss weight factor for each training sample ; Step 4: Obtain the EEG signal to be staged, use the trained sleep staging model to perform sleep staging, and select the sleep stage with the highest predicted probability in the predicted probability distribution output by the model as the sleep staging result.

2. The sleep staging method based on Markov chain dynamic loss according to claim 1, characterized in that, The step of preprocessing the EEG signal and dividing the preprocessed EEG signal into non-overlapping EEG signal segments of fixed length includes: acquiring a single-channel EEG signal from a sleep monitoring instrument; performing bandpass filtering and notch filtering on the EEG signal to obtain a preprocessed EEG signal; uniformly resampling the preprocessed EEG signal to a fixed frequency; and dividing the resampled EEG signal into non-overlapping EEG signal segments of fixed length.

3. The sleep staging method based on Markov chain dynamic loss according to claim 1, characterized in that, The step of calculating the Markov transition probability matrix based on EEG signal segments includes: associating each EEG signal segment obtained in step 1 with a sleep stage manually labeled for that EEG signal segment. The sleep stage and its preceding EEG signal segment in time sequence are artificially labeled. Based on temporally adjacent EEG signal segments, statistics were compiled from the sleep stage. Transition to sleep stage Based on the frequency of the transitions, construct a Markov transition counting matrix and calculate the Markov transition probability matrix. ;in, and Both indicate the sleep stage. Indicates the first Each sleep stage Indicates the first Each sleep stage.

4. The sleep staging method based on Markov chain dynamic loss according to claim 3, characterized in that, The calculation of the Markov transition probability matrix The steps include: row-normalizing the transition count matrix to obtain the Markov transition probability matrix. , satisfy: ; in, Represents the Markov transition probability matrix In the transition counting matrix, the first Line number Column elements; This represents the Markov transition counting matrix from the sleep stage. Transition to sleep stage Frequency; This represents the Markov transition counting matrix from the sleep stage. The sum of the frequencies of each sleep stage.

5. The sleep staging method based on Markov chain dynamic loss according to claim 1, characterized in that, The training samples are labeled EEG signal segments, with the labels including the manually labeled sleep stage of the EEG signal segment and the manually labeled sleep stage of the preceding EEG signal segment in the time sequence of the EEG signal segment.

6. The sleep staging method based on Markov chain dynamic loss according to claim 1, characterized in that, The basic classification loss The calculation formula is: ; in, Indicates the first The actual sleep stages of each training sample; Indicates the first The predicted probability distribution of each training sample; Category number indicating sleep stage; This represents the total number of categories of sleep stages; Indicates the first The training sample truly belongs to the first... Indicators of sleep stages; The model predicts the first The training sample belongs to the first... The probability of each sleep stage; Indicates assignment to the first Static class weights for each sleep stage.

7. The sleep staging method based on Markov chain dynamic loss according to claim 1, characterized in that, The question is whether the sleep stage model correctly predicted the first... The sleep stage of the training sample is calculated. Loss weight factor for each training sample The specific steps include: If the sleep stage model correctly predicts the first... Sleep stages of training samples Then the first Loss weight factor for each training sample The calculation formula is: ; If the sleep stage model incorrectly predicts the first... Sleep stages of training samples Then the first Loss weight factor for each training sample The calculation formula is: ; in, This represents the initial weight, with a value of 1; This represents a coefficient used to control the magnitude of the reward. This is the minimum weight lower limit set; This represents the function that takes the maximum value. This represents a coefficient used to control the severity of punishment.

8. The sleep staging method based on Markov chain dynamic loss according to claim 1, characterized in that, The loss weight factor for each training sample is calculated. The steps also include: if the true physiological transfer probability If the transition probability is greater than or equal to the threshold, then the first... Loss weight factor for each training sample Equal to 1; if the first Manually labeled sleep stages of training samples and the Manually labeled sleep stages of the previous training sample for each training sample If they are the same sleep stage, then the first Loss weight factor for each training sample It equals 1.

9. The sleep staging method based on Markov chain dynamic loss according to claim 1, characterized in that, The method based on each training sample and Calculate the average value of the sequence sensing loss. Specifically, it includes: Loss weight factor for each training sample Its basic classification loss Multiply by each training sample to obtain the sequence-aware loss, and calculate the average value of the sequence-aware loss. The The calculation formula is: ; in, This represents the total number of training samples; Indicates the first The actual sleep stages of each training sample; Indicates the first The predicted probability distribution of each training sample; Indicates the first The basic classification loss for each training sample .

10. The sleep staging method based on Markov chain dynamic loss according to claim 1, characterized in that, The specific steps for updating the model parameters of the sleep staging model are as follows: the model parameters of the sleep staging model are updated using the Adam optimization algorithm with a learning rate of 0.0001.

Citation Information

Patent Citations

  • Multi-mode sleep staging method based on time sequence relevance driving

    CN112450881A

  • Multi-mode sleep staging emotion recognition method based on Dual-CNN + GAN

    CN118750000A