Single-channel eeg sleep staging method based on deep learning
By combining a diachronic feature extraction module, a context encoder, and a capsule network, the problem of insufficient generalization ability of existing single-channel EEG sleep staging methods is solved, achieving higher sleep staging accuracy and generalization ability, and simplifying the feature extraction process.
Patent Information
- Application Number
- CN202310285377.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-22
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2043-03-22
AI Technical Summary
Existing deep learning-based single-channel EEG sleep staging methods cannot fully learn the temporal correlation of diachronic signals, resulting in insufficient generalization ability. Furthermore, traditional methods require manual feature extraction, which is time-consuming.
We employ a deep learning-based single-channel EEG sleep staging method, combining a diachronic feature extraction module, a context encoder, and a capsule network. The capsule network integrates LSTM with a fully connected layer and utilizes a self-attention mechanism for the routing process, fully learning temporal correlations.
It improves the generalization ability and accuracy of the single-channel sleep staging model, reduces training complexity, reduces reliance on professional knowledge, and lowers the time cost of manual feature extraction.
Smart Images

Figure CN116186544B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the field of electroencephalogram sleep staging, and particularly relates to a single-channel electroencephalogram sleep staging method based on deep learning. BACKGROUND
[0002] Sleep occupies one-third of a person's life, during which the electroencephalogram undergoes various changes, which vary with the depth of sleep. According to different characteristics of electroencephalogram, sleep is divided into two states: non-ocular rapid movement sleep (also known as ortho sleep, slow wave sleep, synchronous sleep, quiet sleep, NREM sleep) and ocular rapid movement sleep, which are distinguished by whether there is ocular paroxysmal rapid movement and different electroencephalogram characteristics. It is necessary to evaluate and measure the quality of sleep. Some sleep experts use analog methods to sleep staging polysomnography (PSG) recorded electrical signals, which are recorded by sensors attached to the surface of the brain. PSG includes electroencephalogram (EEG), electrooculogram (EOG), electromyogram (EMG) and electrocardiogram (ECG). Regarding the comfort of the subjects during sleep monitoring, single-channel electroencephalogram signals are increasingly used for sleep staging. PSG is divided into 30s periods, and sleep experts manually divide each period into different stages according to the decision rules made by Rechtschanffen and Kales (R&K) and the American Academy of Sleep Medicine (AASM). In clinical practice, manual sleep staging is very labor-intensive and costly. Therefore, it is essential to conduct research on automatic sleep staging. There have been many studies using various automatic sleep staging methods, which can be divided into two categories: traditional machine learning-based and deep learning-based. Traditional machine learning-based methods usually involve manual feature extraction and sleep stage classification. Electroencephalogram signals usually use artificial feature extraction to extract time or frequency domain features. Then, traditional machine learning algorithms such as support vector machine (SVM), random forest (RF), decision tree and hidden Markov model (HMM) will be used to train sleep stage classification models based on handcrafted features. Although these methods have achieved acceptable performance, they require prior knowledge of artificial engineering and related field expertise, and manual feature extraction, which takes a long time. In addition, deep learning methods have also been applied to single-channel electroencephalogram signal sleep staging. These deep learning-based methods can be divided into two categories according to the composition of the network: convolutional neural network (CNN) and recurrent neural network (RNN).CNNs are most commonly used to extract waveform features related to sleep. Some researchers have successfully applied CNNs to sleep staging tasks. For example, Tsinalis et al. used one-dimensional convolutions to extract features and used maximum ensemble layers to remove redundant information. Sors et al. proposed a 14-layer deep CNN for sleep staging, Perslev et al. proposed an encoder-decoder CNN for sleep staging, and Fiorillo et al. proposed a multi-scale CNN to extract features at different scales for sleep staging. EEG signals exhibit temporal correlations, which CNNs cannot learn, but RNNs can. For example, Michielli et al. proposed a cascaded RNN structure for sleep staging. Some methods combine CNNs and RNNs, using CNNs to extract features and RNNs to learn temporal dependencies. For instance, Supratak et al. proposed a CNN-and-RNN-based model, using CNNs to obtain 30-second diachronic signal feature representations and Long Short-Term Memory (LSTM) to learn transition rules between diachronic stages. In addition, some methods combine CNNs with attention mechanisms, using CNNs to extract features and attention mechanisms to learn the temporal correlations between diachronic stages. Eldele et al. combined CNNs with channel attention and used attention-based modules to quantify the interdependencies between features. Qu et al. used CNNs to extract features and attention mechanisms to study transition rules between time periods. Current methods use CNNs to extract features and RNNs or attention mechanisms to learn the temporal dependencies of diachronic signals. However, these methods cannot fully extract the temporal dependencies of historical signals. RNNs are insufficient for learning the temporal correlations of long time series, and attention mechanisms require longer historical sequences to learn the event dependencies of signals in sleep EEG, and their ability to learn transition relationships between time periods is weaker than that of RNNs. Summary of the Invention
[0003] This invention addresses the shortcomings of existing technologies by proposing a deep learning-based single-channel EEG sleep staging method. This method aims to more fully learn the temporal correlation of diachronic signals, thereby improving the generalization ability of the single-channel sleep staging model and ultimately enhancing the accuracy of single-channel sleep staging.
[0004] To achieve the above-mentioned objectives, the present invention adopts the following technical solution:
[0005] The present invention provides a single-channel EEG sleep staging method based on deep learning, characterized by the following steps:
[0006] Step 1: Obtain the subject's polysomnography and its corresponding sleep tag set. Select the EEG sleep signal from one channel of the polysomnography and divide the EEG sleep signal from one channel into N non-overlapping chronological signal sequences X = {x1, x2, ..., x...}. i , ..., x N}, construct a tag sequence set Y = {y1, y2, ..., y3} according to the sleep tag corresponding to each duration. i , ..., y N}, and simultaneously count the number of tags {N} for each sleep category in all sleep tags corresponding to all durations. f |f = 1, 2, ..., D}; where x i Let x represent the i-th duration signal sequence, and x i ={e i,1 e i,2 , ..., e i,j , ..., e i,l}, y i Represents the i-th duration signal sequence x i The corresponding sleep tag sequence, and y i ={y i,1 y i,2 , ..., y i,j , ..., y i,l}, e i,j ∈R 1×m e i,j Let y represent the j-th duration signal in the i-th duration signal sequence. i,j N represents the label of the j-th duration signal in the i-th duration signal sequence. f Let f represent the number of labels for the f-th sleep category, f∈{1,2,...,D}, and y i,j , ∈{1, 2, ..., D}, where D is the general category of sleep stages, j∈{1, 2, ..., l}, and l is x i The number of time-series signals present in the sample is m, which represents the number of sampling points, and m = θ × δ, where θ represents the sampling rate and δ represents the sampling time.
[0007] Step 2: Construct a deep learning-based EEG sleep staging network, which includes: a diachronic feature extraction module, a context encoder, and a capsule network.
[0008] Step 2.1: The time-based feature extraction module extracts the j-th time-based signal e. i,j After processing, the j-th duration signal e is obtained. i,j Feature map a i,j Thus, the i-th historical signal sequence x is obtained. i Feature map sequence a i ={a i,1 ai,2 , ..., a i,j , ..., a i,l};
[0009] Step 2.2: The context encoder is used to process the feature map sequence a. i Temporal correlation learning is performed to obtain the feature map sequence H. i ={H i,1 H i,2 H i,j , ...H i,l};
[0010] Step 2.3: Construct a capsule network, which consists of a primary capsule layer and a digital capsule layer;
[0011] Step 2.3.1: The primary capsule layer applies the feature map sequence H i The j-th sub-feature map H i,j After processing, primary capsules are obtained. Thus, the i-th historical sequence x is obtained. i The j-th duration signal e i,j Corresponding activated primary capsule sequence v i,j ={v 1 i,j v 2 i,j , ..., v k i,j, ..., v n i,j};
[0012] Step 2.3.2: Activate the primary capsule sequence v i,j The data is input into the digital capsule layer for processing to obtain the j-th epochal signal e associated with all D sleep categories. i,j Corresponding capsule sequence
[0013] Step 2.3.3: Analyze the capsule sequence U i,j The fth advanced feature capsule Taking the l2 norm, we obtain the i-th epochal sequence x. i The j-th duration signal e i,j The probability of the existence of the f-th sleep category This leads to the i-th historical sequence x. i The j-th duration signal e i,j The probability vector of the existence of all sleep categories predicted by the sleep staging network
[0014] Step 3: Construct the loss function l of the EEG sleep staging network using equation (7).MFE :
[0015]
[0016] In equation (7), It is the j-th duration signal e i,j Real Labels i,j The probability of the existence of class f in one-hot encoding;
[0017] Step 4: Train the sleep staging network using the gradient descent algorithm and minimize the loss function to optimize the network parameters until the loss function converges to obtain the optimal sleep staging model, which is used to realize sleep staging of single-channel EEG signals.
[0018] The single-channel EEG sleep staging method based on deep learning described in this invention is characterized in that the diachronic feature extraction module in step 2.1 consists of a first convolutional layer with a stride of S1 and a kernel of K1, a first BN normalization layer, a first ReLU nonlinear activation layer, and a pooling layer with a size of k. m1 Step size is s m1 The first max pooling layer; a second convolutional layer with stride S2 and kernel K2, a second BN normalization layer, and a second ReLU nonlinear activation layer; a third convolutional layer with stride S2 and kernel K2, a third BN normalization layer, and a third ReLU nonlinear activation layer; a fourth convolutional layer with stride S2 and kernel K2, a fourth BN normalization layer, a fourth ReLU nonlinear activation layer, and a pooling size of k. m2 Step size is s m2 It is formed by stacking the second maximum pooling layers.
[0019] The context encoder in step 2.2 includes: a forward LSTM unit and a backward LSTM unit;
[0020] The feature map sequence a i The j-th feature map a i,j The forward hidden state at time j is obtained after processing by the forward LSTM unit. The j-th feature map a i,j The backward hidden state at time j is obtained after processing by the backward LSTM unit. Will and After concatenation, the feature map sequence a is obtained. i The j-th sub-feature map output by the context encoder, Thus, the feature map sequence a is obtained. i The feature map sequence H output by the context encoder i ={H i,1 Hi,2 H i,j , ...H i,l}
[0021] The primary capsule layer in step 2.3.1 consists of a one-dimensional convolution kernel of size K. p ×1, The number of convolutional kernels is N p A convolutional layer and a length of l d The Reshape operation layer is composed of;
[0022] The feature map sequence H i The j-th sub-feature map H i,j After processing by the convolutional layer of the primary capsule layer, the primary feature map P is obtained. i,j After further processing by the Reshape operation layer, the j-th sub-feature map H is output. i,j Primary capsule sequence s i,j , and s i,j ={s 1 i,j s 2 i,j , ..., s k i,j , ..., s n i,j}, Represents the i-th historical sequence x i The j-th duration signal e i,j The corresponding primary capsule sequence s i,j The k-th capsule, where n is the primary capsule sequence s i,j The number of capsules, where n = 1 P / l d ;l d Represents the kth capsule The length of l P P represents i,j The length of the , k∈{1,2,3,…,n};
[0023] The primary capsule sequence s was processed using the Squash activation function. i,j The kth capsule After processing, activated primary capsules are obtained. Thus, the i-th historical sequence x is obtained. i The j-th duration signal e i,j Corresponding activated primary capsule sequence v i,j ={v 1 i,j v 2 i,j , ..., v k i,j , ..., vn i,j}
[0024] In step 2.3.2, the digital capsule layer uses equation (1) to calculate the primary capsule sequence v. i,j The f-th subspace of the mapping predicts the capsule sequence. The k-th prediction capsule Therefore, the primary capsule sequence v can be calculated using formula (2). i,j The f-th subspace of the mapping predicts the capsule sequence.
[0025]
[0026]
[0027] In equations (1) and (2), W f Let f represent the learnable matrix. Representation matrix W f The k-th submatrix; f∈{1,2,3,…,D};
[0028] The digital capsule layer uses equation (3) to calculate the predicted capsule sequence for the f-th subspace. Similarity matrix between each predicted capsule
[0029]
[0030] In equation (3), Indicates the predicted capsule sequence transpose;
[0031] The digital capsule layer uses equation (4) to calculate the predicted capsule sequence for the f-th subspace. The kth subcapsule Weight
[0032]
[0033] In equation (4), represent The learnable bias, Represents a similarity matrix of dimension n×n The element in row p and column o;
[0034] The digital capsule layer uses equation (5) to calculate the predicted capsule sequence for the f-th subspace. The output length is l d+1 Advanced Feature Capsules This yields the j-th epochal signal e associated with all D sleep categories.i,j Corresponding capsule sequence
[0035]
[0036] The present invention provides an electronic device, comprising a memory and a processor, wherein the memory is used to store a program that supports the processor in executing any of the single-channel EEG sleep staging methods, and the processor is configured to execute the program stored in the memory.
[0037] The present invention discloses a computer-readable storage medium on which a computer program is stored, wherein the computer program, when executed by a processor, performs any of the steps of the single-channel EEG sleep staging method.
[0038] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0039] 1. This invention combines LSTM with capsule networks, transforming the traditional scalar network combining LSTM and fully connected layers into a vector network combining LSTM and capsule networks. This overcomes the shortcomings of insufficient generalization in the traditional combination of LSTM and fully connected layers, thereby significantly improving the learning ability of LSTM to the intrinsic temporal correlation of sleep signals.
[0040] 2. This invention uses a routing mechanism based on self-attention to complete the routing process from primary to advanced routes, which makes up for the shortcomings of traditional dynamic routing mechanisms, such as the inability to train in parallel and the high training cost. This reduces the complexity of capsule network training and enables capsule networks to be successfully applied to EEG sleep staging tasks. Attached Figure Description
[0041] Figure 1 This is a diagram of the single-channel sleep staging neural network structure designed for this invention;
[0042] Figure 2 This is a structural diagram of the CNN module for feature extraction designed for this invention;
[0043] Figure 3 This is a schematic diagram of the long short-term memory model unit used in this invention.
[0044] Figure 4 This is a structural diagram of the capsule network designed for this invention;
[0045] Figure 5 This is a schematic diagram of the self-attention mechanism of the capsule network used in this invention.
[0046] Figure 6 This invention designs a model for reconstructing a regularized network structure diagram.
[0047] Figure 7 A bar chart showing the ablation experimental evaluation parameters of the single-channel staged sleep model designed in this invention. Detailed Implementation
[0048] In this embodiment, a single-channel EEG sleep staging method based on deep learning includes the following steps:
[0049] Step 1: Obtain the subject's polysomnography and its corresponding sleep tag set. Select the EEG sleep signal from one channel of the polysomnography and divide the EEG sleep signal from one channel into N non-overlapping chronological signal sequences X = {x1, x2, ..., x...}. i , ..., x N}, and construct a tag sequence set Y = {y1, y2, ..., y} according to the sleep tag corresponding to each duration. i , ..., y N}, and simultaneously count the number of tags {N} for each sleep category in all sleep tags corresponding to all durations. f |f = 1, 2, ..., D}; where x i Let x represent the i-th duration signal sequence, and x i ={e i,1 e i,2 , ..., e i,j , ..., e i,l}, y i Represents the i-th duration signal sequence x i The corresponding sleep tag sequence, and y i ={y i,1 y i,2 , ..., y i,j , ..., y i,l}, e i,j ∈R 1×m e i,j Let y represent the j-th duration signal in the i-th duration signal sequence. i,j N represents the label of the j-th duration signal in the i-th duration signal sequence. f Let f represent the number of labels for the f-th sleep category, f∈{1,2,...,D}, and y i,j , ∈{1, 2, ..., D}, where D is the general category of sleep stages, j∈{1, 2, ..., l}, and l is x i The number of time-series signals present in the sample is m, which represents the number of sampling points, and m = θ × δ, where θ represents the sampling rate and δ represents the sampling time.
[0050] Step 2: Build a deep learning-based EEG sleep staging network, such as... Figure 1As shown, it consists of: a diachronic feature extraction module, a context encoder, and a capsule network;
[0051] Step 2.1: Different sleep stages exhibit significant waveform differences. For example, low-amplitude mixed-frequency (LAMF) waves appear in stage one (N1), while K-complex waves mainly appear in stage two (N2) of NREM sleep. Together with the sleep axis, these are two prominent features of this stage, while sawtooth waves are the only typical EEG feature of REM sleep. Convolutional neural networks are widely used in feature extraction, so a convolutional neural network was designed as the feature extraction module. For example... Figure 2 As shown, the historical feature extraction module consists of a first convolutional layer with a stride of S1 and a kernel of K1, a first BN normalization layer, a first ReLU nonlinear activation layer, and a pooling layer with a size of k. m1 Step size is s m1 The first max pooling layer; a second convolutional layer with stride S2 and kernel K2, a second BN normalization layer, and a second ReLU nonlinear activation layer; a third convolutional layer with stride S2 and kernel K2, a third BN normalization layer, and a third ReLU nonlinear activation layer; a fourth convolutional layer with stride S2 and kernel K2, a fourth BN normalization layer, a fourth ReLU nonlinear activation layer, and a pooling size of k. m2 Step size is s m2 The convolutional layers are stacked, forming a second max-pooling layer. These stacked convolutional layers can merge views and extract deeper features. Between the convolutional layers are dropout layers with a dropout rate of 0.5 to reduce overfitting. The optimal parameters for the feature extraction module, designed using a convolutional neural network, were obtained through continuous adjustments during experiments.
[0052] The i-th duration signal sequence x i The j-th duration signal e in i,j After processing by the time-based feature extraction module, the j-th time-based signal e is obtained. i,j Feature map a i,j Thus, the i-th historical signal sequence x is obtained. i Feature map sequence a i ={a i,1 a i,2 , ..., a i,j , ..., a i,l};
[0053] Step 2.2: Construct a context encoder, including a forward LSTM unit and a backward LSTM unit, used to process the feature map sequence a. i Perform time-related learning:
[0054] according to Figure 3LSTM networks are designed to learn the temporal dependencies of time series. An LSTM network consists of gates with different functions and operations. The forget gate determines which information can be discarded or retained, and its expression is as follows:
[0055] f j =σ(W f ⊙[h j-1 a i,j ]+b f (9)
[0056] The purpose of updating the input and output gates is to determine whether to replace the storage cell with a candidate value and generate the active part of the current time step, which can also be expressed as:
[0057] i j =σ(W i ⊙[h j-1 a i,j ]+b i (10)
[0058] o j =σ(W o ⊙[h j-1 a i,j ]+b o (11)
[0059] The following equations govern the behavior of LSTM cells:
[0060]
[0061]
[0062] h j =o j *tanh(C j (14)
[0063] Where σ is the sigmoid activation function, tanh is the tanh activation function, W represents the weight matrix, and a i,j Let h be the feature vector of the input sequence at time j. j Let b be the hidden state at time j, and b be the bias.
[0064] Feature map sequence a i The j-th feature map a i,j The forward hidden state at time j is obtained after processing by the forward LSTM unit. The j-th feature map a i,j The backward hidden state at time j is obtained after processing by the backward LSTM unit. Will and After concatenation, the feature map sequence a is obtained. i In the j-th sub-feature map output by the context encoder By employing bidirectional long short-term memory units, the temporal transition relationships of diachronic signals can be learned from two directions, thereby obtaining the feature map sequence a. i The feature map sequence H output by the context encoder i ={H i,1 H i,2 ,...,H i,j ,...H i,l};
[0065] Step 2.3: Construct a capsule network, such as... Figure 4 As shown, the capsule network consists of a primary capsule layer and a digital capsule layer;
[0066] Step 2.3.1: The primary capsule layer consists of a one-dimensional convolution kernel of size K. p ×1, The number of convolutional kernels is N p A convolutional layer and a length of l d The Reshape operation layer is composed of;
[0067] Feature map sequence H i The j-th sub-feature map H i,j After processing by the convolutional layer of the primary capsule layer, the primary feature map P is obtained. i,j This convolutional layer is a 1x1 one-dimensional convolutional layer. The reason for setting the kernel size to 1 is that a 1x1 convolutional layer can better fuse features from different channels, thus better transforming them into primary capsules and increasing non-linearity. The number of convolutional kernels is consistent with the number of channels in the input features. After processing by the Reshape operation layer, the j-th sub-feature map H is output. i,j Primary capsule sequence s i,j , and s i,j ={s 1 i,j ,s 2 i,j ,...,s k i,j ,...,s n i,j}, Represents the i-th historical sequence x i The j-th duration signal e i,j The corresponding primary capsule sequence s i,j The k-th capsule, where n is the primary capsule sequence s i,j The number of capsules, where n = 1 P / l d ;l d Represents the kth capsule The length of l P P represents i,j The length of the , k∈{1,2,3,...,n};
[0068] Step 2.3.2: Apply the Squash activation function to the primary capsule sequence s i,j The kth capsule After processing, activated primary capsules are obtained. The Squash activation function serves two purposes: first, it normalizes the capsules; second, it enhances the non-linear learning ability of the capsule network, thereby obtaining the result corresponding to the i-th time sequence x. i The j-th duration signal e i,j Corresponding activated primary capsule sequence v i,j ={v 1 i,j ,v 2 i,j ,...,v k i,j ,...,v n i,j};
[0069] Step 2.3.3, as follows Figure 5 As shown, the activated primary capsule sequence v i,j The input is fed into the digital capsule layer, and the primary capsule sequence v is calculated using equation (1). i,j The f-th subspace of the mapping predicts the capsule sequence. The k-th prediction capsule Therefore, the primary capsule sequence v can be calculated using formula (2). i,j The f-th subspace of the mapping predicts the capsule sequence.
[0070]
[0071]
[0072] In equations (1) and (2), W f Let f represent the learnable matrix. Representation matrix W f The k-th submatrix; f∈{1,2,3,...,D};
[0073] Step 2.3.4: The digital capsule layer uses equation (2) to calculate the predicted capsule sequence for the f-th subspace. Similarity matrix between each predicted capsule
[0074]
[0075] In equation (2), Indicates the predicted capsule sequence transpose;
[0076] Step 2.3.5: The digital capsule layer uses equation (4) to calculate the predicted capsule sequence for the f-th subspace. The kth subcapsule Weight
[0077]
[0078] In equation (4), represent The learnable bias, Represents a similarity matrix of dimension n×n The element in row p and column o;
[0079] Step 2.3.5: The digital capsule layer uses equation (5) to calculate the predicted capsule sequence for the f-th subspace. The output length is l d+1 Advanced Feature Capsules This yields the j-th epochal signal e associated with all D sleep categories. i,j Corresponding capsule sequence The attention-based routing mechanism consists of two parts. The first part is the matrix W. f The first part aims to generate prediction capsules. The second part is the process of the self-attention mechanism assigning weights and generating new capsules. These two parts interact to route the self-attention mechanism.
[0080]
[0081] Step 2.3.6, Perform capsule sequence U i,j The fth advanced feature capsule Taking the l2 norm, we obtain the i-th epochal sequence x. i The j-th duration signal e i,j The probability of the existence of the f-th sleep category This leads to the i-th historical sequence x. i The j-th duration signal e i,j The probability vector of the existence of all sleep categories predicted by the sleep staging network
[0082] Step 3: Construct the loss function l of the EEG sleep staging network using equation (7). MFE :
[0083]
[0084] In equation (7), It is the j-th duration signal e i,j Real Labels i,j In one-hot encoding, the f-th class has a probability. Since sleep staging is an imbalanced classification task, using a balanced loss function will increase the probability that the network will identify the signal as the class with the largest number of samples in the training set, thus causing errors. This problem can be effectively solved by using the MFE weighted loss function. The MFE loss function forces the network to prioritize the class with the smaller sample size, thereby alleviating the problem of imbalance caused by the small sample size. In addition, since the distribution of the validation set cannot be precisely determined, the loss function has priority and does not require adjustment of hyperparameters.
[0085] To improve network performance, reconstruction regularization is used, such as... Figure 6 As shown, the original input signal is reconstructed by placing a fully connected layer at the end of the network, reducing overfitting. The Euclidean distance between the reconstructed signal and the original signal is used to calculate the reconstruction loss. The regularized loss is multiplied by a coefficient γ and added to the loss function. The total loss is:
[0086] l total =l MFE +γ*l Recon (15)
[0087] Step 4: Train the sleep staging network using the gradient descent algorithm and minimize the loss function to optimize the network parameters until the loss function converges to obtain the optimal sleep staging model, which is used to realize sleep staging of single-channel EEG signals.
[0088] In this embodiment, an electronic device includes a memory and a processor. The memory stores a program that supports the processor in executing the above-described method, and the processor is configured to execute the program stored in the memory.
[0089] In this embodiment, a computer-readable storage medium stores a computer program, which is executed by a processor to perform the steps of the above method.
[0090] Example:
[0091] Experimental Dataset: The Sleep-EDFx dataset was used to evaluate the model. In Sleep-EDFx, 153 PSG records from a study on the effects of age on healthy subjects (SCs) were used, collected from 78 participants. To compare with existing methods, Sleep-EDFx was split into two datasets: Sleep-EDF-39 and Sleep-EDF-153. Sleep-EDF-39 included the top 20 SC participants, excluding the 13th participant with only one night's data and 19 others with two nights' data; Sleep-EDF-153 contained 78 participants. To demonstrate the model's broad applicability to different channels, the method of this invention was experimentally tested on the Fpz-Cz, Pz-Oz, and Eog channels respectively.
[0092] As shown in Table 1, the k-fold cross-validation scheme was used to evaluate the model. For Sleep-EDF-39, k equals 20, which means that the data of 19 subjects is used as the training set and the data of 1 subject is used as the test set. For Sleep-EDF-153, k equals 10, and the remaining 10% of the training set is used for validation. The mini-batch of the training set is set to 20.
[0093] Table 1: Sample distribution and number of subjects for each sleep stage category in each dataset.
[0094] Dataset <![CDATA[N s ]]> W N1 N2 N3 REM Total Sleep-EDF-39 20 10197 2804 17799 5703 7717 44220 Sleep-EDF-153 78 69824 21522 69132 13039 25835 199352
[0095] Experimental parameters: The length l of each sequence is 15. To update the model weights, the parameters lr, β1, and β2 of the Adam optimizer are set to 10⁻⁴, 0.90, and 0.999, respectively. For regularization, an L2 regularization term is added to the loss function with a weight of 10⁻³. The reconstruction loss from the capsule network is also applied to the loss function with a weight γ set to 10⁻⁴. The maximum number of training epochs is set to 200. If the validation set loss does not decrease within 20 iterations, the network stops training, and the weights with the lowest validation loss are saved as the optimized weights. Tensorflow is used as the experimental framework, and an NVIDIA GeForce GTX 1070 graphics card with 8GB of VRAM is used to accelerate training.
[0096] Evaluation parameters: Model performance was assessed using precision per class (PR), recall per class (RE), F1 score per class (F1), macro average F1 score (MF1), and overall precision (ACC), as well as Cohen's Kappa coefficient (k). PR reflects the proportion of true positive samples among all positive cases identified by the classifier. RE reflects the proportion of true positive cases among all samples identified as positive by the classifier. F1 is a comprehensive evaluation based on PR and RE; a high F1 indicates a more effective testing method. MF1 is the average F1 score across all classes, reflecting the overall performance of the model. Cohen's Kappa coefficient (k) measures the consistency between two different sleep stage results; it corresponds to the model results and the labels established by sleep experts, and its calculation formula is as follows:
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103] TP represents a true positive result. f TN represents a true positive for type f, and TN represents a true negative. f FP represents a true negative in class f, and FP indicates a false positive. f FN represents a false positive of type f, while FN represents a false negative. f P represents a false negative of type f. e It is the probability of the assumption of coincidence, and is a hyperparameter.
[0104] Experimental Evaluation: Classification performance is referenced in Tables 2, 3, and 4, which list the confusion matrices of the proposed models applied to the Fpz-Cz, Pz-Oz, and Eog channels, respectively. The diagonal elements of the confusion matrix represent the consistency with the labels classified by the experts, while the right side of the table represents the evaluation parameters for each category. The higher the evaluation parameters, the better the performance. In terms of the channels used, the Fpz-Cz channel performed the best, while the Eog channel performed the worst. For each category, the best performance was in the W and N2 stages, while the worst performance was in the N1 stage, which was easily confused with other sleep stages. This is mainly due to the small amount of data in the N1 stage and the similarity between the N1 stage and other sleep stages, making the N1 stage more difficult to distinguish from other sleep stages.
[0105] Table 2: Output confusion matrix of the model using the Fpz-Cz channel signals from the Sleep-EDF-39 dataset.
[0106]
[0107] Table 3: Output confusion matrix of the model using the Pz-Oz channel signals from the Sleep-EDF-39 dataset.
[0108]
[0109] Table 4: Output confusion matrix of the model using EOG channel signals from the Sleep-EDF-39 dataset.
[0110]
[0111] The function of each component of the model is represented by ablation experiments. The model used for comparison consists of the following four basic models, and its performance is compared with and without the component-capsule network:
[0112] ①: CNN+LSTM, which includes a CNN and a unidirectional LSTM;
[0113] ②: CNN+Bi-LSTM, which includes a CNN and a bidirectional LSTM;
[0114] ③: CNN+Bi-LSTM+CapsNet, which includes a CNN, a bidirectional LSTM, and a capsule network, with no reconstruction loss;
[0115] ④: SleepCapsNet, the proposed model, which includes a CNN and a bidirectional LSTM and capsule network for reconstruction loss.
[0116] The performance of different structures was evaluated using the macro-average F1 score (MF1), overall accuracy (ACC), and Cohen's Kappa coefficient. Figure 7The bar charts depict the performance of various models under different evaluation parameters. The bidirectional LSTM model performs better than the unidirectional LSTM model, mainly because the unidirectional LSTM model can only capture the temporal dependency in one direction, while the bidirectional LSTM model can capture the temporal dependency in two directions. This is beneficial for learning the transition rules of the sleep phase. Compared with the CNN+Bi-LSTM model, the CNN+Bi-LSTM+CapsNet model performs better, with higher scores in all three evaluation metrics. This indicates that adding a capsule network can improve the performance of the Bi-LSTM network. By comparing the impact of reconstruction loss on network performance, it can be seen that reconstruction loss can improve network performance, thereby reducing overfitting. Optimal performance is achieved by minimizing the reconstruction regularization loss.
[0117] By comparing the model with state-of-the-art methods, this invention evaluates several parameters, such as the macro average F1 score (MF1), overall accuracy (ACC), and Cohen's Kappa coefficient.
[0118] Table 5 shows the results of comparison with state-of-the-art methods, including DeepSleepNet, SleepEEGNet, TinySleepNet, CCRRSleepNet, AttnNet, and EOGNET. The model outperforms the other models in terms of accuracy, achieving 85.84% on Sleep-EDF-39 and 83.4% on Sleep-EDF-153. Specifically, the model outperforms the other models in the following aspects.
[0119] In terms of W-stage recognition accuracy and generalization performance on large datasets, the model using EOG channel signals for stage segmentation achieves superior results compared to EOGNet, surpassing EOGNet in all aspects. The model is a sequence-to-sequence model, using multiple consecutive epochs as input and outputting the sleep stage corresponding to each epoch. Although DeepSleepNet employs a two-step training method—first learning the representative of each epoch and then training an RNN to learn the transition relationships between epochs—this model does not require two steps. The first half of the model is comparable to TinySleepNet, except for whether the features extracted from the CNN are flattened and fed into the LSTM. TinySleepNet requires mini-batch data augmentation during training. AttnNet is a network that uses multi-head attention to capture temporal dependencies. Unlike the network in this invention, AttnNet achieves optimal results by using three epochs as input and outputting the label of the middle epoch. Furthermore, its loss function is a hyperparameter-based loss function lacking a reasonable interpretation and requiring hyperparameter tuning for different datasets, whereas the network in this invention does not.
[0120] Table 5 shows the evaluation parameters comparing our method with state-of-the-art methods.
[0121]
[0122] In terms of W-stage recognition accuracy and generalization performance on large datasets, the model using EOG channel signals for stage segmentation achieves superior results compared to EOGNet, surpassing EOGNet in all aspects. The model is a sequence-to-sequence model, using multiple consecutive epochs as input and outputting sleep stages corresponding to each epoch. While DeepSleepNet employs a two-step training method—first learning the representative of each epoch and then training an RNN to learn the transition relationships between epochs—this model does not require two steps. The first half of the model is comparable to TinySleepNet, except for whether the features extracted from the CNN are flattened and fed into the LSTM. TinySleepNet requires mini-batch data augmentation during training. AttnNet is a network that uses multi-head attention to capture temporal dependencies. Unlike the network in this invention, AttnNet achieves optimal results by using three epochs as input and outputting the label of the middle epoch. Furthermore, its loss function is a class-aware loss function, lacking a reasonable interpretation and requiring hyperparameter tuning for different datasets, whereas the network in this invention does not.
[0123] The model in this invention can be applied to different EEG channels (Fpz-Cz and Pz-Oz) and EOG channels without modifying the model structure and training algorithm. Experimental results for each channel show that using the Fpz-Cz channel achieves better performance for sleep staging compared to other channels, indicating that the Fpz-Cz channel inherently contains more sleep-related information. Regarding performance for each category, the best performance is in stage W, and the worst performance is in stage N1. Identification of stage N1 has always been a challenge in sleep staging tasks. On the one hand, data for stage N1 is relatively limited; on the other hand, its staging itself is difficult and easily confused with other stages. The model proposed in this invention can be used... Sleep staging from raw, unprocessed single-channel EEG signals is user-friendly for both subjects and those lacking expertise in the field of sleep. The reason for using single-channel EEG signals is that it reduces measurement discomfort for subjects. However, it also increases the risk of inaccurate sleep staging. Single-channel EEG signals do not always exhibit characteristic waveforms associated with sleep and may even contain varying degrees and types of noise. For example, in Sleep-EDF-39, subject 11 achieved only 60% accuracy on the Fpz-Cz channels, the worst result among 20-fold cross-validation results. This was primarily due to high-intensity noise in the validation set, causing durations belonging to other categories to be incorrect. Identified as W- or R-cycles, the model in this invention captures this inherent spatial relationship by introducing a capsule network for more accurate sleep staging. Bidirectional LSTM outperforms unidirectional LSTM; compared to LSTM, Bi-LSTM can consider temporal reference information from two directions, thus making sleep staging more accurate. The self-attention routing mechanism used in this invention fully considers the inherent similarity between capsules and has fewer parameters. The efficient self-attention mechanism enables the capsule network to be widely applied to EEG-based sleep staging tasks. In clinical practice, sleep experts refer not only to single-channel EEG signals but also to other channels when performing sleep staging tasks. Including the EOG channel, sleep-related features, such as the sleep spindle wave not being present in all EEG signals simultaneously, and eye movement and electromyography signals being important for sleep stage discrimination, are also important. In addition, the scoring styles of different experts are not the same, and the differences in scoring styles among different experts lead to different scoring results. Even so, the model in this invention has an overall kappa value of over 0.8 on Sleep-EDF-39. Therefore, the model in this invention can achieve performance comparable to or better than state-of-the-art deep learning methods on the Sleep-EDFx dataset. This invention has practical value, such as in hospitals where sleep assessment is performed manually by sleep experts, which is a time-consuming and expensive process.Sleep staging can be performed using the model of this invention, which can be trained on data accumulated in hospitals. Sleep staging can be completed in a very short time without the need for manual feature extraction. This allows the monitored person to make rapid psychological or physiological adjustments based on the results. In particular, this invention can reduce discomfort for infants during sleep monitoring, which helps monitor infant development. By combining the model of this invention with physical EEG signal acquisition tools, personal sleep monitoring can become more convenient.
Claims
1. A single-channel EEG sleep staging method based on deep learning, characterized in that, Includes the following steps: Step 1: Obtain the subject's polysomnography and its corresponding sleep tag set. Select the EEG sleep signal from one channel of the polysomnography and divide the EEG sleep signal from one channel into N non-overlapping chronological signal sequences X = {x1, x2, ..., x...} i ,…,x N } Construct a tag sequence set Y = {y1, y2, ..., y} according to the sleep tag corresponding to each duration. i ,…,y N }, and simultaneously count the number of tags {N} for each sleep category in all sleep tags corresponding to all durations. f |f=1,2,…,D};where x i Let x represent the i-th duration signal sequence, and x i ={e i,1 ,e i,2 ,…,e i,j ,…,e i,l }, y i Represents the i-th duration signal sequence x i The corresponding sleep tag sequence, and y i ={y i,1 ,y i,2 ,…,y i,j ,…,y i,l }, e i,j ∈R 1×m e i,j Let y represent the j-th duration signal in the i-th duration signal sequence. i,j N represents the label of the j-th duration signal in the i-th duration signal sequence. f Let y represent the number of labels for the f-th sleep category, f∈{1,2,...,D}. i,j ,∈{1,2,…,D}, where D is the general category of sleep stages, j∈{1,2…l}, and l is x i The number of time-series signals present in the data is given by m, which represents the number of sampling points, and m = θ × δ, where θ represents the sampling rate and δ represents the sampling time. Step 2: Construct a deep learning-based EEG sleep staging network, which includes: a diachronic feature extraction module, a context encoder, and a capsule network. Step 2.1: The time-based feature extraction module extracts the j-th time-based signal e. i,j After processing, the j-th duration signal e is obtained. i,j Feature map a i,j Thus, the i-th historical signal sequence x is obtained. i Feature map sequence a i ={a i,1 ,a i,2 ,…,a i,j ,…,a i,l }; Step 2.2: The context encoder is used to process the feature map sequence a. i Temporal correlation learning is performed to obtain the feature map sequence H. i ={H i,1 H i,2 ,...,H i,j ,...H i,l }; Step 2.3: Construct a capsule network, which consists of a primary capsule layer and a digital capsule layer; Step 2.3.1: The primary capsule layer applies the feature map sequence H i The j-th sub-feature map H i,j After processing, primary capsules are obtained. Thus, the i-th historical sequence x is obtained. i The j-th duration signal e i,j Corresponding activated primary capsule sequence v i,j ={v 1 i,j ,v 2 i,j ,...,v k i,j ,...,v n i,j }; Step 2.3.2: Activate the primary capsule sequence v i,j The data is input into the digital capsule layer for processing to obtain the j-th epochal signal e associated with all D sleep categories. i,j Corresponding capsule sequence Step 2.3.3: Analyze the capsule sequence U. i,j The fth advanced feature capsule Taking the l2 norm, we obtain the i-th epochal sequence x. i The j-th duration signal e i,j The probability of the existence of the f-th sleep category This leads to the i-th historical sequence x. i The j-th duration signal e i,j The probability vector of the existence of all sleep categories predicted by the sleep staging network Step 3: Construct the loss function l of the EEG sleep staging network using equation (7). MFE : In equation (7), It is the j-th duration signal e i,j Real Labels i,j The probability of the existence of class f in one-hot encoding; Step 4: Train the sleep staging network using the gradient descent algorithm and minimize the loss function to optimize the network parameters until the loss function converges to obtain the optimal sleep staging model, which is used to realize sleep staging of single-channel EEG signals.
2. The single-channel EEG sleep staging method based on deep learning according to claim 1, characterized in that, The historical feature extraction module in step 2.1 consists of a first convolutional layer with a stride of S1 and a kernel size of K1, a first BN normalization layer, a first ReLU nonlinear activation layer, and a pooling layer with a size of k. m1 Step size is s m1 The first max pooling layer; a second convolutional layer with stride S2 and kernel K2, a second BN normalization layer, and a second ReLU nonlinear activation layer; a third convolutional layer with stride S2 and kernel K2, a third BN normalization layer, and a third ReLU nonlinear activation layer; a fourth convolutional layer with stride S2 and kernel K2, a fourth BN normalization layer, a fourth ReLU nonlinear activation layer, and a pooling size of k. m2 Step size is s m2 It is formed by stacking the second maximum pooling layers.
3. The single-channel EEG sleep staging method based on deep learning according to claim 2, characterized in that, The context encoder in step 2.2 includes: a forward LSTM unit and a backward LSTM unit; The feature map sequence a i The j-th feature map a i,j The forward hidden state at time j is obtained after processing by the forward LSTM unit. The j-th feature map a i,j The backward hidden state at time j is obtained after processing by the backward LSTM unit. Will and After concatenation, the feature map sequence a is obtained. i The j-th sub-feature map output by the context encoder, Thus, the feature map sequence a is obtained. i The feature map sequence H output by the context encoder i ={H i,1 H i,2 ,...,H i,j ,...H i,l } 4. The single-channel EEG sleep staging method based on deep learning according to claim 3, characterized in that, The primary capsule layer in step 2.3.1 consists of a one-dimensional convolution kernel of size K. p ×1, The number of convolutional kernels is N p A convolutional layer and a length of l d The Reshape operation layer is composed of; The feature map sequence H i The j-th sub-feature map H i,j After processing by the convolutional layer of the primary capsule layer, the primary feature map P is obtained. i,j After further processing by the Reshape operation layer, the j-th sub-feature map H is output. i,j Primary capsule sequence s i,j ,and Represents the i-th historical sequence x i The j-th duration signal e i,j The corresponding primary capsule sequence s i,j The k-th capsule, where n is the primary capsule sequence s i,j The number of capsules, where n = 1 P / l d ;l d Represents the kth capsule The length of l P P represents i,j The length of the , k∈{1,2,3,...,n}; The primary capsule sequence s was processed using the Squash activation function. i,j The kth capsule After processing, activated primary capsules are obtained. Thus, the i-th historical sequence x is obtained. i The j-th duration signal e i,j Corresponding activated primary capsule sequence v i,j ={v 1 i,j ,v 2 i,j ,...,v k i,j ,...,v n i,j } 5. The single-channel EEG sleep staging method based on deep learning according to claim 4, characterized in that, In step 2.3.2, the digital capsule layer uses equation (1) to calculate the primary capsule sequence v. i,j The f-th subspace of the mapping predicts the capsule sequence. The k-th prediction capsule Therefore, the primary capsule sequence v can be calculated using formula (2). i,j The f-th subspace of the mapping predicts the capsule sequence. In equations (1) and (2), W f Let f represent the learnable matrix. Representation matrix W f The k-th submatrix; f∈{1,2,3,...,D}; The digital capsule layer uses equation (3) to calculate the predicted capsule sequence for the f-th subspace. Similarity matrix between each predicted capsule In equation (3), Indicates the predicted capsule sequence Transpose of; The digital capsule layer uses equation (4) to calculate the predicted capsule sequence for the f-th subspace. The kth subcapsule Weight In equation (4), represent The learnable bias, Represents a similarity matrix of dimension n×n The element in row p and column o; The digital capsule layer uses equation (5) to calculate the predicted capsule sequence for the f-th subspace. The output length is l d+1 Advanced Feature Capsules This yields the j-th epochal signal e associated with all D sleep categories. i,j Corresponding capsule sequence 6. An electronic device, comprising a memory and a processor, characterized in that, The memory is used to store a program that supports the processor in executing any one of the single-channel EEG sleep staging methods of claims 1-5, and the processor is configured to execute the program stored in the memory.
7. A computer-readable storage medium storing a computer program thereon, characterized in that, When the computer program is run by the processor, it performs the steps of any one of the single-channel EEG sleep staging methods described in claims 1-5.