A Sleep Staging and Interpretability Analysis Method Based on Deep Capsule Network

Through the sleep staging method based on deep capsule network, the problems of insufficient integration of multi-channel PSG data information and poor model interpretation in the prior art are solved, and higher sleep staging accuracy and clinical availability of the model are achieved.

CN118568558BActive Publication Date: 2025-05-27ZHEJIANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410615522.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-17
Publication Date
2025-05-27
Estimated Expiration
2044-05-17

AI Technical Summary

Technical Problem

When the existing automatic sleep staging algorithm processes multi-channel PSG data, it is difficult to effectively integrate information from different channels, resulting in insufficient accuracy of sleep staging, and the 'black box' characteristics of the deep learning model make it difficult to explain in clinical applications.

Method used

Using a sleep staging method based on deep capsule network, by constructing the connection between features at different levels, using capsule mold length to represent the probability of the existence of features, providing an interpretable analysis method for model decision-making.

Benefits of technology

It improves the accuracy of sleep staging, can effectively extract multi-channel features, reduces the complex calculation of large-size inputs, and provides a basis for realizing the clinical availability of automatic sleep staging algorithms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118568558B_ABST
    Figure CN118568558B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for sleep staging and interpretability analysis based on a deep capsule network. The method includes obtaining an initial polysomnogram dataset, dividing the polysomnogram signals in the polysomnogram dataset into N sleep stage sequences, and constructing a sleep staging dataset according to the N sleep stage sequences; constructing a sleep staging network model for sleep staging; inputting the training set into the constructed sleep staging network model for training, and inputting the test set into the trained sleep staging network model to obtain the sleep staging results of each sleep stage sequence in the polysomnogram signal. The present invention constructs an interpretable analysis method by using the capsule characteristics of the capsule network, providing a basis for making the automatic sleep staging algorithm clinically applicable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of sleep staging, and specifically relates to a method for sleep staging based on a deep capsule network. Background Art

[0002] Sleep is an important physiological cycle of humans, accounting for one-third of an individual's lifespan. With the development of the times, the incidence of sleep disorders is also rising continuously. Sleep disorders can lead to reduced work efficiency, decreased immunity, and pose a threat to human health. Long-term sleep disorders may result in various chronic diseases, such as hypertension, Alzheimer's disease, Parkinson's disease, and depression, etc. Sleep staging using polysomnogram (PSG) data is the basis for the diagnosis and treatment of sleep disorders. PSG includes physiological signals such as electroencephalogram (EEG), electrooculogram (EOG), electrocardiogram (ECG), and electromyogram (EMG). According to the sleep stage criteria established by the American Academy of Sleep Medicine (AASM), these signals are segmented into 30-second time intervals (referred to as "epochs"), and then classified into one of five stages (W, N1, N2, N3, and REM). Completing this process takes two hours for human experts. Therefore, it is necessary to establish an accurate automatic sleep staging system to address these challenges. Early automatic sleep staging algorithms used traditional machine learning methods to classify EEG signals into corresponding sleep stages. These methods generally included two steps, namely manual feature extraction and sleep stage classification. First, they designed and extracted various features in the time domain and frequency domain. Feature selection algorithms were usually used to further select the most discriminative features. Second, the selected features were input into traditional machine learning models for sleep stage classification, such as plain Bayes, support vector machine (SVM), random forest (RF), and even classifiers based on ensemble learning. However, these methods require domain knowledge to extract the most representative features. In recent years, deep learning has been applied to different fields and has shown its superiority over traditional machine learning models that do not require domain knowledge. This has prompted researchers to use deep learning techniques for automatic sleep stage classification. Initially, convolutional neural networks (CNNs), deep neural networks (DNNs), and recurrent neural networks (RNNs) were often used to extract features. These methods were based on a one-to-one scheme, using a single EEG epoch signal to predict the corresponding sleep stage. To utilize the context information between multiple sleep stages, many-to-many methods have become increasingly popular in this task. These methods are generally based on CNN, CNN+RNN, transformer, CNN+transformer. To obtain effective features of the EEG, Mohsenvand et al. designed convolutional channels with different convolutional kernels to extract features to obtain frequency and amplitude information at different scales. These studies used feature maps with different receptive field sizes to obtain richer information from the given input signal, but ignored the information of other channels in the PSG signal. PSG provides multi-channel signal recordings, so information from different channels can be extracted and integrated through appropriate methods to achieve higher sleep staging performance. Existing methods accurately extract features from multi-channel PSG data based on CNN or transformers, and these methods perform well in the sleep staging task.CNN cannot recognize the position of an object relative to another object, while the transformer has a tendency to overfit on small datasets. At the same time, due to the 'black box' nature of neural networks, it is difficult to apply the automatic sleep staging algorithm to clinical practice. Summary of the Invention

[0003] To solve the problems in the background art, the purpose of the present invention is to provide a sleep staging and interpretability analysis method based on a deep capsule network, which further improves the accuracy of sleep staging by establishing the connection between different levels of features, and provides an interpretable analysis method for model decision-making by using the feature that the capsule length represents the probability of the existence of features.

[0004] The technical solution of the present invention is as follows:

[0005] A sleep staging and interpretability analysis method based on a deep capsule network, comprising the following steps:

[0006] Step S1: First, obtain the initial polysomnogram dataset, and divide the polysomnogram signals in the polysomnogram dataset into N sleep stage sequences x n according to the AASM sleep staging standard. n Then, construct a sleep staging dataset based on the N sleep stage sequences x

[0007] and divide the sleep staging dataset into a training set, a validation set, and a test set according to a preset ratio of 7:1:2.

[0008] Step S2: Construct a sleep staging network model for sleep staging. The sleep staging network model includes a signal preprocessing module, a feature extraction module, and a feature classifier.

[0009] Step S3: Input the training set in Step S1 into the constructed sleep staging network model for training, and then use the validation set to verify the trained sleep staging network model to determine the weights of the sleep staging network model with the optimal accuracy.

[0010] In the said Step S2, the topological structure of the sleep staging network model is as follows:

[0011] The sleep staging network model is mainly composed of a signal preprocessing module, a feature extraction module based on a deep capsule network, and a feature classifier connected in sequence. The feature extraction module is mainly composed of a primary capsule layer, two consecutive convolutional capsule layers, and a norm normalization module connected in sequence. The output end of the signal preprocessing module is connected to the input end of the primary capsule layer, and the output end of the norm normalization module is connected to the input end of the feature classifier.

[0012] First, amplify the set of sleep stage sequences The amplified sleep stage sequences in are input into the signal preprocessing module, and the logarithmic spectrum image s is obtained through the short-time Fourier transform STFT n :

[0013] Then, the logarithmic spectrum image s n passes through the primary capsule layer and outputs the corresponding primary capsule group P A,n :

[0014]

[0015]

[0016] In the formula, represents the m-th capsule layer in the primary capsule group P A,n The subscript m represents the ordinal number of the capsule layer in the capsule group, and M represents the total number of capsule layers in the primary capsule group; represents the capsule at the position (h, w) in the m-th capsule layer of the primary capsule group P A,n The subscripts h and w respectively represent the positions of the capsule in the height direction and width direction of the capsule layer, and H and W respectively represent the total height and total width of the capsule layer in the primary capsule group;

[0017] The output primary capsule group P A,n is processed by two consecutive convolutional capsule layers to obtain the target capsule group D A,n , and according to the target capsule group D A,n the features f' of each sleep stage sequence x n are obtained, and after performing L2 normalization on the target capsule group D n the probabilities v of the existence of various sleep stages of the sleep stage sequence x A,n are obtained n ; n,k ;

[0018] The features f' of N consecutive sleep stage sequences x n are input into the feature classifier, and the staging results corresponding to each sleep stage sequence x n are output n .

[0019] The described primary capsule layer is mainly composed of three consecutive feature extraction sub-modules, an activation function layer g, and a reshape function layer connected in sequence. Each feature extraction sub-module is mainly composed of a 2D convolution module with a convolution kernel size of 3×3, a batch normalization layer, and a Relu activation function connected in sequence. The activation function layer is mainly composed of a 2D convolution module with a convolution kernel size of 1×1 and a Tanh activation function connected. The Relu activation function of the third feature extraction sub-module is connected to the 2D convolution module of the activation function layer, and the Tanh activation function is connected to the reshape function layer. The logarithmic spectrum image s n is input into the 2D convolution module of the first feature extraction sub-module, and the logarithmic spectrum image s is output by the reshape function layer n corresponding primary capsule group P A,n .

[0020] The described convolutional capsule layer is used to convert the input capsules with a preset convolution kernel size to generate new capsules, and the input capsule group and output capsule group of the convolutional capsule layer are used as the sub-capsule group and the parent capsule group respectively; the primary capsule group p A,n obtains the target capsule group D A,n and the probability v n,k through two consecutive convolutional capsule layer processes. The specific steps are as follows:

[0021] Step S2.1: First, the primary capsule group p output by the primary capsule layer A,n is used as the first sub-capsule group and input into the first convolutional capsule layer, and the first parent capsule group C A,n is output;

[0022] The convolution kernel size of the first convolutional capsule layer is not equal to the capsule layer size H×W in the primary capsule group P A,n ;

[0023] Step S2.2: Then, the capsule group C output in Step S2.1 A,n is used as the second sub-capsule group and input into the second convolutional capsule layer, and the second parent capsule group is output as the target capsule group D A,n ;

[0024] Set the convolution kernel size of the second convolutional capsule layer to be equal to the capsule layer size in the capsule group C A,n , and set the total number of capsules in the target capsule group D A,n to be 5. The expression of the target capsule group D A,n is as follows:

[0025]

[0026]

[0027] Among them, represents the m-th capsule layer in the target capsule group D A,n ;

[0028] Step S2.3. Obtain the corresponding sleep stage sequence x A,n and its feature f′ n from the target capsule group D n :

[0029]

[0030] where concatenate() represents the concatenation function;

[0031] Step S2.4. Process the target capsule group D A,n using the following formula to obtain the corresponding sleep stage sequence x n and the probability v n,k of the existence of various sleep stages:

[0032]

[0033]

[0034] k = m, k ∈ {1, 2, 3, 4, 5}

[0035] where v n,k represents the probability of the existence of the k-th sleep stage in the sleep stage sequence x n ; k = 1 represents the wakefulness stage; k = 2 represents the non-rapid eye movement stage I; k = 3 represents the non-rapid eye movement stage II; k = 4 represents the non-rapid eye movement stage III; k = 5 represents the rapid eye movement stage; d f represents the dimension of each capsule in the target capsule group D A,n ; L 2 () represents the function of taking the second norm.

[0036] The specific method of inputting the feature f′ n of the sleep stage sequence x n into the feature classifier and outputting the corresponding staging result for each sleep stage sequence x n is as follows:

[0037] First, concatenate all the features f′ n of the sleep stage sequences x n , and encode the positions of the features f′ n of the sleep stage sequences to obtain the concatenated sleep stage time series G A :

[0038] G A = concatenate(f′ 1 , f′ 2 ,..., f′ n ,..., f′ N )

[0039] where concatenate() represents the concatenation function;

[0040] Then, the sleep stage time series G A is input into the feature classifier network based on the multi-head attention mechanism for temporal correlation learning to obtain the sleep stage results of each sleep stage sequence x A in the sleep stage time series G n .

[0041] During the training of step S3, the loss function is used to calculate the loss of the sleep staging network model, and at the same time, the sleep staging network model is trained through the gradient descent algorithm. The loss calculation is specifically processed according to the following formula:

[0042]

[0043]

[0044] where loss represents the loss, N represents the total number of sleep stage sequences; α represents the given loss parameter; L n represents the Margin loss function; m + takes 0.9, m - takes 0.1; when k is equal to the actual sleep staging result , T k takes 1, otherwise takes 0; max() represents the maximum value function.

[0045] The specific step S4 is as follows:

[0046] Step S4.1: Input the test set into the trained sleep staging network model to obtain the sleep staging results of each sleep stage sequence in the polysomnogram signal

[0047] Step S4.2: Process the amplified sleep stage sequences in the test set :

[0048] First, set a sliding window with a length of k s and a sliding step of k s / 2, and use the sliding window in the form of a sliding mask to process the amplified sleep stage sequences Perform segment zeroing to obtain a zeroed sleep period sequence Wherein represents the amplified sleep period sequence with zeroing at position t, and t represents the zeroing position;

[0049] Step S4.3. Then, input the amplified sleep period sequence and the corresponding zeroed sleep period sequence into the trained sleep stage classification network model respectively, to obtain the probabilities v of various sleep stages existing in the amplified sleep period sequence n,k and the probabilities v of various sleep stages existing in the zeroed sleep period sequence n,k,t '; Obtain the zeroing position t when the difference between the probabilities and is the largest when k is equal to the actual sleep stage classification result , and use the amplified sleep period sequence at this zeroing position t as the decision basis for the sleep stage classification network model to make the sleep stage classification result .

[0050] Respectively use the capsules in the sub-capsule group and the parent-capsule group as sub-capsules and parent-capsules Use the convolutional capsule layer to obtain the expression of the parent-capsule as follows:

[0051]

[0052]

[0053] Wherein represents the capsule at the (h, w) position in the i-th capsule layer of the input capsule group corresponding to the logarithmic spectrum image s n , and the subscript i represents the ordinal number of the capsule layer in the input capsule group; represents the capsule at the (h, w) position in the j-th capsule layer of the output capsule group corresponding to the logarithmic spectrum image s n , and the subscript j represents the ordinal number of the capsule layer in the output capsule group; g() represents the activation function; represents the weighted sum of all sub-capsules; represents the routing coefficient between the sub-capsule at the (h, w) position and its corresponding parent-capsule, represents the prediction vector between the sub-capsule at the (h, w) position and its corresponding parent-capsule;

[0054] In the above formula, the routing coefficient between the sub-capsule and its corresponding parent-capsule and the prediction vector ​

[0055]

[0056]

[0057]

[0058] Among them, represents the prediction coefficient, represents the given first transformation matrix, which is used to transform the sub-capsules of the i-th layer at the (h, w) position into the parent capsules of the j-th layer; W ij represents the given second transformation matrix, which is used to transform the capsules of the i-th layer in the same capsule group into the capsules of the j-th layer.

[0059] In the step S1, according to the N sleep stage sequences x n The specific method for constructing the sleep stage classification dataset is as follows:

[0060] Step S1.1: First, obtain the label sequences y n corresponding to each sleep stage sequence x n , and respectively construct the sleep stage sequence set X n and the label sequence set Y n : A A A X

[0061] X A ={x 1 , x 2 , …, x n , …, x N}

[0062] Y A ={y 1 , y 2 , …, y n , …, y N}

[0063] y n ∈{1, 2, 3, 4, 5}

[0064] Among them, the subscript n represents the ordinal number of the sleep stage sequence; y n =1 indicates that the current sleep stage sequence x n is in the wakefulness stage; y n =2 indicates that the current sleep stage sequence x n is in the non-rapid eye movement stage I; y n =3 indicates that the current sleep stage sequence x n is in the non-rapid eye movement stage II; y n =4 indicates that the current sleep stage sequence x nIn non-rapid eye movement stage III; y n = 5 indicates the current sleep stage sequence x n In the rapid eye movement stage;

[0065] Step S1.2, then according to the following formula for the sleep stage sequence x n Perform boundary expansion to obtain each sleep stage sequence x n Corresponding amplified sleep stage sequence And based on the amplified sleep stage sequence Construct an amplified sleep stage sequence set

[0066]

[0067]

[0068] where x c Is a given zero amplification sequence, and the number of elements in the zero amplification sequence x c Is the same as the number of elements in the sleep stage sequence x n And all elements are 0; concatenate() represents the concatenation function;

[0069] Step S1.3, establish a sleep staging dataset, including the amplified sleep stage sequence set And the corresponding label sequence set Y A .

[0070] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0071] 1. The present invention uses a capsule network to overcome the problem that the traditional CNN network cannot establish hierarchical relationships between features. Using the capsule network as a feature extraction network can extract more effective multi-channel features, effectively improving the classification accuracy of the model.

[0072] 2. The present invention adopts a convolutional routing method with local constraints based on the attention mechanism, reducing the complex computational amount brought by large-size inputs and traditional dynamic routing, enabling the capsule network to process large-size sleep signals.

[0073] 3. The present invention uses the capsule characteristics of the capsule network to construct an interpretable analysis method, providing a basis for making the automatic sleep staging algorithm clinically applicable. Brief Description of the Drawings

[0074] Figure 1 Is a flowchart of a sleep staging and interpretability analysis method based on a deep capsule network provided by an embodiment of the present invention;

[0075] Figure 2Structural diagram of a sleep staging and interpretability analysis method based on a deep capsule network provided by an embodiment of the present invention;

[0076] Figure 3 Structural diagram of the data preprocessing module provided by an embodiment of the present invention;

[0077] Figure 4 Structural diagram of the capsule feature extraction network module provided by an embodiment of the present invention;

[0078] Figure 5 Structural diagram of the multi-head attention mechanism provided by an embodiment of the present invention;

[0079] Figure 6 Flowchart of the interpretability analysis method provided by an embodiment of the present invention. Detailed implementation manners

[0080] The present invention will be described in detail below in conjunction with specific implementation cases. The following implementation cases will help those skilled in the art to further understand the present invention, but do not limit the present invention in any form.

[0081] The sleep staging and interpretability analysis method based on the deep capsule network of the present invention includes the following steps, as Figure 1 shown:

[0082] Step S1: First, obtain the initial polysomnography dataset. According to the AASM sleep staging standard, divide the polysomnography signals in the polysomnography dataset into N sleep stage sequences x n , x n ∈R 30fs×c , where fs represents the sampling rate of the signal; c represents the number of channels. The signals of different channels in the polysomnography are uniformly resampled to fs = 100hz, and the signals with a sampling time t' less than 30s are discarded. According to the N sleep stage sequences x n , construct a sleep staging dataset, and then divide the sleep staging dataset into a training set, a validation set, and a test set according to a preset ratio of 7:1:2;

[0083] The specific method for constructing the sleep staging dataset according to the N sleep stage sequences x n in step S1 is:

[0084] Step S1.1: First, obtain the corresponding label sequence y n for each sleep stage sequence x n . According to the sleep stage sequence x n and the corresponding label sequence y n , construct a sleep stage sequence set X A and a label sequence set Y A respectively:

[0085] X A ={x 1 , x 2 , …, x n , …, x N}

[0086] Y A ={y 1 , y 2 , …, y n , …, y N}

[0087] y n ∈ {1, 2, 3, 4, 5}

[0088] where the subscript n represents the ordinal number of the sleep stage sequence; y n = 1 indicates that the current sleep stage sequence x n is in the wake stage; y n = 2 indicates that the current sleep stage sequence x n is in non-rapid eye movement stage I; y n = 3 indicates that the current sleep stage sequence x n is in non-rapid eye movement stage II; y n = 4 indicates that the current sleep stage sequence x n is in non-rapid eye movement stage III; y n = 5 indicates that the current sleep stage sequence x n is in the rapid eye movement stage;

[0089] Specifically, y n ∈ {Wake, N1, N2, N3, REM}, Wake = 1 represents the wake stage; N1 = 2 represents non-rapid eye movement stage I; N2 = 3 represents non-rapid eye movement stage II; N3 = 4 represents non-rapid eye movement stage III; REM = 5 represents the rapid eye movement stage, Wake, N1, N2, N3, REM are all sleep stages, and Wake can be abbreviated as W;

[0090] Step S1.2, then expand the boundary of the sleep stage sequence x n according to the following formula to obtain the amplified sleep stage sequence corresponding to each sleep stage sequence x n and construct an amplified sleep stage sequence set according to the amplified sleep stage sequence And according to the amplified sleep stage sequence Construct an amplified sleep stage sequence set

[0091]

[0092]

[0093] where x c is a given zero-amplified sequence, and the zero-amplified sequence xc The number of elements in is the same as that in the sleep stage sequence x n and all elements are 0, that is, the zero amplification sequence x c is a sequence with the same length as the sleep stage sequence x n and the number of elements in all sleep stage sequences x n is the same; concatenate() represents the concatenation function. When using the concatenate(a', b', c') function, it means concatenating sequence a' and sequence c' in front of and behind sequence b' respectively;

[0094] Step S1.3: Establish a sleep staging dataset, including an amplified sleep stage sequence set and the corresponding label sequence set Y A .

[0095] Step S2: Construct a sleep staging network model for sleep staging. The sleep staging network model includes a signal preprocessing module, a feature extraction module, and a feature classifier;

[0096] In step S2, the topological structure of the sleep staging network model is as follows, as Figure 4 shown:

[0097] The sleep staging network model is mainly composed of a signal preprocessing module, a feature extraction module based on a deep capsule network, and a feature classifier connected in sequence; the feature extraction module is mainly composed of a primary capsule layer, two consecutive convolutional capsule layers, and a norm normalization module connected in sequence. The output end of the signal preprocessing module is connected to the input end of the primary capsule layer, and the output end of the norm normalization module is connected to the input end of the feature classifier;

[0098] First, the amplified sleep stage sequences in the amplified sleep stage sequence set are input into the signal preprocessing module. As Figure 3 shown, the amplified sleep stage sequence is subjected to short-time Fourier transform STFT to obtain the logarithmic spectrum image s corresponding to the amplified sleep stage sequence n , and the logarithmic spectrum image s n ∈R f×t×c , f represents the frequency band. According to the logarithmic spectrum image s n , a logarithmic spectrum image set S A is constructed:

[0099] S A ={s 1 , s 2 ,…, s n ,…, s N}

[0100] Next, for the logarithmic spectrum image s n After passing through the primary capsule layer, the corresponding primary capsule group P is output A,n :

[0101]

[0102]

[0103] Among them, represents the m-th capsule layer in the primary capsule group P. The subscript m represents the ordinal number of the capsule layer in the capsule group, and M represents the total number of capsule layers in the primary capsule group; A,n represents the capsule at the position (h, w) in the m-th capsule layer of the primary capsule group P. The subscripts h and w respectively represent the positions of the capsule in the height direction and width direction of the capsule layer, and H and W respectively represent the total height and total width of the capsule layer in the primary capsule group. The capsule layers of the same capsule group are set to have the same total height and total width; represents the primary capsule group P A,n After being processed by two consecutive convolutional capsule layers, the target capsule group D is obtained

[0104] The output primary capsule group P A,n After being processed by two consecutive convolutional capsule layers, the target capsule group D is obtained. According to the target capsule group D A,n , the features f' of each sleep stage sequence x A,n are obtained, and after performing L2-norm normalization on the target capsule group D n , the probabilities v of the existence of various sleep stages in the sleep stage sequence x n are obtained; A,n n n,k n n ;

[0105] The features f' of N consecutive sleep stage sequences x n are input into the feature classifier, and the staging results corresponding to each sleep stage sequence x n are output n .

[0106] In specific implementation, the features f' of L consecutive sleep stage sequences x n can be input into the feature classifier first, where L << N. Input them into the feature classifier N / L times, so that the length of the sequence input each time is smaller and the operation speed is faster. n

[0107] ​The primary capsule layer is mainly composed of three consecutive feature extraction sub-modules, an activation function layer g, and a reshape function layer connected in sequence. Each feature extraction sub-module is mainly composed of a 2D convolution module with a convolution kernel size of 3×3, a batch normalization layer, and a Relu activation function. That is, the Relu activation function of the first feature extraction sub-module is connected to the 2D convolution module of the second feature extraction sub-module, and the Relu activation function of the second feature extraction sub-module is connected to the 2D convolution module of the third feature extraction sub-module. The activation function layer is mainly composed of a 2D convolution module with a convolution kernel size of 1×1 and a Tanh activation function connected. The Relu activation function of the third feature extraction sub-module is connected to the 2D convolution module of the activation function layer, and the Tanh activation function is connected to the reshape function layer, and the logarithmic spectral image s n is input into the 2D convolution module of the first feature extraction sub-module, and the logarithmic spectral image s is output by the reshape function layer n The corresponding primary capsule group P A,n .

[0108] Specifically, three consecutive feature extraction sub-modules form a feature extraction function layer f 1 , for each input logarithmic spectral image s in the primary capsule layer n , the initial feature obtained is P B,n ’ = g(f : (s n ))), where g represents the activation function layer, and the activation function g(x) = Tanh(conv 1×1 (x)), Tanh() represents the Tanh activation function, and conv 1×1 () represents a 2D convolution operation with a convolution kernel size of 1×1; finally, the reshape function layer is used to divide the initial feature P B,n ’ into M classes of capsules, and one class of capsules is represented by one layer of capsule layer to obtain the primary capsule group P A,n , and the capsules in the primary capsule group P A,n d p represents the dimension of the capsule .

[0109] The convolutional capsule layer is used to convert the input capsules with a preset convolution kernel size to generate new capsules, and the input capsule group and output capsule group of the convolutional capsule layer are used as the sub-capsule group and the parent capsule group respectively; the capsules in the sub-capsule group and the parent capsule group are used as sub-capsules and parent capsules respectively, and the expression of the parent capsule is obtained by using the convolutional capsule layer as follows:

[0110] ​

[0111]

[0112] wherein, represents the sub-capsule at the (h, w) position in the i-th capsule layer of the input capsule group corresponding to the logarithmic spectrum image s n ; the subscript i represents the ordinal number of the capsule layer in the input capsule group; represents the parent capsule at the (h, w) position in the j-th capsule layer of the output capsule group corresponding to the logarithmic spectrum image s n ; the subscript j represents the ordinal number of the capsule layer in the output capsule group; g() represents the activation function, which is the same as the activation function g(x) in the primary capsule layer; represents the weighted sum of all sub-capsules; represents the routing coefficient associated with the sub-capsule and its corresponding parent capsule at the (h, w) position, represents the prediction vector between the sub-capsule and its corresponding parent capsule at the (h, w) position;

[0113] In the above formula, the routing coefficient between the sub-capsule and the corresponding parent capsule and the prediction vector

[0114]

[0115]

[0116]

[0117] wherein, represents the prediction coefficient, represents the given first transformation matrix for transforming the sub-capsule of the i-th layer at the (h, w) position into the parent capsule of the j-th layer. The capsules of the same class are represented by one capsule layer. Therefore, the capsules of the i-th layer can also be considered as the capsules of the i-th class, and the capsules of the j-th layer can also be considered as the capsules of the j-th class; W ij represents the given second transformation matrix for transforming the capsules of the i-th layer in the same capsule group into the capsules of the j-th layer.

[0118] The primary capsule group P A,n is processed by two consecutive convolutional capsule layers to obtain the target capsule group D A,n and the probability v n,k The specific steps are as follows:

[0119] Step S2.1: First, the primary capsule group P A,n output by the primary capsule layer is used as the first sub-capsule group and input into the first convolutional capsule layer, and the first parent capsule group C A,n is output;

[0120] Capsule group C A,n has the same structural form as the primary capsule group and is also a three-dimensional matrix. Each capsule in capsule group C A,n can be expressed as ; the difference is that the total number and size of the capsule layers can be inconsistent:

[0121]

[0122]

[0123] Among them, represents the m-th capsule layer in capsule group C A,n , and MM represents the total number of capsule layers in capsule group C A,n ; represents the capsule at the (h, w) position in the m-th capsule layer of capsule group C A,n , and HH and WW respectively represent the total height and total width of the capsule layers in capsule group C A,n ;

[0124] The convolution kernel size of the first convolutional capsule layer is not equal to the capsule layer size H×W of the primary capsule group P A,n ;

[0125] Step S2.2. Then, take the capsule group C A,n output in step S2.1 as the second sub-capsule group and input it into the second convolutional capsule layer, and output the second parent capsule group as the target capsule group D A,n ;

[0126] Set the convolution kernel size of the second convolutional capsule layer to be equal to the capsule layer size in capsule group C A,n , and set the total number of capsule layers in the target capsule group D A,n to be 5. The expression of the target capsule group D A,n is as follows:

[0127]

[0128]

[0129] Among them, represents the m-th capsule layer in the target capsule group D A,n ;

[0130] Since the convolution kernel size of the second convolutional capsule layer is equal to the capsule layer size in capsule group C A,n , the output target capsule group D A,nBoth the height and width are 1, and the target capsule group D A,n Capsules in where d f represents the dimension of the capsule;

[0131] Step S2.3: According to the target capsule group D A,n Obtain the corresponding sleep stage sequence x n with the feature f′ n :

[0132]

[0133] where concatenate() represents the concatenation function;

[0134] Step S2.4: According to the target capsule group D A,n Use the following formula to process and obtain the corresponding sleep stage sequence x n The probability v of the existence of various sleep stages n,k :

[0135]

[0136]

[0137] k = m, k ∈ {1, 2, 3, 4, 5}

[0138] where v n,k represents the probability of the existence of the k-th sleep stage in the sleep stage sequence x n ; k = 1 represents the waking stage; k = 2 represents the non-rapid eye movement stage I; k = 3 represents the non-rapid eye movement stage II; k = 4 represents the non-rapid eye movement stage III; k = 5 represents the rapid eye movement stage; d f represents the dimension of each capsule in the target capsule group D A,n ; L 2 () represents the function of taking the two-norm.

[0139] Specifically, the second convolutional capsule layer and the norm normalization module constitute the high-level capsule layer. The feature extraction module contains a convolutional routing algorithm based on the attention mechanism; for the parent capsule of the convolutional capsule layer, it can only receive the routing information of a specified sub-capsule group with the convolutional kernel size of the previous capsule layer as follows:

[0140] First, each input capsule within the specified convolutional kernel size passes through a deep learning transform matrix W ij to obtain its predicted vector The transform matrix W ijIndependent of the capsule position (h, w), whose value is parameter - shared throughout the affine transformation after a given capsule type, the final output of the convolutional capsule is the weighted sum of all different types of sub - capsules:

[0141]

[0142] is the routing coefficient that associates the sub - capsule at (h, w) with its corresponding parent capsule. The present invention uses an attention mechanism as the routing algorithm instead of dynamic routing.

[0143] Input the features f′ n of the sleep period sequence x n into the feature classifier, and the specific way to output the staging results corresponding to each sleep period sequence x n is as follows:

[0144] First, concatenate the features f′ n of all sleep period sequences x n , and encode the positions of the features f′ n of the sleep period sequences to obtain the concatenated sleep period time series G A :

[0145] G A = concatenate(f′ 1 , f′ 2 ,..., f′ n ,..., f′ N )

[0146] where concatenate() represents the concatenation function;

[0147] Then, input the sleep period time series G A into the feature classifier network based on the multi - head attention mechanism for temporal correlation learning, and obtain the sleep staging results of each sleep period sequence x A in the sleep period time series G n indicates that the current sleep period sequence x n is in the wake period; indicates that the current sleep period sequence x n is in non - rapid eye movement stage I; indicates that the current sleep period sequence x n is in non - rapid eye movement stage II; indicates that the current sleep period sequence x n is in non - rapid eye movement stage III; indicates that the current sleep period sequence x n is in the rapid eye movement period;

[0148] Among them, the feature classifier network based on the multi-head attention mechanism is an existing feature classifier, and the topological structure of this feature classifier is as Figure 5 shown.

[0149] Step S3: Input the training set in Step S1 into the constructed sleep staging network model for training, and then use the validation set to verify the trained sleep staging network model to determine the weights of the sleep staging network model with the optimal accuracy;

[0150] During the training in Step S3, the loss function is used to calculate the loss of the sleep staging network model, and at the same time, the sleep staging network model is trained through the gradient descent algorithm. The loss calculation is specifically processed according to the following formula:

[0151]

[0152]

[0153] Among them, loss represents the loss, N represents the total number of sleep stage sequences; α represents the given loss parameter; L n represents the Margin loss function; m + takes 0.9, and m - takes 0.1; when k is equal to the actual sleep staging result , T k takes 1, otherwise takes 0; max() represents the maximum value function.

[0154] Step S4: Input the test set obtained in Step S1 into the trained sleep staging network model to obtain the sleep staging results of each sleep stage sequence in the polysomnogram signal. In addition, an interpretability analysis method is also constructed: Input the original signal of the test set and the signal of the partially masked test set obtained in Step S1 into the trained sleep staging network model to obtain the decision basis for the model to classify, as Figure 2 shown.

[0155] The specific steps of Step S4 are as follows, as Figure 6 shown:

[0156] Step S4.1: Input the test set into the trained sleep staging network model to obtain the sleep staging results of each sleep stage sequence in the polysomnogram signal

[0157] Step S4.2: Process the amplified sleep stage sequences in the test set as follows:

[0158] First, set the length to k P and the sliding step size to k PA sliding window of / 2, and using the sliding window in the form of a sliding mask to process the amplified sleep period sequence to perform fragment zeroing processing to obtain a zeroed sleep period sequence where represents the amplified sleep period sequence with zeroing processing at position t, and t represents the zeroing position;

[0159] Step S4.3: Then, input the amplified sleep period sequence and the corresponding zeroed sleep period sequence into the trained sleep staging network model respectively, to obtain the probabilities v of various sleep stages existing in the amplified sleep period sequence n,k and the probabilities v of various sleep stages existing in the zeroed sleep period sequence n,k,t '; Obtain the zeroing position t when k is equal to the actual sleep staging result and the difference between the probabilities and is the largest, and use the amplified sleep period sequence at this zeroing position t as the decision basis for the sleep staging network model to make the sleep staging result .

[0160] The specific method for constructing the interpretability analysis method in Step 4 is: For a trained model, given the input sequence to obtain the intermediate output {v n,1 , v n,2 , v n,3 , v n,4 , v n,5}, where v n,k represents the existence probability of the k-th type of sleep stage feature in the n-th sleep period. Using a sliding window with a length of k s and a sliding step of k s / 2 to perform sliding masking on the original signal , zero the signals within the sliding window, record the masking position as t, and observe the output probability v ' corresponding to the masked signal and the output probability v n,k,t corresponding to the original signal . For different t, when k = the sleep staging result , make v n,k -v n,k -v n,k,t ' the largest, record and highlight this position t, and use this position as the basis for the model to make classification judgments.

[0161] In a specific embodiment provided in the present invention, the publicly available dataset SleepEDFx was used, which contains a total of 153 EDF sleep records. The SleepEDFx dataset adopted the Fpz-Cz and Pz-Oz of the EEG channels and the EOG channel. The experimental design used 10-fold cross-validation, dividing the data into a training set, a validation set, and a test set. For each fold, the EDF data of 7 individuals was taken as the validation set to verify whether to stop training, and the test set was used as the judgment for the final index to test the model.

[0162] The performance of the model provided by the present invention is as follows, including the accuracy ACC, F1 score, and macro-f1 (MF1) score for each category;

[0163] The performance of this invention model is better than other studies, and the results are shown in Table 1:

[0164]

[0165] In the above table, SleepEEGNet, U-time, SeqSleepNet, XSleepNet2, and AttnSleep are all existing sleep staging models. The accuracy ACC represents the ratio of the number of samples correctly classified by the classification model to the total number of samples for a given test set. The F1 score is a metric used in statistics to measure the precision of a binary classification model. It takes into account both the precision and recall of the classification model. Macro-f1 (MF1) is the arithmetic mean of the F1 scores for each class, which treats all classes equally without considering the importance of different classes. F1(W) represents the F1 score for the wake period, F1(N1) represents the F1 score for non-rapid eye movement stage I, F1(N2) represents the F1 score for non-rapid eye movement stage II, F1(N3) represents the F1 score for non-rapid eye movement stage III, and F1(REM) represents the F1 score for the rapid eye movement period. These metrics are commonly used to measure the performance of sleep staging models.

[0166] It can be concluded that the model proposed in the present invention has reached the current advanced level, and the recognition effect for different types of sleep stages is better than other models. This model accurately recognizes the rapid eye movement period, which is helpful for diagnosing and evaluating sleep disorder types, such as rapid eye movement sleep behavior disorder, etc.

[0167] In summary, the above is only the preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A sleep staging and interpretability analysis method based on deep capsule network, characterized in that: The following steps are involved: Step S1: first obtain an initial sleep polygraph data set, and divide the sleep polygraph signals in the sleep polygraph data set into N sleep stage sequences x according to the AASM sleep staging standard. n , according to the N sleep period sequence x n Construct a sleep staging dataset, and then divide the sleep staging dataset into a training set, a validation set, and a test set according to a preset ratio of 7:1:2; Step S2, constructing a sleep staging network model for sleep staging, wherein the sleep staging network model includes a signal preprocessing module, a feature extraction module and a feature classifier; Step S3, inputting the training set in step S1 into the constructed sleep staging network model for training, and then using the validation set to validate the trained sleep staging network model to determine the weight of the sleep staging network model with the best accuracy; Step S4, inputting the test set obtained in step S1 into the trained sleep staging network model to obtain the sleep staging results of each sleep stage sequence in the sleep polygraph signal; In step S2, the topological structure of the sleep staging network model is as follows: The sleep staging network model is composed of a signal preprocessing module, a feature extraction module based on a deep capsule network, and a feature classifier connected in sequence; the feature extraction module is composed of a primary capsule layer, two continuous convolutional capsule layers, and a norm normalization module connected in sequence, the output end of the signal preprocessing module is connected to the input end of the primary capsule layer, and the output end of the norm normalization module is connected to the input end of the feature classifier; The step S4 is specifically as follows: Step S4.1: Input the test set into the trained sleep staging network model to obtain the sleep staging results of each sleep stage sequence in the sleep polygraph signal Step S4.2: amplify the sleep sequence in the test set To process: First, set the length to k s , the sliding step length is k s / 2 sliding window, using the sliding window to amplify the sleep period sequence in a sliding mask manner Perform fragment zeroing processing to obtain a zeroed sleep period sequence in represents an amplified sleep period sequence that is zeroed at position t, where t represents the zeroing position; Step S4.3: Next, amplify the sleep period sequence and the corresponding zeroed sleep period sequence Input them into the trained sleep staging network model to obtain the amplified sleep stage sequence The probability v of each sleep stage existing n,k and zeroing sleep period sequences The probability v of each sleep stage existing n,k,t '; Get the current k and actual sleep stage results When equal, the probability and The zero position t when the difference is the largest, and the amplified sleep period sequence at the zero position t Sleep staging results as a sleep staging network model basis for decision making.

2. According to claim 1, a sleep staging and interpretability analysis method based on a deep capsule network is characterized by: First, expand the sleep period sequence set Amplified sleep sequence in The signal is input into the signal preprocessing module and the logarithmic spectrum image s is obtained through short-time Fourier transform STFT. n : Then the log spectrum image s n After passing through the primary capsule layer, the corresponding primary capsule group P is output A,n : in, Represents the primary capsule group P A,n The mth capsule layer in the primary capsule group, where the subscript m represents the ordinal number of the capsule layer in the capsule group, and M represents the total number of capsule layers in the primary capsule group; Represents the primary capsule group P A,n The capsule at position (h,w) in the m-th capsule layer, where the subscripts h and w represent the positions of the capsule in the height direction and width direction of the capsule layer, respectively, and H and W represent the total height and total width of the capsule layer in the primary capsule group, respectively; Output primary capsule group P A,n After two consecutive convolutional capsule layers, the target capsule group D is obtained. A,n , according to the target capsule group D A,n Get each sleep period sequence x n The characteristic f′ n , and for the target capsule group D A,n After the two-norm normalization process, the sleep period sequence x is obtained n The probability v of each sleep stage existing n,k ; The N consecutive sleep period sequences x n The characteristic f′ n Input into the feature classifier and output each sleep period sequence x n The corresponding staging results.

3. The sleep staging and interpretability analysis method based on deep capsule network according to claim 1, characterized in that: The primary capsule layer is composed of three consecutive feature extraction submodules, an activation function layer g and a reshape function layer connected in sequence, each feature extraction submodule is composed of a 2d convolution module with a convolution kernel size of 3×3, a batch normalization layer and a Relu activation function connected in sequence, and the activation function layer is composed of a 2d convolution module with a convolution kernel size of 1×1 and a Tanh activation function connected; The Relu activation function of the third feature extraction submodule is connected to the 2D convolution module of the activation function layer, the Tanh activation function is connected to the reshape function layer, and the log spectrum image s n Input to the 2D convolution module of the first feature extraction submodule, and the log spectrum image s is output by the reshape function layer n The corresponding primary capsule group P A,n .

4. The sleep staging and interpretability analysis method based on deep capsule network according to claim 2, characterized in that: The convolution capsule layer is used to convert the input capsule into a preset convolution kernel size. Convert and generate new capsules, and use the input capsule group and output capsule group of the convolutional capsule layer as the child capsule group and the parent capsule group respectively; the primary capsule group P A,n After two consecutive convolutional capsule layers, the target capsule group D is obtained. A,n and probability v n,k The specific steps are: Step S2.1: First, the primary capsule group P output by the primary capsule layer A,n As the first child capsule group, it is input into the first convolutional capsule layer and outputs the first parent capsule group C A,n ; The convolution kernel size of the first convolutional capsule layer Not equal to primary capsule group P A,n The size of the middle capsule layer is H×W; Step S2.2: Next, the capsule group C output in step S2.1 is A,n As the second child capsule group, it is input into the second convolution capsule layer and the second parent capsule group is output as the target capsule group D A,n ; Set the convolution kernel size of the second convolutional capsule layer Equivalent to capsule group C A,n The capsule layer size in , and set the target capsule group D A,n The total number of capsule layers is 5, and the target capsule group D A,n The expression is as follows: in, Indicates the target capsule group D A,n The mth capsule layer in ; Step S2.3: According to the target capsule group D A,n Get the corresponding sleep period sequence x n The characteristic f′ n : Among them, concatenate() represents the concatenation function; Step S2.4: According to the target capsule group D A,n The corresponding sleep period sequence x is obtained by using the following formula: n The probability v of each sleep stage existing n,k : k=m,k∈{1,2,3,4,5} Among them, v n,k represents the sleep period sequence x n The probability of the existence of the k-th sleep stage in the sleep cycle; k = 1 means the sleep stage is awake; k = 2 means the sleep stage is non-rapid eye movement stage I; k = 3 means the sleep stage is non-rapid eye movement stage II; k = 4 means the sleep stage is non-rapid eye movement stage III; k = 5 means the sleep stage is rapid eye movement; d f Indicates the target capsule group D A,n The dimension of each capsule in; L2( ) represents the two-norm function.

5. The sleep staging and interpretability analysis method based on deep capsule network according to claim 2, characterized in that: The sleep period sequence x n The characteristic f′ n Input into the feature classifier and output each sleep period sequence x n The specific method of corresponding staging results is: First, all sleep period sequences x n The characteristic f′ n splicing, and the characteristics of the sleep period sequence f′ n The position is encoded to obtain the concatenated sleep period time series G A : G A =concatenate(f′1,f′2,…,f′ n ,...,f′ N ) Among them, concatenate() represents the concatenation function; Then the sleep period time series G A Input into the feature classifier network based on the multi-head attention mechanism for time correlation learning, and obtain the sleep period time series G A Each sleep phase sequence x n Sleep staging results 6. The sleep staging and interpretability analysis method based on deep capsule network according to claim 1, characterized in that: During the training in step S3, the loss function is used to calculate the loss of the sleep staging network model, and the sleep staging network model is trained by a gradient descent algorithm. The loss calculation is specifically obtained by the following formula: Among them, loss represents loss, N represents the total number of sleep period sequences; α represents the given loss parameter; L n represents the Margin loss function; m + Take 0.9, m - Take 0.1; when k and the actual sleep stage result When they are equal, T k Take 1, otherwise take 0; max() means to take the maximum value function; y n Represents each sleep period sequence x n The corresponding label sequence; v n,k represents the sleep period sequence x n The probability of the existence of the k-th sleep stage.

7. The sleep staging and interpretability analysis method based on deep capsule network according to claim 4, characterized in that: The capsules in the sub-capsule group and the parent capsule group are respectively used as sub-capsules Hefu Capsule The expression for obtaining the parent capsule using the convolutional capsule layer is as follows: in, Representation and log spectrum image s n The capsule at position (h, w) in the i-th capsule layer of the corresponding input capsule group, where the subscript i represents the ordinal number of the capsule layer in the input capsule group; Representation and log spectrum image s n The capsule at position (h, w) in the j-th capsule layer of the corresponding output capsule group, where the subscript j represents the ordinal number of the capsule layer in the output capsule group; g( ) represents the activation function; represents the weighted sum of all sub-capsules; represents the routing coefficient associated with the child capsule at position (h,w) and its corresponding parent capsule, Represents the prediction vector between the child capsule at position (h,w) and its corresponding parent capsule; In the above formula, the routing coefficient between the child capsule and the corresponding parent capsule is and the prediction vector The expression is as follows: in, represents the prediction coefficient, W represents the given first transformation matrix, which is used to transform the child capsule of the i-th layer at the position (h, w) into the parent capsule of the j-th layer; ij Represents a given second transformation matrix, which is used to transform the capsule of the i-th layer in the same capsule group into the capsule of the j-th layer.

8. The sleep staging and interpretability analysis method based on deep capsule network according to claim 1, characterized in that: In step S1, according to N sleep period sequences x n The specific method of constructing the sleep stage dataset is as follows: Step S1.1: First, obtain each sleep period sequence x n The corresponding label sequence y n , according to the sleep period sequence x n and the corresponding label sequence y n Construct the sleep period sequence set X A and label sequence set Y A : X A {x1,x2,…,x n ,…,x N } Y A ={y1,y2,…,y n ,…,y N } y n ∈{1,2,3,4,5} Wherein, the subscript n represents the ordinal number of the sleep period sequence; y n =1 indicates the current sleep sequence x n In the sober stage; n =2 indicates the current sleep period sequence x n In non-rapid eye movement I stage; y n =3 indicates the current sleep sequence x n In non-rapid eye movement II stage; n =4 indicates the current sleep period sequence x n In non-rapid eye movement stage III; n =5 indicates the current sleep sequence x n In rapid eye movement sleep; Step S1.2, then calculate the sleep period sequence x according to the following formula n Expand the boundaries and get the sleep period sequence x n Corresponding augmented sleep period sequence And according to the amplified sleep sequence Constructing an augmented sleep period sequence set Among them, x c For a given zero amplification sequence, the zero amplification sequence x c The number of elements in the sleep sequence x n The number of elements in is the same and all elements are 0; concatenate() represents the concatenation function; Step S1.3: Establish a sleep stage dataset, including expanding the sleep stage sequence set and the corresponding label sequence set Y A .

Citation Information

Patent Citations

  • Single-channel electroencephalogram sleep staging method based on deep learning

    CN116186544A

  • Method for training sleep stage classification model

    CN116304882A