Electroencephalogram sleep staging method, apparatus and device
Patent Information
- Application Number
- CN202611548015.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-08
- Publication Date
- 2026-11-03
AI Technical Summary
Existing EEG sleep staging methods are easily affected by historical information during sleep stage transitions, leading to classification errors and abrupt changes in staging sequences. Furthermore, they are difficult to adapt to the time scale requirements of different sleep stages and cannot meet the real-time requirements of online monitoring scenarios.
By acquiring multi-channel EEG signals and dividing them into continuous EEG staging units, selective propagation and aggregation are performed using causal temporal convolutional networks and boundary-aware contextual features to suppress interference from historical information. Features are extracted using convolutional networks with multiple receptive fields at different times, and attention modulation is performed by combining stage boundary probabilities to form cross-boundary path constraints and avoid reliance on future information.
It improves the accuracy of identifying N1 stage and easily confused sleep stages, reduces staging errors and sequence jumps, adapts to the time scale requirements of different sleep stages, and meets the real-time requirements of online monitoring.
Smart Images

Figure CN123031102A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of sleep monitoring, and in particular to a method, device, and equipment for EEG sleep staging. Background Technology
[0002] Sleep staging is a fundamental technique for sleep quality assessment and sleep structure analysis. According to relevant standards, the sleep signals throughout the night are usually divided into multiple sleep stages of 30 seconds each. Each stage is labeled as the wakefulness stage, non-rapid eye movement (NREM) stage 1 (N1), NREM stage 2 (N2), NREM stage 3 (N3), or rapid eye movement (REM) stage. Traditional manual interpretation is time-consuming and labor-intensive, and the results are easily affected by the experience of the interpreter.
[0003] With the development of deep learning technology, automatic sleep staging methods usually first use convolutional neural networks to extract EEG features of each sleep stage, and then use recurrent neural networks, Transformers or temporal convolutional networks to aggregate contextual information of adjacent stages to improve the continuity of staging results. In terms of multi-scale feature extraction, since sleep spindle waves, K complex waves, slow waves and other EEG signals have different durations and frequency ranges, existing technologies often use multi-scale convolutional structures to extract features at different time scales.
[0004] However, existing methods still have the following technical shortcomings:
[0005] Firstly, when there is a sleep stage transition in the context sequence, the historical information before the boundary may belong to a different stage than the current period. However, existing methods uniformly aggregate the information within the entire context window, causing features from earlier stages to interfere with the current period. This can easily lead to classification errors and stage sequence jumps near the stage transition.
[0006] Secondly, although some existing methods set up stage transition detection auxiliary tasks, the detection results are only used as auxiliary losses in training and do not directly control the propagation of historical features. Other methods use local boundary scores to adjust attention weights, but rely only on endpoint boundary scores and do not accumulate judgments on all adjacent boundaries passed between two periods, making it difficult to fully reflect whether the historical propagation path crosses stage boundaries.
[0007] Thirdly, the duration of different sleep stages varies, with some stages relying on short-term characteristics and others requiring reference to a longer time range. Existing models use fixed receptive fields, which are difficult to adapt to the different time scale requirements of different stages.
[0008] Fourthly, some existing models use a bidirectional network structure, which requires information from subsequent periods to predict the current period, making them unsuitable for online sleep monitoring scenarios.
[0009] Therefore, there is an urgent need in this field for an EEG sleep staging method that can selectively propagate and aggregate historical contexts at different time scales by making full use of stage boundary information without relying on future information, so as to effectively suppress the interference of historical information near stage transitions and improve the identification accuracy of N1 stage and other easily confused sleep stages. Summary of the Invention
[0010] This application provides a method, apparatus, and device for EEG sleep staging, which can guide the selective propagation and aggregation of historical context at different time scales through stage boundary information, suppress historical interference near stage transitions, and improve the identification accuracy of N1 stage and other easily confused sleep stages.
[0011] On one hand, embodiments of this application provide a method for EEG sleep staging, including:
[0012] Acquire continuous EEG signals from multiple channels to be staged, and divide the continuous EEG signals into multiple continuous and non-overlapping EEG staging units based on a preset time length.
[0013] Extract the feature vector of each of the EEG staging units;
[0014] The stage boundary probability between adjacent EEG stage units is determined based on the feature vectors of two adjacent EEG stage units.
[0015] Taking the current EEG staging unit as the endpoint, a preset number of consecutive historical EEG staging units, including the current EEG staging unit, are selected to form a historical window. The feature vectors of each EEG staging unit in the historical window are input in parallel into multiple causal temporal convolutional networks with different temporal receptive fields to obtain multiple historical temporal feature sequences.
[0016] Based on the stage boundary probability, calculate all adjacent stage boundary probabilities crossed between any historical EEG stage unit and the current EEG stage unit within the historical window to obtain the cumulative cross-boundary path constraint. Based on the cumulative cross-boundary path constraint, perform attention weight modulation on the historical temporal features of each causal temporal convolutional network, and perform weighted aggregation on the modulated historical temporal features to obtain the boundary-aware context features corresponding to each causal temporal convolutional network.
[0017] The feature vector of the current EEG stage unit and the boundary perception context feature are aggregated to obtain the final fused feature;
[0018] The sleep staging results are determined based on the final fusion features.
[0019] Furthermore, the extraction of the feature vector for each of the EEG staging units includes:
[0020] The amplitude of the continuous EEG signal of each EEG channel in each EEG stage unit is calibrated to obtain the calibrated continuous EEG signal. The amplitude calibration is performed by linearly transforming the continuous EEG signal by setting independent learnable scaling coefficients and bias parameters for each EEG channel.
[0021] After calibration, the continuous EEG signal of each EEG staging unit is subjected to multi-scale convolution to obtain multi-scale temporal features. The temporal features of the multi-scale temporal features are then spliced along the feature channel dimension and then subjected to scale integration convolution to obtain scale features of a preset dimension.
[0022] Perform cross-channel spatial convolution on the scale features of the preset dimensions to obtain collaborative activity features of multiple channels;
[0023] Channel recalibration is performed on the aforementioned collaborative activity features;
[0024] The co-activity features after channel recalibration are encoded using single-period temporal context encoding and aggregated along the time dimension to obtain the feature vector of each EEG stage unit.
[0025] Furthermore, determining the stage boundary probability between adjacent EEG staging units based on the feature vectors of two adjacent EEG staging units includes:
[0026] Calculate the element-wise absolute difference between the feature vectors of two adjacent EEG staging units;
[0027] Boundary input features are constructed based on the feature vectors of two adjacent EEG staging units and their corresponding element-wise absolute differences.
[0028] The boundary input features are input into the boundary prediction network to obtain the boundary prediction value and the stage boundary probability.
[0029] The boundary prediction network comprises a first fully connected layer, an activation function layer, a random deactivation layer, and a second fully connected layer connected in sequence. The first fully connected layer is used to map the boundary input features to intermediate features of a preset dimension. The activation function layer uses a non-linear activation function to activate the intermediate features. The random deactivation layer is used to randomly discard the activated features. The second fully connected layer is used to map the features output by the random deactivation layer to the boundary prediction value.
[0030] Furthermore, each of the aforementioned causal temporal convolutional networks includes at least two causal convolutional layers, wherein each causal convolutional layer employs a different dilation rate;
[0031] Each causal convolutional layer is followed by activation processing, random deactivation processing, residual connection processing, and normalization processing in sequence.
[0032] Furthermore, the step of calculating the probability of all adjacent stage boundaries crossed between any historical EEG staging unit and the current EEG staging unit within the historical window based on the stage boundary probability includes:
[0033] For each historical EEG staging unit within the historical window, obtain the stage boundary probability of each adjacent boundary position between the historical EEG staging unit and the current EEG staging unit;
[0034] Calculate the unbounded continuity probability for each adjacent boundary position, where the unbounded continuity probability is 1 minus the stage boundary probability of the corresponding boundary position.
[0035] Multiply the unbounded continuous probabilities of all adjacent boundary positions to obtain the path constraint value corresponding to the historical EEG staging unit.
[0036] Furthermore, the step of modulating attention weights on the historical temporal features of each of the causal temporal convolutional networks based on the accumulated cross-boundary path constraints, and then weighting and aggregating the modulated historical temporal features, includes:
[0037] For each of the causal temporal convolutional networks, calculate the basic attention score of the feature vector of each historical EEG staging unit within the historical window;
[0038] The basic attention score of each historical EEG stage unit is fused with the corresponding cumulative cross-boundary path constraint to obtain the boundary perception attention score of the historical EEG stage unit.
[0039] The boundary perception attention score of each historical EEG stage unit is normalized to obtain the boundary perception attention weight of each historical EEG stage unit.
[0040] Based on the boundary-aware attention weights, the historical temporal features of each historical EEG staging unit in the corresponding causal temporal convolutional network are weighted and summed to obtain the boundary-aware context features of the corresponding causal temporal convolutional network.
[0041] Furthermore, the aggregation of the feature vector of the current EEG staging unit and the boundary-aware context features includes:
[0042] Project the feature vector of the current EEG stage unit onto a preset dimension to obtain the current projected features;
[0043] The current projection features and the boundary-aware context features of each causal temporal convolutional network are concatenated to obtain the concatenated features;
[0044] The spliced features are input into a scale-gated network to obtain the scale fusion weights corresponding to each causal temporal convolutional network.
[0045] Based on the scale fusion weights, the features of each boundary-aware context are weighted and summed to obtain the multi-scale historical context.
[0046] Based on the current projection features and the multi-scale historical context, a threshold is introduced by calculating the historical information of each feature channel;
[0047] Based on the historical information, a threshold is introduced to perform feature-channel weighting on the multi-scale historical context to obtain the gated historical context. The gated historical context and the current projected features are then residually fused and normalized at the execution layer to obtain the final fused features.
[0048] The scale-gated network includes an input layer, an intermediate layer, and an output layer connected in sequence. The input layer is used to perform dimensionality transformation on the spliced features. The intermediate layer includes a fully connected layer, an activation layer, and a random deactivation layer arranged in sequence. The output dimension of the output layer is the same as the number of layers in the causal temporal convolutional network.
[0049] Furthermore, determining the sleep staging result based on the final fusion features includes:
[0050] The final fused features are input into a classification network to obtain the classification probability of the current EEG stage unit belonging to each preset sleep stage category. The classification network includes a fully connected layer, and the preset sleep stage categories include wakefulness, non-rapid eye movement (NREM) stage 1, NREM stage 2, NREM stage 3, and rapid eye movement (REM) stage.
[0051] The sleep stage category corresponding to the highest classification probability is taken as the sleep staging result of the current EEG staging unit;
[0052] Based on the temporal order of EEG staging units, the sleep staging results of all EEG staging units are combined into an overnight sleep staging sequence.
[0053] On the other hand, embodiments of this application provide an EEG sleep staging device, the device comprising:
[0054] The acquisition module is used to acquire continuous EEG signals from multiple channels to be staged, and to divide the continuous EEG signals into multiple continuous and non-overlapping EEG staging units based on a preset time length.
[0055] The extraction module is used to extract the feature vector of each of the EEG staging units;
[0056] The first determining module is used to determine the stage boundary probability between adjacent EEG stage units based on the feature vectors of two adjacent EEG stage units.
[0057] The selection module is used to select a preset number of consecutive historical EEG staging units, including the current EEG staging unit, as the endpoint to form a historical window. The feature vector of each EEG staging unit in the historical window is input in parallel into multiple causal temporal convolutional networks with different temporal receptive fields to obtain multiple historical temporal feature sequences.
[0058] The calculation module is used to calculate the probability of all adjacent stage boundaries crossed between any historical EEG stage unit and the current EEG stage unit within the historical window based on the stage boundary probability, to obtain the cumulative cross-boundary path constraint, to modulate the attention weight of the historical temporal features of each causal temporal convolutional network based on the cumulative cross-boundary path constraint, and to perform weighted aggregation on the modulated historical temporal features to obtain the boundary-aware context features corresponding to each causal temporal convolutional network.
[0059] The aggregation module is used to aggregate the feature vector of the current EEG staging unit and the boundary perception context features to obtain the final fused features;
[0060] The second determining module is used to determine the sleep staging result based on the final fusion features.
[0061] In another aspect, embodiments of this application provide an electronic device, the device comprising: a processor and a memory storing computer program instructions;
[0062] When the processor executes the computer program instructions, it implements an EEG sleep staging method as described in any one of the first aspects.
[0063] This application discloses an EEG sleep staging method, apparatus, and device. It calculates the stage boundary probabilities of adjacent EEG staging units and accumulates all adjacent stage boundary probabilities crossed between any historical EEG staging unit and the current EEG staging unit within a historical window, forming cross-boundary path constraints. This overcomes the shortcomings of existing methods that rely solely on endpoint boundary scores and cannot comprehensively determine path crossings. Based on the accumulated constraints, attention weights are modulated on the historical features output by a multi-path causal temporal convolutional network. This effectively suppresses the weights of historical information before the transition boundary when a stage transition occurs, avoiding interference from earlier stage features on the current stage and reducing staging errors and sequence jumps near stage transitions. Multiple causal temporal convolutional networks with different temporal receptive fields are used in parallel to extract historical features. This adapts to the differentiated time scale requirements of signals with different durations, such as sleep spindle waves and slow waves, while avoiding reliance on future information, meeting the real-time requirements of online monitoring scenarios. The current unit features are fused with the modulated and aggregated boundary-aware context features to obtain a clear feature representation, thereby improving the identification accuracy of N1 stage and easily confused sleep stages. Attached Figure Description
[0064] Figure 1 This is a flowchart illustrating a brainwave sleep staging method in an embodiment of this application;
[0065] Figure 2 This is a structural block diagram illustrating a brainwave sleep staging device in the embodiments of this application;
[0066] Figure 3 This is a structural block diagram illustrating an electronic device in the embodiments of this application. Detailed Implementation
[0067] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.
[0068] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element.
[0069] Traditional sleep staging methods rely on manual interpretation, which is time-consuming and susceptible to the experience of the interpreters. Existing automatic staging methods aggregate contextual information uniformly when handling sleep stage transitions, leading to historical information interfering with the current stage and easily causing classification errors and abrupt changes in the staging sequence. While some methods attempt boundary detection, they fail to effectively control the propagation of historical features and are insufficient in accumulating all adjacent boundaries between two stages. Furthermore, existing models use fixed receptive fields, making it difficult to adapt to the different time scale requirements of different sleep stages, and bidirectional network structures are not suitable for online sleep monitoring scenarios.
[0070] To address the problems of the prior art, embodiments of this application provide a method, apparatus, and device for EEG sleep staging. The EEG sleep staging method provided in this application embodiment is described below.
[0071] Figure 1 A flowchart illustrating an EEG sleep staging method according to an embodiment of this application is shown. Figure 1 As shown in the figure, the EEG sleep staging method provided in this application includes the following steps:
[0072] S101. Acquire continuous EEG signals from multiple channels to be staged, and divide the continuous EEG signals into multiple continuous and non-overlapping EEG staging units based on a preset time length.
[0073] In this embodiment, continuous EEG signals can be acquired in real time by an EEG acquisition device or obtained from pre-saved overnight EEG recordings. The acquired continuous EEG signals are bandpass filtered to reduce the impact of baseline drift and high-frequency noise. The bandpass filter uses a 0.3-40Hz bandpass filter and the sampling frequency is 100Hz. In this embodiment, two channels of continuous EEG signals are used, i.e., two EEG leads are selected, for example, the frontal midline-central midline lead and the parietal midline-occipital midline lead. In addition, depending on the acquisition device and application scenario, a single lead or three or more leads can also be used.
[0074] In this embodiment, an automated program or timer is used to periodically extract the filtered continuous EEG signal, thereby obtaining multiple continuous and non-overlapping EEG staging units. The preset time length is 30 seconds, and each lead contains 3000 sampling points. The t-th EEG staging unit is represented as:
[0075]
[0076] Where C represents the number of EEG channels, S represents the number of sampling points in each EEG staging unit, and t represents the time index of the EEG staging unit. Let R be the EEG matrix of the t-th EEG stage unit, where R is the real number field.
[0077] In this embodiment, in order to reduce the category distribution shift caused by excessively long periods of wakefulness before and after the recording of the whole night, a preset period of wakefulness can be retained before the first occurrence of the non-wakefulness stage and after the last occurrence of the non-wakefulness stage, for example, the preset duration is 30 minutes.
[0078] S102. Extract the feature vector of each EEG stage unit.
[0079] Specifically, amplitude calibration is performed on the continuous EEG signals of each EEG channel in each EEG staging unit to obtain calibrated continuous EEG signals. Amplitude calibration involves linearly transforming the continuous EEG signals by setting independent learnable scaling coefficients and bias parameters for each EEG channel. Multi-scale convolution is performed on the calibrated continuous EEG signals of each EEG staging unit to obtain multi-scale temporal features. The temporal features of the multi-scale temporal features are then concatenated along the feature channel dimension and then scale-integrated convolution to obtain scale features of a preset dimension. Cross-channel spatial convolution is performed on the scale features of the preset dimension to obtain collaborative activity features of multiple channels. Channel recalibration is performed on the collaborative activity features. Single-period temporal context encoding is performed on the channel-recalibrated collaborative activity features and aggregated along the time dimension to obtain the feature vector of each EEG staging unit.
[0080] Specifically, the learnable amplitude calibration for the c-th EEG channel is as follows:
[0081]
[0082] in, and Let $\mathbf{c}$ be the learnable scaling factor and the bias corresponding to the $c$-th EEG channel, where $c \in {1, ..., C} is the EEG channel index. To calibrate the pre-electroencephalogram (EEG) signals, To calibrate the EEG signal, the learnable scaling factor and bias are both learnable parameters used to adaptively compensate for the distribution shift caused by individual differences among different subjects and differences in signal amplitude characteristics of different acquisition devices. In addition to linear transformation, amplitude calibration can also be achieved by Z-score standardization of the signal of each EEG channel, that is, subtracting the mean and dividing by the standard deviation or minimum-maximum normalization.
[0083] In this embodiment, multi-scale convolution is used to capture physiological events at different time scales in EEG signals, such as sharp waves, K-complexes, sleep spindles, and slow waves. Multi-scale convolution includes four scale branches. Each scale branch first undergoes average pooling along the time axis at the corresponding scaling factor, and then extracts temporal features using a one-dimensional convolution kernel of length 15. Subsequently, complementary max pooling matching the corresponding downsampling scaling factor is applied to unify the feature sequences output by the four scale branches to the same time length. In this embodiment, the average pooling scaling factors for the four scale branches are 1, 2, 4, and 8, respectively, and the complementary max pooling factors are 8, 4, 2, and 1, respectively. Finally, each branch output contains 375 time positions, resulting in multi-scale temporal features.
[0084] The multi-scale temporal features of the four scale branches are concatenated along the feature mapping dimension, and then scale integration convolution with a kernel length of 5 and a stride of 5 is performed to form 32 output channels. The scale integration result is input into a cross-channel spatial convolutional layer covering all EEG channels. This cross-channel spatial convolutional layer performs convolution operations along the EEG electrode lead dimension to extract the collaborative activity features between leads in the whole brain region. The spatial convolution outputs 64 spatial feature channels. In this embodiment, the cross-channel spatial convolution can adopt depthwise separable convolution. When depthwise separable convolution is adopted, it is achieved by C×1 depthwise spatial convolution and 1×1 pointwise convolution.
[0085] It should be noted that scale integration convolution operates on the feature sequence output by multi-scale branches, rather than directly sampling points from the original EEG signal. Its convolution kernel length and stride are both 5, and every 5 adjacent features are aggregated into 1, reducing the time length from 375 to 75. Subsequently, spatial convolution with a kernel size of C×1 is used to cover all C EEG leads to extract translead features.
[0086] In this embodiment, channel recalibration employs an identity-preserving Residual ECA module. This module is set after the cross-channel spatial convolution, and the output of the cross-channel spatial convolution is set as follows: ∈R (D×M) Where D is the number of spatial feature channels and M is the number of temporal positions, the global descriptor of the j-th channel is calculated first along the time dimension:
[0087]
[0088] Where j∈{1,…,D} is the spatial feature channel index, and m∈{1,…,M} is the temporal location index. This represents the feature value of the t-th EEG stage unit at the j-th spatial feature channel and the m-th temporal position. Indicates the first Each spatial feature channel in all The average value at each time position is the global descriptive value of the j-th spatial feature channel of the EEG staging unit. The time position is not the EEG staging unit. t represents the EEG staging unit index, and m represents the time position index of the convolutional feature sequence within the t-th EEG staging unit. In this embodiment, M=75.
[0089] In other alternative implementations, the identity-preserving Residual ECA module can be replaced with other channel attention or feature recalibration structures with identity initialization capabilities. Joint training can employ cross-entropy, focus loss, or other class imbalance losses, and the weights of stage classification loss and boundary prediction loss can be adjusted.
[0090] In this embodiment, the global descriptor is input into a one-dimensional convolution along the channel dimension, and the channel weights are generated using the Sigmoid function:
[0091]
[0092] in, For global description, and The relationship between the whole and its components: Indicates the first The complete channel global description vector of each EEG staging unit For the first scalar component For a convolution kernel length of One-dimensional convolution of channels, where σ is the Sigmoid function. For the channel weights of the t-th EEG staging unit, in this embodiment, the channel convolution kernel length is... It is 3, and no bias is set.
[0093] In this embodiment, the collaborative activity features are recalibrated using channel weights, and the channel convolution kernel weights are initialized to zero:
[0094]
[0095] in, The recalibrated spatial convolution features are, where, Indicates the first The complete channel weight vector of each EEG staging unit For the first The weights of each channel, |init is the value taken at initialization. Since 2σ(0)=1 at initialization, the Residual ECA module is equivalent to the identity mapping at the beginning of training, without destroying the original spatial convolution features. As training progresses, it learns the importance of different spatial feature channels.
[0096] In this embodiment, the recalibrated collaborative activity features are input into the single-period time context encoding module:
[0097]
[0098] in, Indicates the first The complete spatial feature matrix of each EEG staging unit after channel recalibration This is a period-specific feature dimension. In this embodiment, , , The 64-dimensional spatial features after channel recalibration are mapped to a 32-dimensional embedding through a feature projection layer, along... After aggregating the time positions, we get TCM stands for Single-Period Time Context Module, and Mean stands for Along-Period Time Context Module. Calculate the average at each time point. Indicates the first EEG staging unit 3D eigenvectors.
[0099] In this embodiment, single-period temporal context encoding employs a single-period temporal context module, which includes a feature projection layer, a position encoding layer, and an attention encoder. The feature projection layer projects the channel-recalibrated features onto a preset feature dimension to obtain a projected feature sequence. In this embodiment, the channel-recalibrated features are 64-dimensional spatial features, mapped to a 32-dimensional embedding by the feature projection layer. The position encoding layer superimposes position encoding onto the projected feature sequence to obtain an encoded enhanced feature sequence. In this embodiment, both the projected feature matrix and the position encoding matrix have an M×F shape. They are directly added element-wise according to the same time position and feature dimension, and then input into the attention encoder. The attention encoder performs multi-head attention encoding on the encoded enhanced feature sequence and outputs the encoded feature sequence. In this embodiment, the attention encoder employs a two-layer multi-head self-attention encoding structure, with each layer including four attention heads, used to extract the relationships between different time positions within a single 30-second EEG staging unit.
[0100] In this embodiment, amplitude calibration eliminates the dimensional differences between EEG channels. The combination of multi-scale convolution and scale integration convolution ensures comprehensive capture of physiological waveforms of different frequencies and durations, such as sleep spindles and slow waves, overcoming the limitation that a single scale cannot cover complex physiological patterns. Cross-channel spatial convolution mines the spatial correlation between EEG channels, enhancing the ability to perceive the distribution patterns of brain activity to a certain extent. Channel recalibration optimizes feature representation by adaptively weighting each feature channel, thereby focusing on the information that contributes most to sleep staging. Single-stage temporal context encoding and aggregation integrate these rich local physiological information into high-quality, high-discriminative feature vectors, thereby more accurately representing the complex physiological patterns of different sleep stages and improving the accuracy and reliability of the entire sleep staging method.
[0101] S103. Determine the stage boundary probability between adjacent EEG stage units based on the feature vectors of two adjacent EEG stage units.
[0102] Specifically, the element-wise absolute difference between the feature vectors of two adjacent EEG staging units is calculated; boundary input features are constructed based on the feature vectors of two adjacent EEG staging units and their corresponding element-wise absolute differences; the boundary input features are input into the boundary prediction network to obtain the boundary prediction value and the stage boundary probability; wherein, the boundary prediction network includes a first fully connected layer, an activation function layer, a random deactivation layer and a second fully connected layer connected in sequence. The first fully connected layer is used to map the boundary input features to intermediate features of a preset dimension. The activation function layer uses a non-linear activation function to activate the intermediate features. The random deactivation layer is used to randomly discard the activated features. The second fully connected layer is used to map the features output by the random deactivation layer to the boundary prediction value.
[0103] In this embodiment, the element-by-element absolute difference is obtained by calculating the absolute difference between the corresponding elements of the feature vector of the current EEG staging unit and the feature vector of the previous EEG staging unit.
[0104] For adjacent EEG staging units k and k+1, the boundary input features are:
[0105]
[0106] Where k is the index of adjacent EEG staging units, the semicolon indicates vector concatenation, and the absolute value symbol indicates taking the absolute value of each element. Input features for 3F-dimensional boundaries Let k be the element-wise absolute difference between k and k+1.
[0107] In other alternative embodiments, boundary features can also be constructed based on feature splicing, absolute difference, feature product, distance, or similarity of adjacent phase units.
[0108] Input the boundary input features into the boundary prediction network to obtain the boundary prediction value and the stage boundary probability:
[0109]
[0110] in, For boundary prediction networks, For boundary prediction values, This represents the stage boundary probability;
[0111] In this embodiment, the boundary input feature is formed by concatenating three F-dimensional vectors, so its dimension is 3F, F=32, hence 3F=96. The boundary prediction network includes a fully connected layer with an output dimension of 32, a GELU activation layer, a random deactivation layer, and a fully connected layer with an output dimension of 1, which are connected in sequence. The fully connected layer with a dimension of 1 outputs the boundary prediction value of the EEG staging unit. The random deactivation layer can be set with a random deactivation rate, such as 0.2 or 0.5, which represents the probability that each neuron is randomly discarded. In other optional embodiments, the boundary prediction network can also use a multilayer perceptron, a one-dimensional convolutional network, or an attention network, as long as it can output the continuous stage boundary probability between adjacent staging units.
[0112] When training the boundary prediction network, the boundary label for adjacent EEG staging units with different actual sleep stages is 1, and with the same stage is 0.
[0113]
[0114] in, and These are the actual sleep stage labels for adjacent EEG staging units. As a corresponding boundary label, the first target position of each data block does not participate in the boundary loss calculation because there is no available previous valid period. The stage boundary probability not only serves as an auxiliary output for stage transition, but also directly participates in the subsequent historical context weight calculation, so that the stage boundary prediction and the sleep staging task form a joint optimization relationship.
[0115] In this embodiment, the element-wise absolute difference of the feature vector is calculated to capture the degree of change of adjacent EEG staging units in the feature space. Based on the feature vectors of two adjacent EEG staging units and the corresponding element-wise absolute difference, the boundary input features are constructed, so that the boundary prediction network can simultaneously utilize the feature expression of the EEG staging unit itself and the differences between adjacent units, thereby more comprehensively representing the boundary state.
[0116] S104. Taking the current EEG stage unit as the endpoint, select a preset number of consecutive historical EEG stage units, including the current EEG stage unit, to form a historical window. Input the feature vector of each EEG stage unit in the historical window into multiple causal temporal convolutional networks with different temporal receptive fields in parallel to obtain multiple historical temporal feature sequences.
[0117] In this embodiment, the history window is:
[0118]
[0119] in, This represents the historical window feature matrix up to the current EEG stage t, where F is the feature dimension of a single period. Let L be the feature vector of the t-th EEG stage unit, and L be the preset number. In this embodiment, L=15, which corresponds to 7.5 minutes of EEG information including the current and previous data. When the starting position of the record is less than 15 EEG stage units, the first period of the record is used to fill the left to keep the input length consistent.
[0120] The historical window is input in parallel into multiple causal temporal convolutional networks. The output of the s-th causal temporal convolutional network is:
[0121]
[0122] Where s∈{1,2,4} denotes a causal temporal convolutional network identified by its basic dilation rate. It is a causal temporal convolutional network. ∈R (L×64) This is the historical temporal feature sequence output by the causal temporal convolutional network.
[0123] Each causal temporal convolutional network includes at least two causal convolutional layers, each with a different dilation rate; and each causal convolutional layer is followed by activation processing, random deactivation processing, residual connection processing, and normalization processing in sequence.
[0124] In this embodiment, three causal temporal convolutional networks are set up with base dilation rates of 1, 2 and 4, respectively. Each causal temporal convolutional network includes two causal convolutional layers with a dilation rate of ds for the first layer and 2ds for the second layer. The kernel length is 3 and the hidden feature dimension is 64. The causal convolution only pads the left side of the input sequence with zeros, so that the output at position i is calculated only by position i and the positions before it.
[0125] In other alternative embodiments, the causal temporal convolutional network can also employ causal TCNs with different dilation rates, or it can employ unidirectional recurrent neural networks, GRU, LSTM, causal Transformer, or state-space models; different temporal receptive fields can be formed through branching structures, hierarchical structures, or historical windows of different lengths, but none of them use EEG information after the current period.
[0126] After each causal convolutional layer, perform GELU activation, random deactivation, residual connections, and layer normalization:
[0127]
[0128] Here, R represents the residual mapping. When the dimensions of the input and output features are the same, R uses the identity mapping; when the dimensions of the input and output features are different, R uses linear projection. l∈{1,2} is the index of the causal convolutional layer. Let CConv represent the dilation rate of the l-th layer of the s-th causal temporal convolutional network, where CConv represents causal convolution, and LN, Dropout, and GELU represent layer normalization, random deactivation, and GELU activation, respectively. The output of the corresponding causal convolutional layer represents the historical temporal feature sequence. The dilation rate combinations of the three causal temporal convolutional networks are (1, 2), (2, 4) and (4, 8), respectively, thereby simultaneously obtaining information on changes in adjacent stages, medium duration dependence and long-term sleep states.
[0129] In this embodiment, the causal convolutional layer pads zeros only in the historical direction to ensure temporal causality and avoid interference from future information on the current EEG stage. The activation processing, random deactivation processing, residual connection processing, and normalization processing performed after each causal convolutional layer jointly optimize the training process of the deep network, thereby effectively suppressing the interference of historical information near the stage transition and improving the sensitivity to sleep stage transitions.
[0130] S105. Calculate the probability of all adjacent stage boundaries crossed between any historical EEG stage unit and the current EEG stage unit within the historical window based on the stage boundary probability, obtain the cumulative cross-boundary path constraint, modulate the attention weight of the historical temporal features of each causal temporal convolutional network based on the cumulative cross-boundary path constraint, and perform weighted aggregation on the modulated historical temporal features to obtain the boundary-aware context features corresponding to each causal temporal convolutional network.
[0131] The calculation of all adjacent stage boundary probabilities between any historical EEG staging unit and the current EEG staging unit within the historical window, based on stage boundary probabilities, includes: for each historical EEG staging unit within the historical window, obtaining the stage boundary probabilities of each adjacent boundary position between the historical EEG staging unit and the current EEG staging unit; calculating the unbounded continuity probability of each adjacent boundary position, where the unbounded continuity probability is 1 minus the stage boundary probability of the corresponding boundary position; and multiplying the unbounded continuity probabilities of all adjacent boundary positions together to obtain the path constraint value corresponding to the historical EEG staging unit.
[0132] In this embodiment, all adjacent EEG staging units within the historical window are predicted to obtain the stage boundary probabilities between them. Based on the relative positions of the historical EEG staging units and the current EEG staging units within the historical window, the probabilities of all adjacent stage boundaries on the path between them are determined.
[0133] The probability of unbounded continuity is obtained by subtracting the stage boundary probability of the corresponding boundary position from the value 1. For example, if the stage boundary probability of a certain boundary is 0.8, then its probability of unbounded continuity is 0.2.
[0134] In this embodiment, the unbounded continuous probability from the historical EEG staging unit to the current EEG staging unit is:
[0135]
[0136] Where i represents the historical EEG staging unit, t represents the current EEG staging unit, and k represents the adjacent boundary index. It represents the unbounded continuous probability between the historical EEG staging unit and the current EEG staging unit.
[0137] To improve numerical stability, the unbounded continuous probability is converted into a cumulative logarithm form:
[0138]
[0139] in, To accumulate the natural logarithm, ln represents the natural logarithm.
[0140] In this embodiment, the path constraint value is obtained by calculating and multiplying the unbounded continuous probabilities of all adjacent boundaries on the historical path. For example, the larger the path constraint value, the less likely the path is to cross the boundary. The influence of any high-probability boundary is amplified by the path constraint value, so that the weight of historical information near the boundary is automatically attenuated, thereby differentiating the evaluation of historical information in feature aggregation.
[0141] In other alternative embodiments, the cumulative cross-boundary path constraint can also be calculated using the cumulative logarithm of the boundaryless probability of each boundary, a weighted summation, or a learnable aggregation function, and can also be used as an attention bias, historical feature weight, or gating control quantity.
[0142] Specifically, attention weights are modulated on the historical temporal features of each causal temporal convolutional network based on cumulative cross-boundary path constraints, and the modulated historical temporal features are then weighted and aggregated. This includes: for each causal temporal convolutional network, calculating the basic attention score of the feature vector of each historical EEG staging unit within the historical window; fusing the basic attention score of each historical EEG staging unit with the corresponding cumulative cross-boundary path constraints to obtain the boundary-aware attention score of the historical EEG staging unit; normalizing the boundary-aware attention score of each historical EEG staging unit to obtain the boundary-aware attention weight of each historical EEG staging unit; and weighting and summing the historical temporal features of each historical EEG staging unit in the corresponding causal temporal convolutional network based on the boundary-aware attention weight to obtain the boundary-aware context features of the corresponding causal temporal convolutional network.
[0143] In this embodiment, a separate attention mechanism, such as a fully connected layer or a small neural network, is used to map the feature vector of the historical EEG staging unit to a scalar score; or a dot product attention mechanism is used to perform a dot product between the feature vector of the historical EEG staging unit and a learnable query vector, and then pass it through a nonlinear activation function, such as Softmax, to obtain the result.
[0144] The current EEG staging unit does not cross any boundaries, therefore r(t→t)=0. For the s-th causal temporal convolutional network, the basic attention score is calculated based on the temporal features of the ith position:
[0145]
[0146] in, For the s-th causal temporal convolutional network, the historical temporal features of historical EEG staging unit i are given. Based on attention score, , , and Here, tanh is a learnable parameter, t is the hyperbolic tangent function, and T denotes the transpose. Indicates the first in the history window The first EEG staging unit, the... The position refers to the first Each historical EEG staging unit is distinct from the temporal location within a single EEG staging unit. , This is an index for causal temporal convolutional networks.
[0147] In this embodiment, the fusion method can be varied. For example, multiplicative fusion can be used, which multiplies the basic attention score by the cumulative cross-boundary path constraint element by element; or additive fusion can be used, which adds the two element by element; or a gated fusion mechanism can be used, which learns how to dynamically combine the two through a small fully connected network, thereby generating a more discriminative boundary-aware attention score.
[0148] In this embodiment, the accumulated boundary constraints are added to the basic attention score to obtain the boundary-aware attention weights:
[0149]
[0150] in, Here, j represents the boundary-aware attention weight, j is the Softmax normalized summation index, λ is the learnable boundary strength constrained to be non-negative by the Softplus function, and L is the historical range of the current attention calculation.
[0151] The contextual features of the s-th causal temporal convolutional network are:
[0152]
[0153] in, For the boundary-aware context features of the s-th causal temporal convolutional network, (s) is used to indicate the index of the causal temporal convolutional network. In this embodiment, continuous suppression is used instead of hard zeroing upon boundary detection. As the value approaches 1, the Softmax weights for cross-boundary historical positions approach 0, only when... The theoretical limit of 1 is 0.
[0154] In this embodiment, when there is a high-probability stage boundary between the historical EEG staging unit and the current EEG staging unit, the (1- in the path) As the cumulative logarithm decreases, the attention weight of historical periods before the boundary decreases. The further back the historical EEG stage unit is and the more high-probability boundaries it crosses, the stronger the inhibition it receives. Since the stage boundary probability is not binarized, it is possible to make continuous adjustments between clear boundaries and fuzzy transitions.
[0155] S106. Aggregate the feature vector of the current EEG stage unit and the boundary perception context feature to obtain the final fused feature.
[0156] Specifically, the feature vector of the current EEG staging unit is projected onto a preset dimension to obtain the current projected feature; the current projected feature and the boundary-aware context feature of each causal temporal convolutional network are concatenated to obtain the concatenated feature; the concatenated feature is input into a scale-gated network to obtain the scale fusion weights corresponding to each causal temporal convolutional network; the boundary-aware context features are weighted and summed based on the scale fusion weights to obtain the multi-scale historical context; the historical information introduction threshold for each feature channel is calculated based on the current projected feature and the multi-scale historical context; the multi-scale historical context is weighted for each feature channel based on the historical information introduction threshold to obtain the gated historical context; and the gated historical context and the current projected feature are residually fused and then normalized by the execution layer to obtain the final fused feature; wherein, the scale-gated network includes an input layer, an intermediate layer and an output layer connected in sequence. The input layer is used to transform the dimension of the concatenated feature, the intermediate layer includes a fully connected layer, an activation layer and a random deactivation layer set in sequence, and the output dimension of the output layer is the same as the number of causal temporal convolutional networks.
[0157] In this embodiment, the projection operation can be implemented through a fully connected layer or linear transformation layer. This fully connected layer multiplies the input feature vector with a learnable weight matrix and adds a bias term, thereby mapping it to a preset output dimension. The concatenation can be performed on the feature channel dimension. For example, if the current projected feature dimension is D1 and each context feature dimension is D2, then the concatenated feature dimension is D1+N*D2, where N is the number of causal temporal convolutional networks.
[0158] In this embodiment, the feature vector of the current EEG staging unit is projected onto a 64-dimensional space to obtain the current projected features. These current projected features are then concatenated with the three scale contexts and input into a scale-gated network. Finally, a weighted summation of the contexts at each scale is performed.
[0159]
[0160] in, This represents the periodic projection characteristics of the current EEG staging unit. and Here are the projection parameters and the learnable parameters. This is a brainwave staging unit. For scale-gated networks, ∈R 3 This is a weight vector with three scales. For the s-th scale weight, For multi-scale historical context after multi-scale weighted fusion, represents the boundary-aware context features of the s-th causal temporal convolutional network.
[0161] In this embodiment, the current projection features and the three scale contexts are all 64-dimensional, and the dimensions after the four are stitched together are 4×64=256. The scale-gated network includes a 256-32 dimension fully connected layer, a GELU activation layer, a random deactivation layer, and a 32-3 dimension fully connected layer. The weights and biases of the last layer are initialized with zero values so that the three scales have the same weights at the beginning of training.
[0162] In other alternative embodiments, the scale-gated network may also employ Softmax gating, Sigmoid gating, attention-weighted gating, or a hybrid expert structure.
[0163] The historical information introductory threshold can be calculated using a small gating unit, for example, through a network comprising fully connected layers and a sigmoid activation function. Its input is a concatenation or some form of interaction between the current projected features and the multi-scale historical context, such as element-wise multiplication or addition. The output dimension is the same as the feature channel dimension of the multi-scale historical context. Alternatively, it can be based on a self-attention mechanism module. This module uses the current projected features as the query and the multi-scale historical context as the key and value. It generates the weights for each feature channel by calculating attention scores, and then passes these weights through a sigmoid activation function to obtain the historical information introductory threshold.
[0164] In this embodiment, the amount of historical information introduced per channel is calculated based on the characteristics of the current period and the multi-scale historical context, while retaining the direct residual path of the current period:
[0165]
[0166] in, ∈(0,1) 64 To introduce historical information for each channel. and Here are the gating parameters, which are learnable parameters. A semicolon indicates vector concatenation, ⊙ indicates element-wise multiplication, Dropout is random deactivation, and LN is layer normalization. This is the final fusion feature.
[0167] In this embodiment, residual fusion can be achieved by adding the gated historical context to the current projected features element by element. Layer normalization is a standardization process performed on the fused features after residual fusion to stabilize the training process and accelerate convergence. Layer normalization performs independent normalization on each feature of each sample so that its mean is 0 and its variance is 1.
[0168] The weights of the historical information introduction gates are initialized with zero values, and the bias is preferably set to -1, so that the gate values of each channel are approximately 0.269 during initialization. The model prioritizes retaining the features of the current period, and then learns the proportion of historical information allowed to be introduced in each feature dimension based on the training data, thereby reducing the coverage of current period features by unreliable historical information and the continuous propagation of errors along the time direction.
[0169] In this embodiment, the current feature is projected onto a unified dimension and concatenated with the boundary-aware context feature to form a concatenated feature containing interactive information. Then, a scale-gated network adaptively allocates fusion weights to different receptive field branches to solve the problem of differences in contributions from various causal temporal convolutional networks. Historical information is calculated channel by channel to introduce a threshold to filter the aggregated multi-scale context, retaining only historical information with high relevance and strong discriminative power. The gated historical context is fused with the residual of the current projected feature and normalized layer by layer. While retaining the current feature, the multi-scale historical information is balanced, thereby enhancing the stability of the fused feature and improving the recognition accuracy of easily confused stages such as the N1 stage to a certain extent.
[0170] S107. Determine sleep staging results based on final fusion features.
[0171] Specifically, the final fused features are input into a classification network to obtain the classification probability of the current EEG staging unit belonging to each preset sleep stage category. The classification network includes fully connected layers, and the preset sleep stage categories include wakefulness, non-rapid eye movement (NREM) stage 1, NREM stage 2, NREM stage 3, and rapid eye movement (REM) stage. The sleep stage category corresponding to the highest classification probability is taken as the sleep staging result of the current EEG staging unit. Based on the temporal order of the EEG staging units, the sleep staging results of all EEG staging units are combined into a whole-night sleep staging sequence.
[0172] In this embodiment, the classification network is a five-class fully connected layer. The final fused features are input into the classification network, and the Softmax function is used to obtain the probability that the current EEG staging unit belongs to the awake stage (W), non-rapid eye movement (NREM) stage 1 (N1), NREM stage 2 (N2), NREM stage 3 (N3), and rapid eye movement (REM) stage. The category with the highest probability is taken as the current sleep staging result.
[0173]
[0174] in, ∈R K The raw scores for classification into K categories, where K=5, corresponding to the five categories: W, N1, N2, N3, and REM. and The weights and biases of the five-class fully connected layer are the learning parameters. This represents the probability that the current EEG stage unit belongs to class c. The original score c belongs to category c, where c represents the sleep stage category index. For the predicted category.
[0175] Among them, the whole night sleep stage sequence is a complete sequence of the classification results of all EEG stage units in chronological order throughout the entire sleep process.
[0176] In this process, the learnable parameters included in steps S101 to S107 are backpropagated through joint loss and iteratively updated using gradient descent. The model composed of steps S101 to S107 is jointly trained using class-weighted sleep stage cross-entropy and stage boundary binary cross-entropy with positive sample weights. The joint loss is:
[0177]
[0178] in, The number of valid periods for participating in the stage classification loss calculation. To represent the number of effective adjacent period pairs participating in the boundary loss calculation, n and m are the indices of the stage sample and the boundary sample, respectively. and These are stage labels and boundary labels, For the true class probability, For the stage boundary probability, For stage category weights, For the weights of the boundary positive samples, , and These are stage classification loss, boundary loss, and joint loss. The category weights for sleep stage c are... The total number of valid periods in the training set. Number of sleep stage categories For the quantity of period c, The ratio of non-boundary samples to boundary samples in the training set is determined and limited to the range of 1 to 10. In this embodiment, the boundary loss weights are used as the basis for determining the boundary loss weights. =0.20.
[0179] It should be noted that after completing the subject-level data segmentation, only valid adjacent EEG staging unit pairs in the training set were counted. For the number of boundary samples, The number of non-boundary samples, and according to Confirmed, currently in a fixed 8:1:1 experiment. "clip" indicates truncation or clipping, limiting the values to a specified range; that is, first calculating the ratio of non-boundary samples to boundary samples. Then limit the results to between 1 and 10.
[0180] In this embodiment, the training set, validation set, and test set of the model composed of steps S101 to S107 are divided according to the subject level, for example, in a ratio of 80%:10%:10%. All nighttime records of the same subject are only included in one set, and the optimal model is saved according to the macro-average F1 value of the validation set. In the inference stage, the current period and the previous 14 periods constitute a sliding history window of length 15. Each time a new complete period is obtained, the sleep stage of that period is output. The entire processing does not use future period information, nor does it use additional post-processing probability smoothing.
[0181] Based on the EEG sleep staging method provided in the above embodiments, this application also provides a specific implementation of an EEG sleep staging device. Please refer to the following embodiments.
[0182] First see Figure 2 The present application provides an EEG sleep staging device 200, comprising:
[0183] The acquisition module 201 is used to acquire continuous EEG signals from multiple channels to be staged, and divide the continuous EEG signals into multiple continuous and non-overlapping EEG staging units based on a preset time length.
[0184] Extraction module 202 is used to extract the feature vector of each EEG staging unit;
[0185] The first determining module 203 is used to determine the stage boundary probability between adjacent EEG stage units based on the feature vectors of two adjacent EEG stage units.
[0186] Module 204 is selected to select a preset number of consecutive historical EEG staging units, including the current EEG staging unit, to form a historical window, with the current EEG staging unit as the endpoint. The feature vectors of each EEG staging unit in the historical window are input in parallel into multiple causal temporal convolutional networks with different temporal receptive fields to obtain multiple historical temporal feature sequences.
[0187] The calculation module 205 is used to calculate the probability of all adjacent stage boundaries crossed between any historical EEG stage unit and the current EEG stage unit within the historical window based on the stage boundary probability, to obtain the cumulative cross-boundary path constraint, to modulate the attention weight of the historical temporal features of each causal temporal convolutional network based on the cumulative cross-boundary path constraint, and to perform weighted aggregation on the modulated historical temporal features to obtain the boundary-aware context features corresponding to each causal temporal convolutional network.
[0188] The aggregation module 206 is used to aggregate the feature vector of the current EEG staging unit and the boundary perception context features to obtain the final fused features;
[0189] The second determining module 207 is used to determine the sleep staging result based on the final fusion features.
[0190] As an optional implementation of this embodiment, the extraction module 202 is specifically used for:
[0191] Amplitude calibration is performed on the continuous EEG signals of each channel in each EEG staging unit to obtain calibrated continuous EEG signals. Amplitude calibration involves linearly transforming the continuous EEG signals by setting independent learnable scaling coefficients and bias parameters for each EEG channel. Multi-scale convolution is performed on the calibrated continuous EEG signals of each EEG staging unit to obtain multi-scale temporal features. The temporal features of the multi-scale temporal features are then concatenated along the feature channel dimension and subjected to scale integration convolution to obtain scale features of a preset dimension. Cross-channel spatial convolution is performed on the scale features of the preset dimension to obtain collaborative activity features of multiple channels. Channel recalibration is performed on the collaborative activity features. Single-period temporal context encoding is performed on the channel recalibrated collaborative activity features and aggregated along the time dimension to obtain the feature vector of each EEG staging unit.
[0192] As an optional implementation of this embodiment, the first determining module 203 is specifically used for:
[0193] The element-wise absolute difference between the feature vectors of two adjacent EEG staging units is calculated. Boundary input features are constructed based on the feature vectors of two adjacent EEG staging units and their corresponding element-wise absolute differences. The boundary input features are then input into a boundary prediction network to obtain the boundary prediction value and the stage boundary probability. The boundary prediction network consists of a first fully connected layer, an activation function layer, a random deactivation layer, and a second fully connected layer connected in sequence. The first fully connected layer maps the boundary input features to intermediate features of a preset dimension. The activation function layer activates the intermediate features using a non-linear activation function. The random deactivation layer randomly discards the activated features. The second fully connected layer maps the features output by the random deactivation layer to the boundary prediction value.
[0194] As an optional implementation of this embodiment, each causal temporal convolutional network includes at least two causal convolutional layers, wherein each causal convolutional layer adopts a different dilation rate; wherein each causal convolutional layer is followed by activation processing, random deactivation processing, residual connection processing and normalization processing in sequence.
[0195] As an optional implementation of this embodiment, the calculation module 205 is specifically used for:
[0196] For each historical EEG staging unit within the historical window, obtain the stage boundary probability of each adjacent boundary position between the historical EEG staging unit and the current EEG staging unit; calculate the unbounded continuity probability of each adjacent boundary position, where the unbounded continuity probability is 1 minus the stage boundary probability of the corresponding boundary position; multiply the unbounded continuity probabilities of all adjacent boundary positions together to obtain the path constraint value corresponding to the historical EEG staging unit.
[0197] As an optional implementation of this embodiment, the calculation module 205 is further specifically used for:
[0198] For each causal temporal convolutional network, the basic attention score of the feature vector of each historical EEG staging unit within the historical window is calculated; the basic attention score of each historical EEG staging unit is fused with the corresponding cumulative cross-boundary path constraint to obtain the boundary-aware attention score of the historical EEG staging unit; the boundary-aware attention score of each historical EEG staging unit is normalized to obtain the boundary-aware attention weight of each historical EEG staging unit; based on the boundary-aware attention weight, the historical temporal features of each historical EEG staging unit in the corresponding causal temporal convolutional network are weighted and summed to obtain the boundary-aware context features of the corresponding causal temporal convolutional network.
[0199] As an optional implementation of this embodiment, the aggregation module 206 is specifically used for:
[0200] The feature vector of the current EEG staging unit is projected onto a preset dimension to obtain the current projected feature. The current projected feature and the boundary-aware context feature of each causal temporal convolutional network are concatenated to obtain the concatenated feature. The concatenated feature is input into a scale-gated network to obtain the scale fusion weights corresponding to each causal temporal convolutional network. The boundary-aware context features are weighted and summed based on the scale fusion weights to obtain the multi-scale historical context. The historical information introduction threshold for each feature channel is calculated based on the current projected feature and the multi-scale historical context. The multi-scale historical context is weighted for each feature channel based on the historical information introduction threshold to obtain the gated historical context. The gated historical context and the current projected feature are residually fused and then normalized by the execution layer to obtain the final fused feature. The scale-gated network includes a sequentially connected input layer, intermediate layer and output layer. The input layer is used to transform the dimension of the concatenated feature. The intermediate layer includes a fully connected layer, an activation layer and a random deactivation layer set in sequence. The output dimension of the output layer is the same as the number of causal temporal convolutional networks.
[0201] As an optional implementation of this embodiment, the second determining module is specifically used for:
[0202] The final fused features are input into a classification network to obtain the classification probability of the current EEG staging unit belonging to each preset sleep stage category. The classification network includes fully connected layers, and the preset sleep stage categories include wakefulness, non-rapid eye movement (NREM) stage 1, NREM stage 2, NREM stage 3, and rapid eye movement (REM) stage. The sleep stage category corresponding to the highest classification probability is taken as the sleep staging result of the current EEG staging unit. Based on the temporal order of the EEG staging units, the sleep staging results of all EEG staging units are combined into a whole-night sleep staging sequence.
[0203] Figure 3 A schematic diagram of the hardware structure of the electronic device provided in an embodiment of this application is shown.
[0204] The electronic device may include a processor 301 and a memory 302 storing computer program instructions.
[0205] Specifically, the processor 301 may include a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0206] Memory 302 may include mass storage for data or instructions. For example, and not limitingly, memory 302 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. In one instance, memory 302 may include removable or non-removable (or fixed) media, or memory 302 may be non-volatile solid-state memory. Memory 302 may be internal or external to the integrated gateway disaster recovery device.
[0207] In one instance, memory 302 may be read-only memory (ROM). In one instance, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM), or flash memory, or a combination of two or more of these.
[0208] Memory 302 may include read-only memory (ROM), random access memory (RAM), disk storage media device, optical storage media device, flash memory device, electrical, optical, or other physical / tangible memory storage device. Therefore, typically, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to a method for EEG sleep staging according to a first aspect of this disclosure.
[0209] The processor 301 reads and executes computer program instructions stored in the memory 302 to achieve... Figure 1 An EEG sleep staging method is shown in the embodiment.
[0210] In one example, the electronic device may also include a communication interface 303 and a bus 304. For example, Figure 3 As shown, the processor 301, memory 302, and communication interface 303 are connected through bus 304 and complete communication with each other.
[0211] The communication interface 303 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.
[0212] Bus 304 includes hardware, software, or both, that couples components of an electronic device together. For example, and not as a limitation, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 304 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, any suitable bus or interconnect is contemplated herein.
[0213] This electronic device can execute an EEG sleep staging method as described in this application embodiment, thereby achieving a combination of Figures 1-2 This describes a method and apparatus for EEG sleep staging.
[0214] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.
[0215] The functional blocks shown in the above block diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.
[0216] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.
[0217] The aspects of this disclosure have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by special-purpose hardware performing the specified functions or actions, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0218] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.
Claims
1. A method for EEG sleep staging, characterized in that, include: Acquire continuous EEG signals from multiple channels to be staged, and divide the continuous EEG signals into multiple continuous and non-overlapping EEG staging units based on a preset time length. Extract the feature vector of each of the EEG staging units; The stage boundary probability between adjacent EEG stage units is determined based on the feature vectors of two adjacent EEG stage units. Taking the current EEG staging unit as the endpoint, a preset number of consecutive historical EEG staging units, including the current EEG staging unit, are selected to form a historical window. The feature vectors of each EEG staging unit in the historical window are input in parallel into multiple causal temporal convolutional networks with different temporal receptive fields to obtain multiple historical temporal feature sequences. Based on the stage boundary probability, calculate all adjacent stage boundary probabilities crossed between any historical EEG stage unit and the current EEG stage unit within the historical window to obtain the cumulative cross-boundary path constraint. Based on the cumulative cross-boundary path constraint, perform attention weight modulation on the historical temporal features of each causal temporal convolutional network, and perform weighted aggregation on the modulated historical temporal features to obtain the boundary-aware context features corresponding to each causal temporal convolutional network. The feature vector of the current EEG stage unit and the boundary perception context feature are aggregated to obtain the final fused feature; The sleep staging results are determined based on the final fusion features.
2. The EEG sleep staging method according to claim 1, characterized in that, The extraction of the feature vector for each EEG staging unit includes: The amplitude of the continuous EEG signal of each EEG channel in each EEG stage unit is calibrated to obtain the calibrated continuous EEG signal. The amplitude calibration is performed by linearly transforming the continuous EEG signal by setting independent learnable scaling coefficients and bias parameters for each EEG channel. After calibration, the continuous EEG signal of each EEG staging unit is subjected to multi-scale convolution to obtain multi-scale temporal features. The temporal features of the multi-scale temporal features are then spliced along the feature channel dimension and then subjected to scale integration convolution to obtain scale features of a preset dimension. Perform cross-channel spatial convolution on the scale features of the preset dimensions to obtain collaborative activity features of multiple channels; Channel recalibration is performed on the aforementioned collaborative activity features; The co-activity features after channel recalibration are encoded using single-period temporal context encoding and aggregated along the time dimension to obtain the feature vector of each EEG stage unit.
3. The EEG sleep staging method according to claim 1, characterized in that, The determination of the stage boundary probability between adjacent EEG staging units based on the feature vectors of two adjacent EEG staging units includes: Calculate the element-wise absolute difference between the feature vectors of two adjacent EEG staging units; Boundary input features are constructed based on the feature vectors of two adjacent EEG staging units and the corresponding element-wise absolute differences. The boundary input features are input into the boundary prediction network to obtain the boundary prediction value and the stage boundary probability. The boundary prediction network comprises a first fully connected layer, an activation function layer, a random deactivation layer, and a second fully connected layer connected in sequence. The first fully connected layer is used to map the boundary input features to intermediate features of a preset dimension. The activation function layer uses a non-linear activation function to activate the intermediate features. The random deactivation layer is used to randomly discard the activated features. The second fully connected layer is used to map the features output by the random deactivation layer to the boundary prediction value.
4. The EEG sleep staging method according to claim 1, characterized in that, Each of the aforementioned causal temporal convolutional networks includes at least two causal convolutional layers, wherein each causal convolutional layer employs a different dilation rate; Each causal convolutional layer is followed by activation processing, random deactivation processing, residual connection processing, and normalization processing in sequence.
5. The EEG sleep staging method according to claim 1, characterized in that, The calculation of all adjacent stage boundary probabilities between any historical EEG staging unit and the current EEG staging unit within the historical window based on the stage boundary probabilities includes: For each historical EEG staging unit within the historical window, obtain the stage boundary probability of each adjacent boundary position between the historical EEG staging unit and the current EEG staging unit; Calculate the unbounded continuity probability for each adjacent boundary position, where the unbounded continuity probability is 1 minus the stage boundary probability of the corresponding boundary position. Multiply the unbounded continuous probabilities of all adjacent boundary positions to obtain the path constraint value corresponding to the historical EEG staging unit.
6. The EEG sleep staging method according to claim 1, characterized in that, The process of modulating attention weights on the historical temporal features of each causal temporal convolutional network based on the accumulated cross-boundary path constraints, and then weighting and aggregating the modulated historical temporal features, includes: For each of the causal temporal convolutional networks, calculate the basic attention score of the feature vector of each historical EEG staging unit within the historical window; The basic attention score of each historical EEG stage unit is fused with the corresponding cumulative cross-boundary path constraint to obtain the boundary perception attention score of the historical EEG stage unit. The boundary perception attention score of each historical EEG stage unit is normalized to obtain the boundary perception attention weight of each historical EEG stage unit. Based on the boundary-aware attention weights, the historical temporal features of each historical EEG staging unit in the corresponding causal temporal convolutional network are weighted and summed to obtain the boundary-aware context features of the corresponding causal temporal convolutional network.
7. The EEG sleep staging method according to claim 1, characterized in that, The aggregation of the feature vector of the current EEG staging unit and the boundary-aware context features includes: Project the feature vector of the current EEG stage unit onto a preset dimension to obtain the current projected features; The current projection features and the boundary-aware context features of each causal temporal convolutional network are concatenated to obtain the concatenated features; The spliced features are input into a scale-gated network to obtain the scale fusion weights corresponding to each causal temporal convolutional network. Based on the scale fusion weights, the features of each boundary-aware context are weighted and summed to obtain the multi-scale historical context. Based on the current projection features and the multi-scale historical context, a threshold is introduced by calculating the historical information of each feature channel; Based on the historical information, a threshold is introduced to perform feature-channel weighting on the multi-scale historical context to obtain the gated historical context. The gated historical context and the current projected features are then residually fused and normalized at the execution layer to obtain the final fused features. The scale-gated network includes an input layer, an intermediate layer, and an output layer connected in sequence. The input layer is used to perform dimensionality transformation on the spliced features. The intermediate layer includes a fully connected layer, an activation layer, and a random deactivation layer arranged in sequence. The output dimension of the output layer is the same as the number of layers in the causal temporal convolutional network.
8. The EEG sleep staging method according to claim 1, characterized in that, The determination of sleep staging results based on the final fusion features includes: The final fused features are input into a classification network to obtain the classification probability of the current EEG stage unit belonging to each preset sleep stage category. The classification network includes a fully connected layer, and the preset sleep stage categories include wakefulness, non-rapid eye movement (NREM) stage 1, NREM stage 2, NREM stage 3, and rapid eye movement (REM) stage. The sleep stage category corresponding to the highest classification probability is taken as the sleep staging result of the current EEG staging unit; Based on the temporal order of EEG staging units, the sleep staging results of all EEG staging units are combined into an overnight sleep staging sequence.
9. A brainwave sleep staging device, characterized in that, The device includes: The acquisition module is used to acquire continuous EEG signals from multiple channels to be staged, and to divide the continuous EEG signals into multiple continuous and non-overlapping EEG staging units based on a preset time length. The extraction module is used to extract the feature vector of each of the EEG staging units; The first determining module is used to determine the stage boundary probability between adjacent EEG stage units based on the feature vectors of two adjacent EEG stage units. The selection module is used to select a preset number of consecutive historical EEG staging units, including the current EEG staging unit, as the endpoint to form a historical window. The feature vector of each EEG staging unit in the historical window is input in parallel into multiple causal temporal convolutional networks with different temporal receptive fields to obtain multiple historical temporal feature sequences. The calculation module is used to calculate the probability of all adjacent stage boundaries crossed between any historical EEG stage unit and the current EEG stage unit within the historical window based on the stage boundary probability, to obtain the cumulative cross-boundary path constraint, to modulate the attention weight of the historical temporal features of each causal temporal convolutional network based on the cumulative cross-boundary path constraint, and to perform weighted aggregation on the modulated historical temporal features to obtain the boundary-aware context features corresponding to each causal temporal convolutional network. The aggregation module is used to aggregate the feature vector of the current EEG staging unit and the boundary perception context features to obtain the final fused features; The second determining module is used to determine the sleep staging result based on the final fusion features.
10. An electronic device, characterized in that, The device includes: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, it implements a brainwave sleep staging method as described in any one of claims 1-8.
