Sleep staging method based on Markov chain dynamic loss

CN120884256AActive Publication Date: 2025-11-04CHANGCHUN UNIV OF SCI & TECH

Patent Information

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

Smart Images

  • Figure CN120884256A_ABST
    Figure CN120884256A_ABST
Patent Text Reader

Abstract

The invention relates to a sleep staging method based on Markov chain dynamic loss, and relates to the field of data processing. The method comprises the steps that electroencephalogram signals are preprocessed to obtain training samples, a sleep staging model is constructed and trained, sleep staging is conducted through the trained model, and training comprises the steps that basic classification loss is calculated; when the sleep stage of the training sample is transferred to different stages, obtaining a real physiological transition probability through a Markov transition probability matrix, and if the probability is smaller than a threshold value, calculating a loss weight factor of the training sample according to whether the model correctly predicts the sleep stage of the current training sample; calculating an average value of the sequence sensing loss according to the loss weight factor and the basic classification loss; and calculating the gradient of the average value to the parameters of the sleep staging model, and updating the model parameters of the sleep staging model. According to the method and the device, the physiological interpretability of understanding and prediction of the sleep staging model on the overall sleep structure is improved, and then the sleep staging accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

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

[0002] Sleep staging is an important basis for evaluating the sleep quality of individuals and diagnosing sleep disorders. Sleep staging refers to a process of dividing the sleep process into different stages according to the changes in physiological signals such as electroencephalogram (EEG), electrooculogram (EOG), and electromyogram (EMG). Generally, sleep staging is divided into five stages, namely, a wake stage (W), a rapid eye movement stage (REM), and three non-rapid eye movement stages (N1, N2, and N3).

[0003] Traditional manual 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, it is of great significance to study an efficient and accurate automatic sleep staging method. In recent years, deep learning methods have been widely used in this task due to their strong feature extraction capabilities.

[0004] Currently, the staging accuracy of automatic sleep staging methods is low, which is usually due to class imbalance. Since the proportions of different sleep stages (such as N1 and REM) in the entire night sleep are significantly different, the distribution of training samples is highly uneven. To alleviate this problem, existing technologies are mainly divided into data-level and algorithm-level strategies. Data-level sleep staging methods such as oversampling and undersampling aim to directly adjust the data set 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 one is static class-weighted cross-entropy loss, which presets higher weights for minority classes. More advanced methods, such as class-aware loss or confidence-driven weight adjustment mechanism, introduce sample discriminability information to achieve dynamic weighting, improving the attention to difficult-to-classify samples.

[0005] Although these strategies improve the accuracy of sleep staging to some extent, their weight adjustment relies mainly on static class attributes or prediction results, and the structural information contained in the sleep sequence itself has not been introduced. Even the dynamic weighting scheme, few methods consider the physiological transfer patterns between sleep stages. This makes sleep staging methods lack the ability to reasonably judge the context transition, and thus the accuracy of sleep staging methods is still low. SUMMARY

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

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

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

[0009] Step 1, pre-processing the electroencephalogram signal, dividing the pre-processed electroencephalogram signal into non-overlapping electroencephalogram signal segments of fixed length, and calculating a Markov transition probability matrix according to the electroencephalogram signal segments

[0010] Step 2, constructing a sleep staging model based on a CNN module and a BiLSTM network module, the input of the sleep staging model being the electroencephalogram signal segment and the output being a sleep stage prediction probability distribution;

[0011] Step 3, training the sleep staging model, comprising: inputting training samples into the sleep staging model, calculating a basic classification loss according to the prediction probability distribution of each training sample and the real sleep stage of the sleep staging model ; when the artificial labeled sleep stage of the th training sample is different from the artificial labeled sleep stage of the previous training sample of the th training sample , the real physiological transition probability from to is obtained through , and if is less than a transition probability threshold, then a loss weight factor of the th training sample is calculated according to whether the sleep stage of the th training sample is correctly predicted by the sleep staging model ; the average value of the sequence-aware loss is calculated according to and of each training sample ; the gradient of on the parameters of the sleep staging model is calculated, and the model parameters of the sleep staging model are updated Step 4, obtaining the electroencephalogram signal to be staged, using the trained sleep staging model to perform sleep staging, and selecting the sleep stage with the maximum prediction probability in the prediction probability distribution output by the model as the sleep staging result.

[0012] Step 4, obtaining the electroencephalogram signal to be staged, using the trained sleep staging model to perform sleep staging, and selecting the sleep stage with the maximum prediction probability in the prediction 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 an EEG signal segment with a label, the label including an artificial sleep stage label of the EEG signal segment and an artificial sleep stage label of a previous EEG signal segment in time sequence of the EEG signal segment.

[0019] In a preferred embodiment, the base classification loss is calculated according to the following formula:

[0020] ;

[0021] wherein, y i represents a true sleep stage of an i-th training sample; p i represents a predicted probability distribution of the i-th training sample; c represents a class number of a sleep stage; C represents a total number of sleep stages; I i represents an indicator that the i-th training sample actually belongs to a j-th sleep stage; p i represents a probability that the i-th training sample belongs to the j-th sleep stage predicted by the model; w j represents a static class weight assigned to the j-th sleep stage. In a preferred embodiment, the step of calculating a loss weight factor w i of the i-th training sample according to whether the sleep staging model correctly predicts a sleep stage of the i-th training sample specifically includes: If the sleep staging model correctly predicts the sleep stage of the i-th training sample , the loss weight factor w i of the i-th training sample is calculated according to the following formula:

[0022] If the sleep staging model incorrectly predicts the sleep stage of the i-th training sample , the loss weight factor w i of the i-th training sample is calculated according to the following formula:

[0023]

[0024] ;

[0025]

[0026] ;

[0027] wherein,​​​​​​​​​​​​​​​​ represents the initial weight of the sample, and the value is 1; represents a coefficient for controlling the reward amplitude; is a set minimum weight lower limit; represents a maximum value function; represents a coefficient for controlling the punishment strength.

[0028] In a preferred embodiment, the step of calculating the loss weight factor of each training sample further comprises: if the real physiological transition probability is greater than or equal to a transition probability threshold, the loss weight factor of each training sample is equal to 1; if the artificial labeled sleep stage of the th training sample is the same as the artificial labeled sleep stage of the previous training sample of the th training sample, the loss weight factor of the th training sample is equal to 1.

[0029] In a preferred embodiment, the average value of the sequence-aware loss is calculated according to the and of each training sample, and the calculation formula is:

[0030] The loss weight factor of each training sample is multiplied by the basic classification loss of the training sample to obtain the sequence-aware loss of each training sample, and the average value of the sequence-aware loss is calculated, and the calculation formula of the average value of the sequence-aware loss is:

[0031] ;

[0032] wherein, represents the total number of training samples; represents the real sleep stage of the th training sample; represents the predicted probability distribution of the th training sample; represents the basic classification loss of the th sample.

[0033] In a preferred embodiment, the model parameters of the sleep staging model are updated by using an Adam optimization algorithm with a learning rate of 0.0001. ​​​​​​​​​

[0034] The sleep staging method based on Markov chain dynamic loss calculates a Markov transition probability matrix according to the electroencephalogram segment, and incorporates the Markov transition probability into the loss function of model training as a physiological prior, so that the loss weight adjustment not only considers the class imbalance, but more importantly, perceives the context of the sleep sequence and the rationality of the physiological conversion, thereby improving the physiological interpretability of the sleep staging model in understanding and predicting the overall sleep structure, and improving the accuracy of the sleep staging method. BRIEF DESCRIPTION OF DRAWINGS

[0035] Figure 1 A flowchart of the method in one embodiment of the present disclosure is shown.

[0036] Figure 2 A structural diagram of the sleep staging model in one embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0037] The present disclosure will be further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely intended to explain the present disclosure, but not to limit the present disclosure. In addition, it should be noted that only parts related to the present disclosure are shown in the drawings for the convenience of description.

[0038] Although the prior art, in particular the dynamic weight adjustment strategy, has improved the problem of low sleep staging accuracy caused by class imbalance to some extent, its core defect lies in generally ignoring the inherent structure and physiological conversion rule of sleep stages as time series, and not taking into account the key sequence context information of whether the transition from the previous sleep stage to the current sleep stage conforms to the physiological probability pattern, which makes it difficult for the sleep staging method to effectively learn and strengthen those conversion paths that are important in physiology but occur less frequently, and also unable to distinguish different classification errors according to the physiological reasonableness of the conversion. Therefore, the present disclosure provides a sleep staging method based on Markov chain dynamic loss to further improve the staging accuracy of sleep staging.

[0039] Referring to Figure 1 , the sleep staging method based on Markov chain dynamic loss comprises:

[0040] Step 1, pre-processing the electroencephalogram, dividing the pre-processed electroencephalogram into a plurality of non-overlapping electroencephalogram segments of a fixed length, and calculating a Markov transition probability matrix according to the electroencephalogram segments ;

[0041] Step 2, constructing a sleep staging model based on a CNN module and a BiLSTM network module, the input of the sleep staging model being the electroencephalogram segment, and the output being a sleep stage prediction probability distribution;

[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, re-sampling the pre-processed EEG signals to a fixed frequency, for example, 100 Hz, and dividing them into a number of non-overlapping EEG signal segments of fixed length (for example, 30 seconds), which are referred to as epochs. Each epoch is used as an independent sample for subsequent model training. That is, all the EEG signal segments obtained by step 1.2 are used as training samples for training the sleep staging model in step 3.

[0048] Step 1.3, associating each EEG signal segment obtained in step 1.2 with the sleep stage annotated by a human for the EEG signal segment .

[0049] Obtain the manually annotated label information. For each epoch obtained in step 1.2, associate it with the sleep stage annotated by a human, in this embodiment, as an example, the class is 5, including W, N1, N2, N3 and REM, i.e. 5 sleep stages, W is the 1st sleep stage, N1 is the 2nd sleep stage, N2 is the 3rd sleep stage, N3 is the 4th sleep stage, and REM is the 5th sleep stage. (In addition to the first epoch) additionally record the manually annotated sleep stage of the previous epoch (in time sequence of the same subject) as the prerequisite information required for subsequent dynamic loss calculation. Among them, represents the sleep stage annotated by a human for the EEG signal segment, i.e. the true sleep stage of the EEG signal segment , represents the sleep stage annotated by a human for the EEG signal segment in time sequence, i.e. the true sleep stage of the EEG signal segment in time sequence .

[0050] Each EEG signal segment is used as a training sample (referred to as a sample for short), and the establishment of the training sample library is thus completed.

[0051] Step 1.4, count the frequency of sleep stage transition of EEG signal segments in time sequence, i.e. according to adjacent EEG signal segments in time sequence, count the frequency of sleep stage transition to sleep stage , construct a Markov transition count matrix according to the statistical result, and calculate a Markov transition probability matrix from the Markov transition count matrix. It can be understood that for the transition probability in the Markov chain, the transition includes 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 of 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 counting 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. Save, specifically, as the physiological aspects of sleep stage transition priori information save, load in subsequent model training process, and embedded in the loss function as the basis for dynamic weight adjustment, so as to guide the model to pay more attention to the physiological law of stage conversion.

[0058] Step 2, build CNN+BiLSTM (based on CNN module and BiLSTM network module) sleep staging model, the input of the sleep staging model is the EEG signal segment, and the output is the sleep stage prediction probability distribution, the CNN module is used to extract the sleep stage discriminative features of the EEG signal segment, and the BiLSTM network module is used for sequence modeling according to the sleep stage discriminative features;

[0059] The overall structure of the model is shown in Figure 2 The sleep staging model includes a feature extraction module and a sequence modeling and classification module, the CNN module is used as the feature extraction module, the sequence modeling and classification module includes a BiLSTM network module and a full connection layer, and the full connection layer is used for sleep stage classification based on the output of the BiLSTM network module.

[0060] The CNN module is composed of four one-dimensional convolution layers, the first convolution layer is provided with 64 convolution kernels, the kernel size is 50, and the step is 8, the convolution kernel is large, and the long-time window information in the low frequency band is captured. The second convolution layer and the third convolution layer each adopt a convolution layer with 128 convolution kernels, a kernel size of 8 and a step of 1, which is used to extract fine-grained features in the middle and high frequency bands. The fourth convolution layer has 64 convolution kernels, a kernel size of 8 and a step of 1. Batch normalization and LeakyReLU (Leaky Rectified Linear Unit) activation function are used after each convolution layer in the CNN to improve the stability of training and nonlinear expression ability. Two maximum pooling layers are embedded in the CNN, the first layer maximum pooling layer between the first layer convolution layer and the second layer convolution layer has a pooling kernel size of 8 and a step of 8, which is used to significantly reduce the time dimension, and the second layer pooling kernel size is 4 and the step is 4, which is used to further compress the feature scale. In order to prevent overfitting, a random inactivation layer with an inactivation probability of 0.5 is also used in the network, which is added between the first layer maximum pooling layer and the first layer maximum pooling layer.

[0061] The CNN module is used to extract the time domain features of the EEG signal segment, and the time domain features are used as sleep stage discriminative features. The extracted time domain features are input into a bidirectional long short-term memory network module (BiLSTM network module), and the BiLSTM network module performs sequence modeling and outputs a time sequence feature vector. The BiLSTM network module integrates the context information of the previous and subsequent time points through the forward and backward two-directional cycle units, more accurately models the time dependence of the sleep stage, and improves the discrimination performance of sleep staging. The sequence modeling and classification module flattens the time sequence feature vector, and then inputs the flattened time sequence feature vector into a fully connected layer for classification. The classifier of the last layer of the fully connected layer adopts a Softmax activation function to output the probability distribution of each sleep stage, thereby obtaining the preliminary predicted probability distribution of each sleep stage, and realizing the prediction of the sleep stage of the current EEG signal epoch.

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

[0063] The step 3 includes:

[0064] Step 3.1, input each epoch (input size is 1 channel x 3000 sampling points) obtained in step 1.2 into a convolutional neural network (CNN) module to extract time domain features, and the time domain features are used as sleep stage discriminative features. The extracted time domain features are input into a bidirectional long short-term memory network (BiLSTM network) for sequence modeling, and the BiLSTM network outputs a time sequence feature vector. The time sequence feature vector is flattened, and then input into a fully connected layer for classification. The classifier of the last layer of the fully connected layer adopts a Softmax activation function to output the probability distribution of each sleep stage, thereby obtaining the preliminary predicted probability distribution of each sleep stage, and obtaining the prediction probability distribution of each training sample .

[0065] The training sample is an EEG signal segment with a label, and the label includes an artificially labeled sleep stage of the EEG signal segment and an artificially labeled sleep stage of a previous EEG signal segment in time sequence of the EEG signal segment. It can be understood that for the EEG signal segment ranked first among all EEG signal segments of each subject, the artificially labeled sleep stage of the previous EEG signal segment in time sequence in the label is defaulted as no information, or defaulted as still the sleep stage of itself, which is not limited herein.

[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 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, a dynamic weight factor is utilized The loss weight factor is calculated For common transitions, the loss weight factor is kept as 1 and is not dynamically adjusted. For the first training sample, the corresponding is equal to 1 by default.

[0075] For rare transitions, if the model correctly predicts the sleep stage of the current sample (the first training sample), it is considered as successfully capturing the low- conversion event, and the loss is given a "reward" in this case, i.e., the dynamic weight factor will be multiplied by a reward factor less than 1:

[0076]

[0077] where represents the initial weight, with an initial value of 1; represents a coefficient for controlling the reward amplitude; represents the degree of rarity; is the set minimum weight lower limit (e.g., 0.1) to prevent gradient disappearance, represents the maximum value function.

[0078] For rare transitions, if the model prediction is incorrect, it is considered as a misjudgment of the key transition and needs to be "punished", i.e., the dynamic weight factor will be multiplied by a factor greater than 1:

[0079]

[0080] where represents a coefficient for controlling the punishment intensity.

[0081] Step 3.5, multiply the loss weight factor of each sample with its basic classification loss to obtain the sequence-aware loss of each sample, and calculate the average value of the sequence-aware loss . For a training batch containing samples, the average loss is defined as:

[0082]

[0083] Step 3.6, calculate the average value of the sequence-aware loss of the sleep staging model parameters, and use the Adam optimization algorithm (Adaptive Moment Estimation) with a learning rate of 0.0001 to update the parameters.

[0084] The model training process of step 3 continues until a preset termination condition is met: the maximum number of training rounds (100 epochs) is reached or there is 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; obtain 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 step 1, input the EEG signal to be staged into the trained sleep staging model, obtain the output of the trained sleep staging model, select the sleep stage with the maximum prediction probability in the prediction probability distribution of the trained sleep staging model output as the sleep staging result of the EEG signal segment; concatenate 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 is completed, the model is evaluated for performance using the reserved test set. Evaluation indicators include overall accuracy, precision, recall, F1 score and Cohen's Kappa coefficient for each sleep stage, which measure the classification ability, stability and adaptability to unbalanced data of the model from multiple dimensions.

[0087] Step 4.2, for the EEG signal to be staged, here, the obtained is new, unlabeled single-channel EEG sleep data derived from a sleep monitoring instrument. The trained model is used for forward inference to perform bandpass filtering and notch filtering on the EEG signal to be staged to obtain preprocessed EEG signal to be staged. The preprocessed EEG signal to be staged is uniformly resampled to a fixed frequency, and the resampled EEG signal to be staged is divided into several non-overlapping EEG signal segments of a fixed length. Obtain the sleep stage prediction probability distribution corresponding to each EEG signal segment to be staged. Finally, the stage with the maximum prediction probability is taken as the sleep staging result of the EEG signal segment, and the sleep staging sequence of the whole night, i.e. the sleep staging result of the whole night EEG signal, is obtained by concatenating in chronological order, providing basic data support for subsequent clinical analysis or sleep structure evaluation.

[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] While the preferred embodiments of the disclosure have been described, additional variations and modifications can be made to these embodiments by those skilled in the art once they learn of the basic inventive concepts. Therefore, the appended claims are intended to encompass within their scope all possible variations and modifications of the preferred embodiments. It is apparent that those skilled in the art can, without departing from the spirit and scope of the disclosure, make various changes and modifications of the present disclosure. Thus, it is intended that the present disclosure cover all such changes and modifications that fall within the scope of the disclosure, together with all equivalents thereof.

Claims

1. A sleep staging method based on Markov chain dynamic loss characterized in that, The method comprises the following steps: Step 1, pre-processing the electroencephalogram signal, dividing the pre-processed electroencephalogram signal into non-overlapping electroencephalogram signal segments of fixed length, and calculating a Markov transition probability matrix according to the electroencephalogram signal segments ; Step 2, constructing a sleep staging model based on a CNN module and a BiLSTM network module, wherein the input of the sleep staging model is an electroencephalogram (EEG) signal segment, and the output is a sleep stage prediction probability distribution; 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, obtaining an EEG signal to be staged, and performing sleep staging on the EEG signal to be staged by using the trained sleep staging model, and selecting a sleep stage with the maximum prediction probability in the prediction probability distribution output by the model as a sleep staging result.

2. The Markov chain dynamics loss based sleep staging method of claim 1, wherein, The step of preprocessing the EEG signal, dividing the preprocessed EEG signal into fixed-length non-overlapping EEG signal segments comprises: obtaining a single-channel EEG signal on a sleep monitoring instrument, performing band-pass filtering and notch filtering on the EEG signal to obtain a preprocessed EEG signal, uniformly resampling the preprocessed EEG signal to a certain fixed frequency, and dividing the resampled EEG signal into fixed-length non-overlapping EEG signal segments.

3. The Markov chain dynamics loss based sleep staging method of claim 1, wherein, The step of calculating the Markov transition probability matrix according to the brain electrical signal segments comprises: associating each brain electrical signal segment obtained in step 1 with the sleep stage artificially marked for the brain electrical signal segment and the sleep stage artificially marked for the brain electrical signal segment in time sequence ; according to the brain electrical signal segments in time sequence, counting the frequency of transition from the sleep stage to the sleep stage , constructing a Markov transition count matrix, and calculating a Markov transition probability matrix ; wherein, and both represent sleep stages, represents the th sleep stage, represents the th sleep stage.

4. The Markov chain dynamics loss based sleep staging method of claim 3, wherein, the step of computing the Markov transition probability matrix comprises normalizing the transition count matrix by row to obtain the Markov transition probability matrix , , satisfies: ; wherein denotes a Markov transition probability matrix the element in the transition count matrix in row and column denotes the frequency of transitions from sleep stage to sleep stage in the Markov transition count matrix; denotes the frequency of transitions from sleep stage to each sleep stage in the Markov transition count matrix.

5. The Markov chain dynamics loss based sleep staging method of claim 1, wherein, The training sample is an EEG signal segment with a label, and the label comprises an artificially labeled sleep stage of the EEG signal segment and an artificially labeled sleep stage of a previous EEG signal segment in time sequence of the EEG signal segment.

6. The Markov chain dynamics loss based sleep staging method of claim 1, wherein, The base classification loss The calculation formula is: ; wherein, represents the true sleep stage of the th training sample; represents the predicted probability distribution of the th training sample; represents the class number of a sleep stage; represents the total number of classes of sleep stages; represents an indicator that the th training sample truly belongs to the th sleep stage; represents the probability that the model predicts that the th training sample belongs to the th sleep stage; represents the static class weight assigned to the th sleep stage.

7. The Markov chain dynamics loss based sleep staging method of claim 1, wherein, 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 staging model correctly predicted the sleep stage of the i th training sample , then the loss weight factor for the i th training sample is calculated as: ; If the sleep staging model incorrectly predicted the sleep stage of the i th training sample , then the loss weight factor for the i th training sample is calculated as: ; wherein, represents an initial weight, with a value of 1 ; represents a coefficient for controlling the reward amplitude; is a set minimum weight lower limit; represents a maximum function; represents a coefficient for controlling the punishment strength.

8. The Markov chain dynamics loss based sleep staging method of claim 1, wherein, 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 Markov chain dynamics loss based sleep staging method of claim 1, wherein, The sequence-aware loss is calculated according to the With , the average value of the sequence-aware loss is calculated Specifically comprises: 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: ; wherein, denotes the total number of training samples; denotes the true sleep stage of the th training sample; denotes the predicted probability distribution of the th training sample; denotes the base classification loss of the th training sample; .

10. The Markov chain dynamics loss based sleep staging method of claim 1, wherein, The step of updating the model parameters of the sleep staging model comprises: updating the model parameters of the sleep staging model by using an Adam optimization algorithm with a learning rate of 0.0001.

Citation Information

Patent Citations

  • Method and device for detection of sleep apnea fragment based on unsupervised feature learning

    CN110801221A

  • 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

  • Real-time seizure prediction informed by hidden markov model event states

    US20170113045A1

Cited By

  • Personalized sleep staging optimization method and device

    CN121337284A