Single-channel eeg sleep staging method based on multi-scale and multi-attention

By employing a multi-scale and multi-attention single-channel EEG signal sleep staging method, this approach utilizes multi-resolution convolution and multi-head attention mechanisms to extract features, and combines Focal Loss to address class imbalance. This solves the problems of time dependence and high complexity in EEG signal sleep staging, achieving efficient and accurate sleep staging.

CN116763324BActive Publication Date: 2026-05-01CHINA UNIV OF MINING & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHINA UNIV OF MINING & TECH
Filing Date
2023-06-16
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Existing technologies for sleep staging of EEG signals suffer from time-consuming and labor-intensive feature extraction, neglect of time dependence, and class imbalance, resulting in insufficient model performance.

Method used

We employ a multi-scale and multi-attention single-channel EEG sleep staging method, extracting features through multi-resolution convolution, convolutional attention modules, and multi-head attention mechanisms, and combining Focal Loss to handle class imbalance problems, thereby learning sleep patterns and transition rules.

Benefits of technology

It achieves efficient automatic sleep staging, captures long-term dependencies between features, reduces model time complexity, solves class imbalance problem, and improves the accuracy of sleep staging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116763324B_ABST
    Figure CN116763324B_ABST
Patent Text Reader

Abstract

The application discloses a single-channel electroencephalogram sleep staging method based on multi-scale and multi-attention, belongs to the field of signal processing and pattern recognition, and aims to improve the accuracy of staging and realize high-quality sleep staging. The method extracts multi-scale features in the original signal through multi-resolution convolution, then uses channel attention and spatial attention mechanisms in the convolution attention module to learn the changes of feature importance with time scale and trend, thereby improving the feature quality. Then, long-term dependency between features is modeled through multi-head attention embedded with causal dilated convolution, and sleep transition rules are learned. Finally, automatic sleep staging based on electroencephalogram signals is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electroencephalogram (EEG) signal processing and monitoring, specifically to a method for sleep staging based on multi-scale and multi-attention single-channel EEG signals. Background Technology

[0002] The American Academy of Sleep Medicine (AASM) defines five stages of human sleep: Wake (W), Rapid Eye Movement (REM), N1, N2, and N3. N1, N2, and N3 all belong to non-rapid eye movement (non-REM) sleep, representing different levels of deep sleep.

[0003] Existing technologies utilize machine learning methods to automate sleep staging based on multi-channel signals (EEG, EOG, EMG, CG) and single-channel EEG signals. These methods typically consist of two parts: manual feature extraction and sleep stage classification. First, various time-domain and frequency-domain features need to be designed and extracted. Then, the most discriminative features are selected, and finally, traditional machine learning models such as Support Vector Machines (SVM), Random Forests (RF), and neural networks are used for classification. However, these methods have some limitations. First, extracting the most representative features requires prior domain knowledge from experts, which is time-consuming and labor-intensive. Second, due to differences between the subjects and recording hardware, manually designed features based on available datasets may not be generalizable to a wider range.

[0004] Existing technologies also apply deep learning to sleep staging. Most deep learning sleep staging networks use convolutional neural networks (CNNs), and designing convolutional kernels of different sizes and convolutional layers of different depths can effectively extract time-invariant features from the original signal. Results show that CNNs achieve good results in sleep staging. However, these models using multi-resolution CNNs for feature extraction ignore the changes in feature importance over time and trends, resulting in information loss and affecting the overall performance of the model. Moreover, sleep signals have strong time dependencies; ignoring the long-term dependencies of features makes it impossible to learn sleep patterns and transition rules.

[0005] As the problem of neglecting temporal information became increasingly apparent, Recurrent Neural Networks (RNNs) and Long Short-Term Memory (LSTM) technologies began to be applied to various deep learning sleep staging models. The main advantage of RNNs is their ability to be trained to learn long-term temporal dependencies. In deep learning sleep staging models, RNNs are primarily used to learn the transition rules that sleep experts use to identify the next possible sleep stage from the PSG period sequence. Therefore, many models use CNNs for feature extraction and RNNs for modeling temporal dependencies, achieving good results in sleep staging applications. Furthermore, some models use an LSTM-based encoder-decoder with an attention mechanism after the encoder to identify the most relevant parts of the input sequence, resulting in a significant improvement in performance. However, the characteristic of RNNs using previous inputs to constrain the output limits the complexity of most RNN-based models.

[0006] Besides the choice of classification model, class imbalance is a common problem in sleep staging. Previously, the most common approach to address this was oversampling, but this significantly increases training time. A more novel approach is to use Synthetic Minority Oversampling Technique (SMOTE) to achieve data balance. Many models also focus on the loss function, using a weighted cross-entropy loss function to assign different weights to different classes, thereby increasing the model's attention to minority class samples. However, the choice of weights is a limitation of this method; too much weight for minority class samples can lead to poor overall classification performance, while too little weight cannot solve the sample imbalance problem.

[0007] Therefore, deep learning-based automatic sleep staging still faces three major challenges: lack of time-related features, high time complexity, and class imbalance. Summary of the Invention

[0008] The purpose of this invention is to provide a sleep staging method based on multi-scale and multi-attention single-channel EEG signals, addressing the problems of time-consuming and labor-intensive manual sleep staging and low feature extraction quality in automatic sleep staging models. This invention provides an automatic sleep staging method based on multi-scale and multi-attention single-channel EEG signals, capable of automatically extracting high-quality features for sleep staging from raw single-channel EEG sleep signals. Furthermore, it can capture long-term dependencies between features to learn sleep patterns and transition rules, ultimately resolving the class imbalance problem in sleep data and achieving accurate automatic sleep staging.

[0009] To achieve the above functions, this invention designs a sleep staging method based on multi-scale and multi-attention single-channel EEG signals, executing the following steps S1-S5 to complete the sleep staging of EEG sleep data:

[0010] Step S1: Collect raw EEG sleep data of a preset duration, including W, N1, N2, N3, N4 and REM sleep stages, and preprocess the raw EEG sleep data to obtain preprocessed EEG sleep data samples.

[0011] Step S2: Construct a single-channel EEG signal sleep staging model. Using EEG sleep data samples as input, the model sequentially passes through multi-resolution convolution, convolutional attention module, and multi-head attention mechanism to extract time-invariant features, extract time-related features, and model features from the EEG sleep data samples. The model is then classified using softmax to obtain the scores of the EEG sleep data samples for each preset sleep stage.

[0012] Step S3: Construct the loss function of the single-channel EEG signal sleep staging model based on Focal Loss, assign weights according to the difficulty of classifying the EEG sleep data samples, complete the sleep staging of the EEG sleep data samples according to the scores of each preset sleep stage, and use the sleep stage corresponding to the EEG sleep data sample as the output of the single-channel EEG signal sleep staging model.

[0013] Step S4: Use the gradient descent method to train the single-channel EEG signal sleep staging model until the preset convergence condition is met, and obtain the trained single-channel EEG signal sleep staging model.

[0014] Step S5: Apply the trained single-channel EEG signal sleep staging model to complete the sleep staging of EEG sleep data.

[0015] As a preferred technical solution of the present invention: In step S1, the W sleep stage in the original EEG sleep data is the wakefulness period, and the N1, N2, N3, N4 and REM sleep stages are the sleep periods. EEG sleep data for 30 minutes before and after the sleep period are collected as the data of the W sleep stage. The preprocessing includes: excluding EEG sleep data that does not belong to any sleep stage, merging the N4 sleep stage into the N3 sleep stage to obtain the merged N3 sleep stage, and cutting the original EEG sleep data into 30-second EEG sleep data segments as EEG sleep data samples.

[0016] As a preferred technical solution of the present invention, step S2 specifically includes the following steps:

[0017] Step S2.1: Input the sleep data samples of the single-channel EEG signal sleep staging model and pass them through a multi-resolution convolution with two branches. The kernel sizes of the two branches of the multi-resolution convolution are Fs / 2 and Fs×4, respectively, where Fs is the sampling frequency. The larger kernel is used to extract frequency domain features, and the smaller kernel is used to extract time domain features. Both branches of the multi-resolution convolution contain three convolutional layers and two pooling layers. Each convolutional layer is followed by a Gaussian error linear unit as the activation function.

[0018] The features obtained from the two multi-resolution convolution branches are concatenated and then randomly discarded through a Dropout layer. The final time-invariant features obtained after multi-resolution convolution are I∈R. L×d , where L represents the number of channels and d represents the number of features in each channel;

[0019] Step S2.2: Extract the time-invariant features I∈R from the multi-resolution convolution. L×d The input convolutional attention module extracts time-related features. This module includes a channel attention module and a spatial attention module. The channel attention module comprises two parallel adaptive one-dimensional average pooling layers and a max pooling layer, as well as a multilayer perceptron unit with shared parameters. The time-invariant feature I∈R L×d After passing through an adaptive one-dimensional average pooling layer and a max pooling layer respectively, two feature maps of size L×1 are obtained, denoted as follows: and

[0020] Will and The input is a shared-parameter multilayer perceptron unit, which has two convolutional layers. The first layer has L / r neurons, where r represents the decay rate, and the second layer has L neurons. The outputs of these two layers are activated by ReLU and then summed element-wise. Finally, a sigmoid activation function is applied to obtain the channel attention score, along with the time-invariant feature I∈R. L×d Multiplying them yields a channel attention-weighted feature map of size L×d; where the channel attention score M c The specific calculation expression is as follows:

[0021]

[0022] Where σ represents the Sigmoid activation function, W0∈R L / e×L and W1∈R L×L / r The weight parameters of the shared-parameter multilayer perceptron are represented by M; obtained from (1) c (I)∈R L×1 With time-invariant feature I∈R L×d The channel attention weighted feature map F∈R obtained by multiplicationL×d As shown in the following formula:

[0023]

[0024] in M represents c The dot product between I and I;

[0025] The channel attention weighted feature map F∈R output by the channel attention module L×d As input to the spatial attention module, the spatial attention module performs max pooling and average pooling on the feature maps along the channel dimension, resulting in two 1×d feature maps. and Then, the two feature maps are concatenated along the channel dimension, and the number of channels is compressed to 1 using a one-dimensional convolutional layer; finally, the sigmoid activation function is applied to obtain the feature map M of the spatial attention module. s Feature map M s The calculation formula is as follows:

[0026]

[0027] Where σ represents the Sigmoid activation function, f 7 This represents a one-dimensional convolution operation with a kernel size of 7.

[0028] The feature map M of the spatial attention module s The channel attention-weighted feature map F∈R of the input L×d Multiply to obtain the output X∈R of the entire convolutional attention module. L×d The formula for calculating X is:

[0029]

[0030] Step S2.3: The output X∈R of the convolutional attention module L×d The matrices Q, K, and V are obtained by passing the convolutional layers through three different causal expansion layers. The attention score is calculated based on Q, K, and V as follows:

[0031]

[0032] Based on the number of heads H in the multi-head attention mechanism, the matrices Q, K, and V are divided, and each head is represented according to equation (5). The specific formula is as follows:

[0033] A h =ATT(Q h ,K h ,v h (6)

[0034] Where 1 ≤ h ≤ H; finally, all head representations are concatenated to obtain the multi-head attention output; specifically as follows:

[0035] MAH(Q,K,V)=Concat(A 1 ,...A H )∈R L×d (7)

[0036] In the formula, MAH(Q,K,V) represents multi-head attention output, and Concat represents the connection operation;

[0037] The output obtained from multi-head attention is subjected to residual and layer normalization operations, denoted as LayerNorm(x+SubLayer(x)), where x represents the network input, SubLayer represents the residual operation, and LayerNorm represents the layer normalization operation. The outputs of the residual and layer normalization operations are then passed through a feedforward neural network to obtain the final output features used for sleep staging. The operation of the feedforward neural network is as follows:

[0038] F out =W3(δ(W2(x))) (8)

[0039] Among them, F out δ represents the output of the feedforward neural network, W2 and W3 represent two fully connected layers in the feedforward neural network, and δ represents the ReLU activation function.

[0040] Step S2.4: Pass the features output from step S2.3 through a fully connected layer with a Softmax activation function to obtain the score of each sample for each preset sleep stage, thereby realizing the sleep stage classification of each sample.

[0041] As a preferred embodiment of the present invention: the loss function FL of the single-channel EEG signal sleep staging model constructed based on Focal Loss in step S3 is as follows:

[0042] FL(p t )=-α(1-p t ) γ log(p t (9)

[0043] Where α and γ are adjustable parameters, p t The calculation is as follows:

[0044]

[0045] In the formula, y represents the predicted label, p represents the predicted probability of the positive class, and p t This indicates the probability that the prediction is correct.

[0046] As a preferred technical solution of the present invention: in step S4, during the training of the single-channel EEG signal sleep staging model using the gradient descent method, the gradient descent method is Adam, and the learning rate is set to 1e-4.

[0047] As a preferred technical solution of the present invention: according to the AASM sleep staging standard, each preset sleep stage is divided into five sleep stages: W, N1, N2, N3 and REM.

[0048] Beneficial effects: Compared with the prior art, the advantages of the present invention include:

[0049] To address the issues of lack of time-related features, high time complexity, and class imbalance in sleep staging, this invention learns time-related features by using a convolutional attention module to learn the changes in feature importance over time and trends. Furthermore, it employs a multi-head attention mechanism instead of RNNs and LSTMs to capture long-term dependencies of features. The multi-head attention mechanism significantly reduces the model's time complexity by utilizing the advantages of parallel computing. Finally, Focal Loss is introduced to increase attention to minority class samples, thus resolving the class imbalance problem without increasing additional computation. Attached Figure Description

[0050] Figure 1 This is a flowchart of a single-channel EEG signal sleep staging method based on multi-scale and multi-attention, according to an embodiment of the present invention.

[0051] Figure 2 This is a flowchart of time-invariant feature and time-related feature extraction according to an embodiment of the present invention;

[0052] Figure 3 This is a structural diagram of embedded causal extended convolutional multi-head attention used in feature modeling according to embodiments of the present invention. Detailed Implementation

[0053] The present invention will be further described below with reference to the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and should not be used to limit the scope of protection of the present invention.

[0054] Reference Figure 1 The sleep staging method based on multi-scale and multi-attention single-channel EEG signals provided in this embodiment of the invention performs the following steps S1-S5 to complete the sleep staging of EEG sleep data:

[0055] Step S1: Collect raw EEG sleep data of a preset duration, including W, N1, N2, N3, N4 and REM sleep stages, and preprocess the raw EEG sleep data to obtain preprocessed EEG sleep data samples.

[0056] In the raw EEG sleep data, the W sleep stage is the wakefulness period, and the N1, N2, N3, N4 and REM sleep stages are the sleep periods. EEG sleep data is collected 30 minutes before and after the sleep period as the W sleep stage data. The preprocessing includes: excluding EEG sleep data that does not belong to any sleep stage, merging the N4 sleep stage into the N3 sleep stage to obtain the merged N3 sleep stage, and cropping the raw EEG sleep data into 30-second EEG sleep data segments as EEG sleep data samples.

[0057] According to the AASM sleep staging system, the preset sleep stages are divided into five stages: W, N1, N2, N3, and REM.

[0058] Step S2: Construct a single-channel EEG signal sleep staging model. Using EEG sleep data samples as input, the model sequentially passes through Multi-Resolution CNN (MRCNN), Convolutional Block Attention Module (CBAM), and Multi-Head Attention (MHA) to extract time-invariant features, extract time-related features, and model features from the EEG sleep data samples. The model is then classified using softmax to obtain the scores of the EEG sleep data samples for each preset sleep stage.

[0059] Step S2 specifically includes the following steps:

[0060] Step S2.1: Refer to Figure 2 The EEG sleep data samples input to the single-channel EEG signal sleep staging model are processed through a two-branch multi-resolution convolution. The kernel sizes of the two multi-resolution convolution branches are Fs / 2 and Fs×4, respectively, where Fs is the sampling frequency. The larger kernel is used to extract frequency domain features, and the smaller kernel is used to extract time domain features. Both branches of the multi-resolution convolution contain three convolutional layers and two pooling layers. Each convolutional layer is followed by a Gaussian Error Linear Unit (GELU) as the activation function. This loss function allows negative weights to pass through, avoiding information loss and playing an important role in subsequent extraction of time-related features.

[0061] The features obtained from the two multi-resolution convolution branches are concatenated and then randomly discarded through a Dropout layer to prevent overfitting. The final time-invariant features obtained after multi-resolution convolution are I∈R. L×d , where L represents the number of channels and d represents the number of features in each channel.

[0062] Step S2.2: Extract the time-invariant features I∈R from the multi-resolution convolution. L×d The input convolutional attention module extracts time-related features. This module includes channel attention (CA) and spatial attention (SA), and the input time-invariant features I∈R are used for extraction. L×d First, the channel attention module is used to obtain the weighted results of different channels to learn the time scale information. Then, the spatial attention module is applied to obtain another round of weighted learning of time trend information to get the final output.

[0063] The channel attention module consists of two parallel adaptive one-dimensional average pooling layers and a max pooling layer, as well as a shared-parameter multilayer perceptron unit, with time-invariant features I∈R. L×d After passing through an adaptive one-dimensional average pooling layer and a max pooling layer respectively, two feature maps of size L×1 are obtained, denoted as follows: and The reason for using parallel average pooling and max pooling layers is that they reduce information loss better than single pooling layers, achieving better results. Average pooling layers are used to aggregate macroscopic information, while max pooling layers are used to collect important feature cues to infer more refined channel attention.

[0064] Will and The input is a shared-parameter multilayer perceptron unit, which has two convolutional layers. The first layer has L / r neurons, where r represents the decay rate, and the second layer has L neurons. The outputs of these two layers are activated by ReLU and then summed element-wise. Finally, a sigmoid activation function is applied to obtain the channel attention score, along with the time-invariant feature I∈R. L×d Multiplying them yields a channel attention-weighted feature map of size L×d; where the channel attention score M c The specific calculation expression is as follows:

[0065]

[0066] Where σ represents the Sigmoid activation function, W0∈R L / r×L and W1∈R L×L / r The weight parameters of the shared-parameter multilayer perceptron are represented by M; obtained from (1) c (I)∈R L×1 With time-invariant feature I∈R L×d The channel attention weighted feature map F∈R obtained by multiplication L×d As shown in the following formula:

[0067]

[0068] in M represents c The dot product between I and I;

[0069] The channel attention weighted feature map f∈R output by the channel attention module L×d As input to the spatial attention module, the spatial attention module performs max pooling and average pooling on the feature maps along the channel dimension, resulting in two 1×d feature maps. and Then, the two feature maps are concatenated along the channel dimension, and the number of channels is compressed to 1 using a one-dimensional convolutional layer; finally, the sigmoid activation function is applied to obtain the feature map M of the spatial attention module. s Feature map M s The calculation formula is as follows:

[0070]

[0071] Where σ represents the Sigmoid activation function, f 7 This represents a one-dimensional convolution operation with a kernel size of 7.

[0072] The feature map M of the spatial attention module s The channel attention-weighted feature map F∈R of the input L×d Multiply to obtain the output X∈R of the entire convolutional attention module. L×d The formula for calculating X is:

[0073]

[0074] Therefore, the convolutional attention module can adaptively adjust the weights of each channel and spatial location to learn the importance of features with temporal scale and trend changes, without changing the size of the input features.

[0075] Step S2.3: Learn the sleep transition rule by modeling the long-term dependencies between features extracted from the original signal. This is mainly achieved through multi-head attention embedding causal extended convolutions. Multi-head attention can capture the dependencies between features, and the embedding of causal extended convolutions increases the receptive field while restricting the temporal order of the signals, thus achieving the modeling of long-term dependencies. The output feature X∈R of step S2.2 L×dAs input to step S2.3, X first captures the dependencies between features using a multi-head attention mechanism. This mechanism first performs a spatial transformation on the input features, then divides the features into multiple heads, calculates the attention score for each head separately, and finally concatenates all heads to obtain the final output. EEG signals exhibit a clear time series in the temporal domain, and their temporal order is essential for a better understanding of physiological changes and sleep patterns. Fully connected layers violate fundamental temporal constraints, allowing future time steps to influence past time steps, leading to information leakage. Therefore, causal convolution is applied to perform spatial transformations to compute correlations. Causal convolution considers only the influence of earlier input data on later outputs at each time step, strictly restricting the temporal order. This allows causal convolution to model temporal dependencies more accurately in sleep staging. However, because each output point depends only on a small segment of input data prior to the current time step, rather than the entire sequence, the receptive field is smaller, limiting its ability to capture long-term dependencies. Therefore, causal dilation convolution can increase the receptive field by skipping some inputs. Causal dilation convolution is more suitable for the characteristics of EEG signals and sleep staging.

[0076] Reference Figure 3 The output X∈R of the convolutional attention module L×d The queries are processed through three different causal extended convolutional layers to obtain matrices query(Q), key(K), and value(V). The attention score is calculated based on Q, K, and V as follows:

[0077]

[0078] Multi-head attention mechanisms project features into different subspaces to learn the dependencies between features, significantly improving the model's expressive power. The matrices Q, K, and V are partitioned according to the number of heads H in the multi-head attention mechanism. Each head can focus on the input sequence and capture different patterns or features. This enables the model to better model long-term dependencies and capture more complex relationships between different parts of the input. Within each subspace, each head is represented according to Equation (5) as... The specific formula is as follows:

[0079] A h =ATT(Q h ,K h ,v h (6)

[0080] Where 1 ≤ h ≤ H; finally, all head representations are concatenated to obtain the multi-head attention output; specifically as follows:

[0081] MAH(Q,K,V)=Concat(A 1 ,...A H )∈RL×d (7)

[0082] In the formula, MAH(Q,K,V) represents multi-head attention output, and Concat represents the connection operation;

[0083] The output obtained from multi-head attention is subjected to residual and layer normalization operations, denoted as LaterNorm(x+SubLayer(x)), where x represents the network input, SubLayer represents the residual operation, and LayerNorm represents the layer normalization operation. Residual connections help propagate low-level features to higher levels, preventing gradient vanishing and reducing overfitting, while layer normalization accelerates the model training process. The output of the residual and layer normalization operations is passed through a feedforward neural network (FFN) to obtain the final output features used for sleep staging. Since multi-head attention mechanisms involve linear matrix operations, the learning ability of linear operations is far inferior to that of non-linear operations. Therefore, two fully connected layers in the feedforward neural network are used to improve the model's learning ability. The operation of the feedforward neural network is as follows:

[0084] F out =W3(δ(W2(x))) (8)

[0085] Among them, F out δ represents the output of the feedforward neural network, W2 and W3 represent two fully connected layers in the feedforward neural network, and δ represents the ReLU activation function.

[0086] Step S2.4: Pass the features output from step S2.3 through a fully connected layer with a Softmax activation function to obtain the score of each sample for each preset sleep stage, thereby realizing the sleep stage classification of each sample.

[0087] Step S3: Construct the loss function of the single-channel EEG signal sleep staging model based on Focal Loss, assign weights according to the difficulty of classifying the EEG sleep data samples, complete the sleep staging of the EEG sleep data samples for each preset sleep stage based on the scores of the EEG sleep data samples, and use the sleep stage corresponding to the EEG sleep data sample as the output of the single-channel EEG signal sleep staging model.

[0088] In step S3, the loss function FL of the single-channel EEG signal sleep staging model constructed based on Focal Loss is used to address the class imbalance problem. Different weights are assigned to the sample loss according to the difficulty of sample classification, thereby increasing the attention to difficult-to-distinguish samples and reducing the impact of class imbalance. The loss function FL is as follows:

[0089] FL(p t )=-α(1-p t )γ log(p t (9)

[0090] Where α and γ are adjustable parameters, p t The calculation is as follows:

[0091]

[0092] In the formula, y represents the predicted label, p represents the predicted probability of the positive class, and p t This represents the probability of a correct prediction. Therefore, p t The smaller the value, the lower the confidence level of the sample, indicating that it is a difficult-to-distinguish sample, and the higher its corresponding loss weight. This achieves attention to the difficult-to-distinguish samples in the minority class, solving the problem of class imbalance.

[0093] In a five-category sleep stage classification task, each category is treated as a positive class, and the other four categories as negative classes. The loss can be calculated separately and then summed. For minority classes like N1 sleep stage, p t The value is very small, so the loss weight for this sample is relatively high. Therefore, more attention can be paid to samples from the minority class. Compared with the traditional weighted cross-entropy loss that focuses on the influence of the class, Focal Loss pays more attention to the sample, thus overcoming the limitation of distributional differences between sleep stages. After this step, the sleep stage prediction results for each 30s EEG sleep data sample can be obtained.

[0094] Step S4: Use gradient descent to train the single-channel EEG signal sleep staging model and minimize the loss function FL to optimize the network parameters until the preset convergence condition is reached to obtain the trained single-channel EEG signal sleep staging model.

[0095] In the process of training a single-channel EEG signal sleep staging model using the gradient descent method, the gradient descent method used was Adam, and the learning rate was set to 1e-4.

[0096] Step S5: Apply the trained single-channel EEG signal sleep staging model to complete the sleep staging of EEG sleep data.

[0097] The following are examples to verify the effectiveness of the present invention:

[0098] The single-channel EEG sleep staging model designed in this invention was experimentally validated on the Sleep-EDF-20 and Sleep-EDF-78 datasets. Due to the limited sample size of the datasets, 20-fold cross-validation was used in this experiment. Several commonly used evaluation metrics in multi-class classification problems were employed to evaluate the single-channel EEG sleep staging model, including Precision (PR), Recall (RE), F1-score (F1), and G-Mean (GM). The specific performance of the proposed single-channel EEG sleep staging model on the two datasets is shown in Tables 1 and 2.

[0099] Table 1: Confusion matrix and various evaluation metrics on the Sleep-EDF-20 dataset

[0100]

[0101] Table 2: Confusion Matrix and Evaluation Metrics on the Sleep-EDF-78 Dataset

[0102]

[0103] To demonstrate the effectiveness of the proposed single-channel EEG sleep staging model, the performance of existing sleep staging schemes was compared with that of the proposed model, as shown in Table 3. The proposed single-channel EEG sleep staging model was compared with several existing models on two datasets for the following metrics: various F1 scores, accuracy (ACC), composite F1 score (MF1), Kappa(k), and composite G-Mean (MGm). Table 3 shows that the proposed single-channel EEG sleep staging model outperforms other models in several comprehensive evaluation metrics.

[0104] Table 3: Sleep-EDF-20 and Sleep-EDF-78 datasets

[0105]

[0106] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the present invention is not limited to the above embodiments. Within the scope of knowledge possessed by those skilled in the art, various changes can be made without departing from the spirit of the present invention.

Claims

1. A sleep staging method based on multi-scale and multi-attention single-channel EEG signals, characterized in that, Perform the following steps S1-S5 to complete the sleep staging of the EEG sleep data: Step S1: Collect raw EEG sleep data of a preset duration, including W, N1, N2, N3, N4 and REM sleep stages, and preprocess the raw EEG sleep data to obtain preprocessed EEG sleep data samples. According to the AASM sleep staging standard, each preset sleep stage is divided into five sleep stages: W, N1, N2, N3, and REM. In the original EEG sleep data, the W sleep stage is the wakefulness period, and the N1, N2, N3, N4, and REM sleep stages are the sleep periods. EEG sleep data is collected 30 minutes before and after the sleep period as the data for the W sleep stage. The preprocessing includes: excluding EEG sleep data that does not belong to any sleep stage, merging the N4 sleep stage into the N3 sleep stage to obtain the merged N3 sleep stage, and cropping the original EEG sleep data into 30-second EEG sleep data segments as EEG sleep data samples. Step S2: Construct a single-channel EEG signal sleep staging model. Using EEG sleep data samples as input, the model sequentially passes through multi-resolution convolution, convolutional attention module, and multi-head attention mechanism to extract time-invariant features, extract time-related features, and model features from the EEG sleep data samples. The model is then classified using softmax to obtain the scores of the EEG sleep data samples for each preset sleep stage. Step S2 specifically includes the following steps: Step S2.1: Input the sleep data samples of the single-channel EEG signal sleep staging model and pass them through a multi-resolution convolution with two branches. The kernel sizes of the two branches of the multi-resolution convolution are Fs / 2 and Fs×4, respectively, where Fs is the sampling frequency. The larger kernel is used to extract frequency domain features, and the smaller kernel is used to extract time domain features. Both branches of the multi-resolution convolution contain three convolutional layers and two pooling layers. Each convolutional layer is followed by a Gaussian error linear unit as the activation function. The features obtained from the two multi-resolution convolution branches are concatenated and then randomly discarded through a Dropout layer. The final time-invariant features obtained after multi-resolution convolution are: , where L represents the number of channels and d represents the number of features in each channel; Step S2.2: Extract time-invariant features from multi-resolution convolution. The input convolutional attention module extracts time-related features. This module includes a channel attention module and a spatial attention module. The channel attention module comprises two parallel adaptive one-dimensional average pooling layers and a max pooling layer, as well as a multilayer perceptron unit with shared parameters, for time-invariant features. After passing through an adaptive one-dimensional average pooling layer and a max pooling layer respectively, two values ​​of size are obtained. The feature maps are denoted as follows: and ; Will and The input is a shared-parameter multilayer perceptron unit, which has two convolutional layers. The first layer has L / r neurons, where r represents the decay rate, and the second layer has L neurons. The outputs of these two layers are activated by ReLU and then summed element-wise. Finally, a sigmoid activation function is applied to obtain the channel attention score, along with time-invariant features. Multiply to get Channel attention weighted feature map of size; where channel attention score The specific calculation expression is as follows: (1); in This represents the Sigmoid activation function. and The weight parameters of the shared-parameter multilayer perceptron are obtained from (1). Time-invariant characteristics The channel attention weighted feature map obtained by multiplication As shown in the following formula: (2); in express and dot product between; The channel attention weighted feature map output by the channel attention module As input to the spatial attention module, the spatial attention module performs max pooling and average pooling on the channel dimension, respectively, to obtain two... Size feature map and Then, the two feature maps are concatenated along the channel dimension, and the number of channels is compressed to 1 using a one-dimensional convolutional layer. Finally, the Sigmoid activation function is applied to obtain the feature map of the spatial attention module. Feature map The calculation formula is as follows: (3); in, This represents the Sigmoid activation function. This represents a one-dimensional convolution operation with a kernel size of 7. Feature maps of spatial attention module Channel attention weighted feature map of the input Multiply to obtain the output of the entire convolutional attention module. ; The calculation formula is: (4); Step S2.3: Output of the convolutional attention module The matrices Q, K, and V are obtained by passing the convolutional layers through three different causal expansion layers. The attention score is calculated based on Q, K, and V as follows: (5); Based on the number of heads H in the multi-head attention mechanism, matrices Q, K, and V are divided, and each head is represented according to equation (5). The specific formula is as follows: (6); in Finally, all head representations are connected together to obtain multi-head attention output; specifically as follows: (7); In the formula, This indicates multi-head attention output; Concat represents a join operation. Perform residual and layer normalization operations on the output obtained from multi-head attention, as follows: ,in Let SubLayer represent the input to the network, and LayerNorm represent the layer normalization operation. The outputs of the residual and layer normalization operations are passed through a feedforward neural network to obtain the final output features used for sleep staging. The operation of the feedforward neural network is as follows: (8); in, This represents the output of the feedforward neural network. and This represents two fully connected layers in a feedforward neural network. Represents the ReLU activation function; Step S2.4: Pass the features output from step S2.3 through a fully connected layer with a Softmax activation function to obtain the score of each sample for each preset sleep stage, thereby realizing the sleep stage classification of each sample; Step S3: Construct the loss function of the single-channel EEG signal sleep staging model based on Focal Loss, assign weights according to the difficulty of classifying the EEG sleep data samples, complete the sleep staging of the EEG sleep data samples according to the scores of each preset sleep stage, and use the sleep stage corresponding to the EEG sleep data sample as the output of the single-channel EEG signal sleep staging model. The loss function FL of the single-channel EEG signal sleep staging model constructed based on Focal Loss in step S3 is as follows: (9); in and These are adjustable parameters. The calculation is as follows: (10); In the formula, y represents the predicted label, and p represents the predicted probability of the positive class. This indicates the probability that the prediction is correct. Step S4: Use the gradient descent method to train the single-channel EEG signal sleep staging model until the preset convergence condition is met, and obtain the trained single-channel EEG signal sleep staging model. Step S5: Apply the trained single-channel EEG signal sleep staging model to complete the sleep staging of EEG sleep data.

2. The sleep staging method based on multi-scale and multi-attention single-channel EEG signals according to claim 1, characterized in that, In step S4, during the training of the single-channel EEG signal sleep staging model using the gradient descent method, the gradient descent method is Adam, and the learning rate is set to 1e-4.

Citation Information

Patent Citations

  • Automatic sleep staging and migration method based on deep neural network

    CN112869711A

  • Electroencephalogram signal automatic sleep staging method based on multi-scale attention

    CN115530847A