Sleep staging and interpretability analysis method based on deep capsule network
Through the deep capsule network and attention mechanism, the characteristics of multi-channel sleep signals are extracted, which solves the problem of difficulty in effectively utilizing multi-channel information and over-fitting in the sleep staging algorithm in the existing technology, and improves the accuracy and interpretability of sleep staging. , achieving more clinically valuable sleep staging results.
Patent Information
- Application Number
- CN202410615522.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-17
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-05-17
AI Technical Summary
Existing sleep staging algorithms are difficult to effectively extract information from multi-channel signals when utilizing polysomnography data, and traditional CNN and transformer models have overfitting problems when identifying sleep stages, and automatic sleep staging algorithms are difficult to Clinical application.
A sleep staging method based on deep capsule network is used to extract features through primary capsule layer and continuous convolution capsule layer, and combined with attention mechanism and norm normalization, a sleep staging network model is constructed to improve the accuracy and interpretability of sleep staging. sex.
It improves the accuracy of sleep staging and the interpretability of the model, overcomes the problem that traditional CNN cannot establish feature hierarchical relationships, and reduces the complex calculation of large-size input, making the sleep staging algorithm more clinically usable.
Smart Images

Figure CN118568558A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of sleep staging, and specifically relates to providing a sleep staging method based on a deep capsule network. Background Art
[0002] Sleep is an important physiological cycle for humans, accounting for one-third of an individual's life span. With the development of the times, the incidence of sleep disorders is also increasing. Sleep disorders can lead to reduced work efficiency, decreased immunity, and pose a threat to human health. Long-term sleep disorders may lead to various chronic diseases, such as hypertension, Alzheimer's disease, Parkinson's disease, and depression. Using polysomnography (PSG) data for sleep staging is the basis for the diagnosis and treatment of sleep disorders. PSG includes physiological signals such as electroencephalogram (EEG), electroencephalogram (EOG), electrocardiogram (ECG), and electromyogram (EMG). According to the sleep stage standards established by the American Association of Sleep Medicine (AASM), these signals are segmented into 30-second time intervals (called "durations") and subsequently classified into one of five stages (W, N1, N2, N3, and REM). It takes a human expert two hours to complete this process, so it is necessary to establish an accurate automatic sleep staging system to meet these challenges. Early automatic sleep staging algorithms used traditional machine learning methods to divide EEG signals into corresponding sleep stages. These methods usually include two steps, namely, manual feature extraction and sleep stage classification. First, they design and extract various features in the time domain and frequency domain. Feature selection algorithms are usually used to further select the most discriminative features. Second, the selected features are input into traditional machine learning models for sleep stage classification, such as plain Bayes, support vector machine (SVM), random forest (RF), and even ensemble learning-based classifiers. 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 (CNN), deep neural networks (DNN), and recurrent neural networks (RNN) were often used to extract features. These methods are based on a one-to-one scheme and use a single EEG epoch signal to predict the corresponding sleep stage. In order to exploit the contextual 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, tranformer, and CNN+tranformer. In order to obtain effective features of the EEG, Mohsenvand et al. designed convolution channels with different convolution kernels to extract features to obtain frequency and amplitude information of different scales. These studies use feature maps with different receptive field sizes to obtain richer information from a given input signal, but ignore 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 are based on CNN or transformers to accurately extract features from multi-channel PSG data, and these methods perform well in sleep staging tasks.CNNs cannot identify the position of one object relative to another, and transformers tend to overfit on small data sets. At the same time, the "black box" nature of neural networks makes automatic sleep staging algorithms difficult to use clinically. Summary of the invention
[0003] In order to solve the problems in the background technology, the purpose of the present invention is to provide a sleep staging and interpretable analysis method based on a deep capsule network, which further improves the accuracy of sleep staging by establishing connections between features at different levels, and uses the characteristic that the capsule module length represents the probability of feature existence to provide an interpretable analysis method for model decision-making.
[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 includes the following steps:
[0006] 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;
[0007] 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;
[0008] 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;
[0009] 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 sleep polygraph signal.
[0010] In 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 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;
[0012] 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 :
[0013] Then the log spectrum image s n After passing through the primary capsule layer, the corresponding primary capsule group P is output A,n :
[0014]
[0015]
[0016] In the formula, 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;
[0017] 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 ;
[0018] 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.
[0019] The primary capsule layer is mainly 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 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, and 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 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 .
[0020] 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:
[0021] 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 ;
[0022] 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;
[0023] 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 ;
[0024] 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:
[0025]
[0026]
[0027] in, Indicates the target capsule group D A,n The mth capsule layer in ;
[0028] Step S2.3: According to the target capsule group D A,n Get the corresponding sleep period sequence x n The characteristic f′ n :
[0029]
[0030] Among them, concatenate() represents the concatenation function;
[0031] 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 :
[0032]
[0033]
[0034] k=m,k∈{1,2,3,4,5}
[0035] 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.
[0036] 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:
[0037] 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 :
[0038] G A =concatenate(f′1,f′2,...,f′ n ,...,f′ N )
[0039] Among them, concatenate() represents the concatenation function;
[0040] 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
[0041] 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:
[0042]
[0043]
[0044] 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() represents the maximum value function.
[0045] The step S4 is specifically 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 sleep polygraph signal
[0047] Step S4.2: amplify the sleep sequence in the test set To process:
[0048] 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;
[0049] Step S4.3: Next, amplify the sleep period sequence and the corresponding zeroed sleep period sequence Input them into the trained sleep stage 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.
[0050] 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:
[0051]
[0052]
[0053] 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;
[0054] 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:
[0055]
[0056]
[0057]
[0058] 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.
[0059] In step S1, according to N sleep period sequences x n The specific method of constructing the sleep stage dataset is as follows:
[0060] 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 respectively A and label sequence set Y A :
[0061] X A ={x1,x2,…,x n ,…,x N}
[0062] Y A ={y1,y2,…,y n ,…,y N}
[0063] y n ∈{1,2,3,4,5}
[0064] 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;
[0065] 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
[0066]
[0067]
[0068] 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;
[0069] Step S1.3: Establish a sleep stage dataset, including expanding the sleep stage sequence set and the corresponding label sequence set Y A .
[0070] Compared with the prior art, the present invention has the following beneficial effects:
[0071] 1. The present invention uses capsule network to overcome the problem that traditional CNN network cannot establish hierarchical relationship between features. By using capsule network as feature extraction network, more effective multi-channel features can be extracted, so that the classification accuracy of the model can be effectively improved.
[0072] 2. The present invention adopts a convolutional routing method with local constraints based on the attention mechanism, which reduces the complex calculation amount caused by large-size input and traditional dynamic routing, so that the capsule network can process sleep signals with large-size input.
[0073] 3. The present invention utilizes the capsule characteristics of the capsule network to construct an interpretable analysis method, providing a basis for realizing the clinical applicability of the automatic sleep staging algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] Figure 1 A flow chart of a sleep staging and solvability analysis method based on a deep capsule network provided by an embodiment of the present invention;
[0075] Figure 2 A structural diagram of a method for sleep staging and solvability analysis based on a deep capsule network provided by an embodiment of the present invention;
[0076] Figure 3 A structural diagram of a data preprocessing module provided in an embodiment of the present invention;
[0077] Figure 4 A structural diagram of a capsule feature extraction network module provided in an embodiment of the present invention;
[0078] Figure 5 A structural diagram of a multi-head attention mechanism provided for an embodiment of the present invention;
[0079] Figure 6 A flow chart of an interpretable analysis method provided for an embodiment of the present invention. DETAILED DESCRIPTION
[0080] The present invention is 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 will 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 comprises the following steps: Figure 1 As shown:
[0082] 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 at a resolution of 1 / 30 Hz. n , x n ∈R 30fs×c , fs represents the sampling rate of the signal; c represents the number of channels. The signals of different channels in the sleep polygraph are uniformly resampled to fs = 100 Hz, and the signals with sampling time t' less than 30 s are discarded. 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] In step S1, according to N sleep period sequences x n The specific method of constructing the sleep stage dataset is as follows:
[0084] 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 respectively A and label sequence set Y A :
[0085] X A ={x1,x2,…,x n ,…,x N}
[0086] YA ={y1,y2,…,y n ,…,y N}
[0087] y n ∈{1,2,3,4,5}
[0088] 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;
[0089] Specifically, y n ∈{Wake, N1, N2, N3, REM}, Wake = 1 indicates wakefulness; N1 = 2 indicates non-rapid eye movement I; N2 = 3 indicates non-rapid eye movement II; N3 = 4 indicates non-rapid eye movement III; REM = 5 indicates rapid eye movement. Wake, N1, N2, N3, REM are all sleep stages. Wake can be abbreviated as W.
[0090] 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
[0091]
[0092]
[0093] 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, that is, the zero-amplification sequence x c is the sleep period sequence x n Sequences of the same length, all sleep period sequences x nThe number of elements in the sequence a' is the same; concatenate() represents a concatenation function. When the concatenate(a', b', c') function is used, it means that the sequence a' and the sequence c' are concatenated before and after the sequence b' respectively;
[0094] Step S1.3: Establish a sleep stage dataset, including expanding the sleep stage sequence set and the corresponding label sequence set Y A .
[0095] 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;
[0096] In step S2, the topological structure of the sleep staging network model is as follows: Figure 4 As 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 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;
[0098] First, expand the sleep period sequence set Amplified sleep sequence in Input to the signal preprocessing module, such as Figure 3 As shown, the sleep period sequence is expanded The amplified sleep period sequence is obtained by short-time Fourier transform STFT The corresponding log spectrum image s n , log spectrum image s n ∈R f×t×c ,f represents the frequency band, according to the log spectrum image s n Construct the logarithmic spectrum image set S A :
[0099] S A ={s1,s2,…,s n ,…,s N}
[0100] Then the log 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, 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; A,n represents the capsule at the (h, w) position in the m-th capsule layer of the primary capsule group P, where the subscripts h and w respectively represent the positions of the capsule in the height and width directions 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 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 processing 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
[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, and input 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 connected in sequence. 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. The logarithmic spectrogram image sn 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 .
[0108] Specifically, three consecutive feature extraction submodules form a feature extraction function layer f1. For each input log spectrum image s in the primary capsule layer n , the initial feature obtained is P B,n '=g(f : (s n )), g represents the activation function layer, and the activation function in the activation function layer is g(x)=Tanh(conv 1×1 (x)), Tanh() represents the Tanh activation function, conv 1×1 () represents a 2D convolution operation with a convolution kernel size of 1×1; finally, the reshape function layer is used to convert the initial feature P B,n 'It is divided into M types of capsules, one type of capsule is represented by a capsule layer, and the primary capsule group P is obtained A,n , Primary Capsule Group P A,n Capsules in d p Capsules Dimension.
[0109] The convolution capsule layer is used to convert the input capsule into a convolution kernel with a preset size. Convert and generate new capsules. 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-capsule groups respectively. Hefu Capsule , the expression of obtaining the parent capsule using the convolutional capsule layer is as follows:
[0110]
[0111]
[0112] in, Representation and log spectrum image s n The subcapsule 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 parent 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, 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 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;
[0113] 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:
[0114]
[0115]
[0116]
[0117] 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. The same type of capsule is represented by one capsule layer, so the capsule of the i-th layer can also be considered as the capsule of the i-th class, and the capsule of the j-th layer can also be considered as the capsule of the j-th class; W 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.
[0118] Primary capsule set 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:
[0119] 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 ;
[0120] Capsule Group C A,n The structure of the capsule group C is consistent with that of the primary capsule group, which is also a three-dimensional matrix. A,n Each capsule in can be represented as ; The difference is that the total number and size of capsule layers can be inconsistent:
[0121]
[0122]
[0123] in, Indicates capsule group C A,n The mth capsule layer in , MM represents the capsule group C A,nThe total number of capsule layers in the middle; Indicates capsule group C A,n The capsule at position (h,w) in the mth capsule layer in , HH, WW represent capsule groups C A,n The total height and width of the middle capsule layer.
[0124] 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;
[0125] 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 ;
[0126] 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:
[0127]
[0128]
[0129] in, Indicates the target capsule group D A,n The mth capsule layer in ;
[0130] Since the convolution kernel size of the second convolution capsule layer Equivalent to capsule group C A,n The capsule layer size in , so the output target capsule group D A,n The height and width of the target capsule group D A,n Medium Capsule Among them, d f represents the dimension of the capsule;
[0131] Step S2.3: According to the target capsule group D A,n Get the corresponding sleep period sequence x n The characteristic f′ n :
[0132]
[0133] Among them, concatenate() represents the concatenation function;
[0134] Step S2.4: According to the target capsule group DA,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 :
[0135]
[0136]
[0137] k=m,k∈{1,2,3,4,5}
[0138] 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.
[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; the parent capsule of the convolutional capsule layer can only receive a convolution kernel size that specifies the previous capsule layer. The routing information of the sub-capsule group is as follows:
[0140] First, each input capsule within the specified convolution kernel size undergoes a deep learning transformation matrix W ij Get its prediction vector Transformation Matrix W ij Independent of the capsule position (h, w), its value is parameter-shared across the entire affine given the capsule type. The final output of the convolutional capsule is is the weighted sum of all sub-capsules of different types:
[0141]
[0142] It is the routing coefficient that associates the child capsule located at (h, w) with its corresponding parent capsule. The present invention uses the attention mechanism as the routing algorithm instead of dynamic routing.
[0143] 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:
[0144] 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 :
[0145] G A =concatenate(f′1,f′2,...,f′ n ,...,f′ N )
[0146] Among them, concatenate() represents the concatenation function;
[0147] 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 Represents the current sleep period sequence x n In the sober stage; Represents the current sleep period sequence x n In non-rapid eye movement I stage; Represents the current sleep period sequence x n In non-rapid eye movement II stage; Represents the current sleep period sequence x n In non-rapid eye movement stage III; Represents the current sleep period sequence x n In rapid eye movement sleep;
[0148] Among them, the feature classifier network based on the multi-head attention mechanism is an existing feature classifier, and the topological structure of the feature classifier is as follows: Figure 5 shown.
[0149] 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;
[0150] During training in step S3, the loss function is used to calculate the loss of the sleep staging network model. At the same time, the sleep staging network model is trained by the gradient descent algorithm. The loss calculation is specifically obtained according to the following formula:
[0151]
[0152]
[0153] 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() 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 sleep polygraph signal. In addition, an interpretable analysis method is constructed: the original signal of the test set obtained in step S1 and the signal of the partially masked test set are input into the trained sleep staging network model to obtain the decision basis for the model to classify, such as Figure 2 shown.
[0155] The specific steps of step S4 are as follows: Figure 6 As 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 sleep polygraph signal
[0157] Step S4.2: amplify the sleep sequence in the test set To process:
[0158] First, set the length to k P , the sliding step length is k P / 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;
[0159] 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.
[0160] The specific method for constructing interpretable analysis in step 4 is as follows: corresponding to a trained model, given an input sequence Get the intermediate output {v n,1 ,v n,2 ,v n,3 ,v n,4 ,v n,5}, where v n,k It represents the probability of existence of the k-th type of sleep period feature in the n-th sleep period, represented by a length of k s , sliding step length k s / 2 is the sliding window on the original signal Slide the mask, set the signal in the sliding window to zero, record the mask position as t, and observe the mask signal The corresponding output probability v n,k,t ' and the original signal The corresponding output probability v n,k , for different t, when k = sleep stage results When v n,k -v n,k,t 'Maximum, record and highlight this position t, and use this position as the basis for model classification judgment.
[0161] In a specific implementation case provided in the present invention, a public data set SleepEDFx is used, with a total of 153 EDF sleep records. The SleepEDFx data set uses the Fpz-Cz and Pz-Oz and EOG channels of the EEG channel. The experimental design uses 10-fold cross-validation, and the data is divided into a training set, a validation set, and a test set. The EDF data of 7 people in each fold is used as a validation set to verify whether to stop training, and the test set is used as the final indicator of the test model.
[0162] The model performance provided by the present invention is as follows, including the accuracy ACC, F1 score and macro-f1 (MF1) score of each category;
[0163] The performance of this inventive 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. 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. F1 score (F1 Score) is an indicator used in statistics to measure the accuracy of a binary classification model. It takes into account both the precision and recall of the classification model. Macro-f1 (MF1) calculates the arithmetic mean of the F1 score for each class. This method treats all classes equally without considering the importance of different classes. F1(W) represents the F1 score of the wakeful period, F1(N1) represents the F1 score of the non-rapid eye movement stage I, F1(N2) represents the F1 score of the non-rapid eye movement stage II, F1(N3) represents the F1 score of the non-rapid eye movement stage III, and F1(REM) represents the F1 score of the rapid eye movement period. These indicators are commonly used to measure the performance of sleep staging models.
[0166] It can be concluded that the model proposed by the present invention has reached the current advanced level, and the recognition effect of different types of sleep stages is better than other models. This model accurately recognizes the rapid eye movement stage, which is helpful for diagnosing and evaluating types of sleep disorders, such as rapid eye movement sleep behavior disorder, etc.
[0167] In summary, the above are only preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should 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: 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 sleep polygraph signal.
2. According to claim 1, a sleep staging and interpretability analysis method based on a deep capsule network is characterized by: In step S2, the topological structure of the sleep staging network model is as follows: 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 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; 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 2, characterized in that: The primary capsule layer is mainly 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 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, and 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 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(f1′,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() represents the maximum value function.
7. The sleep staging and interpretability analysis method based on deep capsule network according to claim 1, characterized in that: 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 stage 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.
8. 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.
9. 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 ={x : ,x ; ,…,x n ,…,x F } AND A ={and : ,and ; ,…,and n ,…,and F } 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
End-to-end speaker confirmation method based on double convolutional capsule network
CN114093372A
Single-channel electroencephalogram sleep staging method based on deep learning
CN116186544A
Method for training sleep stage classification model
CN116304882A
Automatic sleep staging method based on window attention mechanism
CN116509421A
Method and system for characterizing microorganism-associated sleep-related conditions
EP3769321A1
