An electroencephalogram data classification method fusing mask auto-encoding and conditional diffusion modeling

By fusing masked autoencoders and conditional diffusion modeling, enhanced samples that conform to the distribution of real data are generated. Self-supervised consistency loss is introduced into the EEG signal classification model, which solves the problem of insufficient data and improves the feature representation and generalization ability of the EEG signal classification model.

CN122296909APending Publication Date: 2026-06-30SOUTH CHINA UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SOUTH CHINA UNIV OF TECH
Filing Date
2026-04-08
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

Existing EEG signal classification models are prone to overfitting and insufficient generalization due to insufficient data. Furthermore, existing data augmentation methods struggle to generate new samples with realistic semantic structures and lack constraints on the consistency of features between the original and augmented samples.

Method used

We employ a method that combines masked autoencoders and conditional diffusion modeling to reconstruct unmasked regions with high quality using an EEG signal generation model. This generates enhanced samples that conform to the distribution of real data. Furthermore, we introduce self-supervised consistency loss during the fine-tuning stage of the classification model to improve feature consistency.

Benefits of technology

The training data scale was effectively expanded, which improved the feature expression and generalization ability of the EEG signal classification model and significantly improved the classification accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122296909A_ABST
    Figure CN122296909A_ABST
Patent Text Reader

Abstract

This invention discloses a method for classifying EEG data by integrating masked autoencoding and conditional diffusion modeling. The method includes: training an EEG signal classification model and an EEG signal generation model using an EEG sample set; in the generation stage, dividing the multi-channel spectrogram samples in the EEG sample set into image blocks and performing random masking to obtain masked spectrogram sample blocks and unmasked spectrogram sample blocks; encoding the features of the unmasked spectrogram sample blocks; conditionally reconstructing the masked spectrogram sample blocks under diffusion noise scheduling to generate enhanced multi-channel spectrogram samples; inputting the multi-channel spectrogram samples and enhanced multi-channel spectrogram samples into the EEG signal classification model; fine-tuning the EEG signal classification model using joint loss; and using the optimized EEG signal classification model to achieve automatic staging of sleep EEG data. This invention can achieve high-quality data augmentation while maintaining the consistency of the local structure of EEG signals, effectively improving the stability of EEG signal classification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of EEG signal processing and deep learning, and in particular to an EEG data classification method that integrates mask autoencoder and conditional diffusion modeling. Background Technology

[0002] Electroencephalography (EEG) signals, as important physiological signals reflecting brain neural activity, are widely used in sleep staging, emotion recognition, and brain-computer interfaces. Deep learning-based automated EEG analysis methods are highly dependent on data scale, while EEG data acquisition is costly, annotation is difficult, and the number of samples is limited, leading to overfitting and insufficient generalization ability in classification models.

[0003] To alleviate the problem of low classification accuracy in EEG signal classification models caused by insufficient data, existing techniques typically employ data augmentation methods to expand training samples. Traditional augmentation methods often involve simple operations such as noise perturbation, time shifting, or frequency domain transformation, which are insufficient to generate new samples with realistic semantic structure. In recent years, generative adversarial networks and diffusion models have been used for EEG data generation, but existing methods often generate or reconstruct complete samples as a whole, failing to fully utilize the effective structural information in the original samples, which can easily lead to generated results deviating from the original semantic distribution. Furthermore, existing augmentation methods usually only expand at the sample level, lacking a constraint mechanism for the consistency of features between the original and augmented samples during classification model training, making it difficult to effectively improve the stability and generalization ability of the classification model. Summary of the Invention

[0004] The purpose of this invention is to overcome the shortcomings and deficiencies of the prior art and propose an EEG data classification method that integrates mask autoencoding and conditional diffusion modeling. This method can achieve sample enhancement to improve the local structural consistency of EEG data and introduce feature consistency constraints in the fine-tuning stage of the EEG signal classification model to improve the stability and generalization performance of the EEG signal classification model.

[0005] To achieve the above objectives, the technical solution provided by this invention is: a method for classifying EEG data that integrates mask autoencoder and conditional diffusion modeling, comprising the following steps:

[0006] S1: Obtain a publicly available sleep EEG dataset and perform time-series preprocessing to obtain multi-channel time-domain signals. Convert the multi-channel time-domain signals into a spectrogram representation through time-frequency transformation to obtain multi-channel spectrogram samples. Then, construct an EEG sample set from all the obtained multi-channel spectrogram samples.

[0007] S2: The constructed EEG signal classification model and EEG signal generation model are pre-trained using the EEG sample set to obtain pre-trained EEG signal classification and generation models. The pre-trained EEG signal generation model is then used for sampling, outputting reconstructed mask spectrogram sample blocks. The EEG signal classification model includes a classification model encoder, a feature fusion module, and a classification layer. The classification model encoder consists of multiple parallel feature extraction modules, which are used to extract features from spectrogram samples of different channels to obtain spectrogram sample features of different channels. The spectrogram sample features of different channels are fused through the feature fusion module to obtain joint features. The joint features are processed by a classification layer to output classification results. The EEG signal generation model adopts an architecture based on a diffusion mask autoencoder, including a generative model encoder, a diffusion noise scheduling module, and a conditional decoder module. The generative model encoder first divides the multi-channel spectrogram samples into image blocks and performs random masking to obtain masked spectrogram sample blocks and unmasked spectrogram sample blocks. Then, it encodes the unmasked spectrogram sample blocks to obtain encoded conditional features. The diffusion noise scheduling module adds noise to the masked spectrogram sample blocks according to random sampling time steps to obtain noise sample blocks. The conditional decoder module uses the encoded conditional features and noise sample blocks as input to decode and obtain reconstructed masked spectrogram sample blocks.

[0008] S3: Fuse the reconstructed masked spectrogram sample blocks with the unmasked spectrogram sample blocks to obtain enhanced multi-channel spectrogram samples; simultaneously input the multi-channel spectrogram samples and the enhanced multi-channel spectrogram samples into the pre-trained EEG signal classification model, extract the feature representations of the multi-channel spectrogram samples and the enhanced multi-channel spectrogram samples respectively, construct a self-supervised consistency loss based on the feature representation difference on the basis of the classification loss, use the classification loss and the self-supervised consistency loss as a joint loss, fine-tune the pre-trained EEG signal classification model, and obtain the EEG signal classification model with the best performance;

[0009] S4: Input the sleep EEG data to be tested into the best-performing EEG signal classification model to obtain the sleep stage classification results.

[0010] Furthermore, in step S1, the time-series preprocessing includes: reading sleep EEG signal data and its annotation information, extracting corresponding signal segments according to the annotation information, resampling the signal segments, and removing signal segments corresponding to invalid annotation information to obtain multi-channel time-series signals; the time-frequency transformation includes: performing short-time Fourier transform processing on the multi-channel time-series signals and calculating power spectrum characteristics to obtain multi-channel spectrum samples.

[0011] Furthermore, in step S2, the feature extraction module and the feature fusion module adopt the encoder in the Transformer neural network, the generative model encoder adopts the Vision Transformer, the conditional decoder adopts the cross-attention network, and the diffusion noise scheduling module adopts the classic DDPM model.

[0012] Furthermore, the specific steps of step S2 are as follows:

[0013] S21: In the EEG signal classification model, for the input multi-channel spectrogram samples ,in This represents a single multi-channel spectrogram sample. Represents the first in a single multi-channel spectrogram sample Spectrum samples of each channel , This indicates the number of channels, with each multi-channel spectrogram sample corresponding to a classification label. , Label 0 represents the awakening period, label 1 represents the light sleep period, label 2 represents the deep sleep period, label 3 represents the continued deep sleep period, and label 4 represents the REM sleep period. For the first... Spectrum sample of each channel By adding a position encoding vector, a single-channel spectrogram sample with time and position information is obtained. :

[0014] ;

[0015] ;

[0016] ;

[0017] In the formula, Represents the position encoding vector. Represents the position encoding vector In the middle, at the position index is Dimension index is The value at that location, Represents the position encoding vector In the middle, at the position index is Dimension index is The value at which the even-numbered dimension is located. Using the sine function sin, odd-numbered dimensions Using the cosine function cos, This represents the total number of dimensions of the position vector;

[0018] S22: In the EEG signal classification model, the encoder of the Transformer neural network used in the feature extraction module includes a multi-head attention mechanism. To implement the multi-head attention mechanism, single-channel spectrogram samples with temporal location information are... By applying three different linear transformation matrices, the corresponding query matrix, key matrix, and value matrix are obtained. The calculation formula is as follows:

[0019] ;

[0020] ;

[0021] ;

[0022] In the formula, , , It is a linear transformation matrix. Represents the query matrix. Represents the key matrix. Represents a value matrix;

[0023] Based on the query matrix Bond matrix Calculate the attention weight matrix :

[0024] ;

[0025] In the formula, Key matrix transpose, Representing the query matrix Bond matrix The dimension;

[0026] S23: Adjust the attention weight matrix AND-value matrix Perform a weighted summation to obtain the single-head eigenvector. :

[0027] ;

[0028] In the formula, Indicates the first The calculation results of a single-head self-attention;

[0029] S24: Perform steps S22 and S23. Next, we obtain the multi-head self-attention context-aware feature set. ,in, Indicates the first The calculation results of each single-head self-attention are concatenated along the feature dimension and then linearly mapped to obtain a multi-head fused feature vector with multi-head self-attention. :

[0030] ;

[0031] In the formula, Represents the learnable projection matrix. Indicates the total number of heads of attention;

[0032] S25: Obtain the multi-head fusion feature vector Compared with single-channel spectrogram samples with time and location information Perform residual connections, and then obtain intermediate representations through layer normalization. Then, it is input into a feedforward neural network for nonlinear transformation, and the transformation result is compared with the intermediate representation. Residual connection and normalization are performed to obtain the single-channel spectrogram sample features finally output by the feature extraction module. :

[0033] ;

[0034] ;

[0035] In the formula, Indicates the normalization layer. This represents a feedforward neural network. This represents the spectrogram sample features of the i-th channel;

[0036] S26: Perform steps S21, S22, S23, S24, and S25. This process yields the feature set of each channel in a single multi-channel spectrogram sample. The spectrogram sample features of each channel are concatenated, layer-normalized, and then input into the feature fusion module, where they are normalized again to obtain the joint features. :

[0037] ;

[0038] In the formula, This refers to the random deactivation regularization technique, which prevents the model from overfitting. This indicates a feature fusion module;

[0039] S27: Joint Features Classification is achieved using two fully connected layers and Softmax, with multi-channel spectrogram samples. Classification results Represented as:

[0040] ;

[0041] In the formula, This represents the activation function. and This represents two fully connected layers;

[0042] S28: The model is trained using backpropagation, and the optimal model is selected based on the preset validation set accuracy. The loss function for the EEG signal classification model is... for:

[0043] ;

[0044] In the formula, This indicates the number of multi-channel spectrogram samples processed in a batch. This represents the sample index in a batch of multi-channel spectrogram samples. This represents the total number of categories in the classification task. Indicates category index, Indicates the first The true label distribution of the nth multi-channel spectrogram sample The element, if the element The multi-channel spectrogram sample belongs to the first... Class, then It is 1 if it is 1, otherwise it is 0. The first number predicted by the EEG signal classification model The multi-channel spectrogram sample belongs to the first... The probability values ​​of each category;

[0045] S29: In the EEG signal generation model, the generator encoder will generate multi-channel spectrogram samples. Divide into non-overlapping segments a small piece and all Flattened Composition Sequence :

[0046] ;

[0047] In the formula, express Total number of blocks Indicates the first a small piece ;

[0048] Set the mask ratio ,generate Random noise, The random noise is arranged in ascending order to obtain a binary mask matrix. According to the binary mask matrix right The corresponding position in The sample blocks of the mask spectrum are divided into segments. and unmasked spectrogram sample blocks ;

[0049] S210: For unmasked spectrogram sample blocks After layer normalization, the data is fed into the attention mechanism and... Perform residual connection to obtain intermediate results For intermediate results After undergoing layer normalization again, the data is fed into a multilayer perceptron and compared with intermediate results. Perform residual connections to obtain unmasked spectrogram sample blocks. Encoding conditional features , means as follows:

[0050] ;

[0051] ;

[0052] In the formula, Representation layer normalization, This represents a multilayer perceptron. This represents the attention mechanism;

[0053] S211: The core of the classic DDPM model consists of the forward diffusion process and the reverse denoising process. During the forward diffusion process, the mask spectrum sample blocks are processed. By gradually adding Gaussian random noise, we obtain the first... Noise sample blocks at time steps The noise addition process satisfies the Markov chain property, and the intensity of the Gaussian random noise is controlled by parameters. The noise addition process is expressed as:

[0054] ;

[0055] ;

[0056] ;

[0057] ;

[0058] In the formula, Indicates the time step of random sampling. , , and Representing the first time step, the second time step, the third time step, and the fourth time step, respectively. The parameter that controls the intensity of the random noise added during the time step. , , , and Representing the first time step, the second time step, the third time step, and the fourth time step, respectively. Gaussian random noise was added at each time step. , , , and These represent the first time step, the second time step, the third time step, and the fourth time step, respectively. Time step and the Noise sample blocks obtained at time step;

[0059] Based on the Markov chain property and the superposition property of Gaussian distributions, the superposition of Gaussian random noise from multiple time steps still results in Gaussian random noise, thus yielding the... Noise sample blocks at time steps and The direct relation:

[0060] ;

[0061] In the formula, , Indicates from the 1st time step to the 2nd time step. Each intermediate time step in a time series, Indicates the first The parameter that controls the intensity of the random noise added during the time step. Indicates from the 1st time step to the 2nd time step. The cumulative product of parameters for the intensity of random noise added during time step control. This represents the superposition of Gaussian random noise at each time step;

[0062] During the reverse denoising process, the conditional decoder module uses unmasked spectrogram sample blocks. Encoding conditional features As a conditional constraint, the cross-attention mechanism guides the study of the first... Noise sample blocks at time steps Denoising and reconstruction are performed to directly predict the reconstructed mask spectrum sample blocks. :

[0063] ;

[0064] In the formula, This indicates the condition decoder module;

[0065] S212: Loss function of the final EEG signal generation model for:

[0066] .

[0067] Furthermore, the specific steps of step S3 are as follows:

[0068] S31: Through a binary mask matrix Reconstruct mask spectrogram sample blocks Compared with unmasked spectrogram sample blocks The samples are fused to obtain enhanced multi-channel spectrogram samples. :

[0069] ;

[0070] In the formula, It represents the Hadamardi (or Hadama) stack;

[0071] S32: Sample the multi-channel spectrogram and enhanced multi-channel spectrogram samples Simultaneously, the pre-trained EEG signal classification model is input, and a self-supervised consistency loss is introduced. Fine-tuning is performed by minimizing the weighted sum of the classification loss and the self-supervised consistency loss. The final loss function of the EEG signal classification model is then calculated. Represented as:

[0072] ;

[0073] In the formula, It is the first The mask ratio of a multi-channel spectrogram sample. It is the first A multi-channel spectrogram sample The first result obtained before the last fully connected layer of the EEG signal classification model dimensional feature vectors It is the first A multi-channel spectrogram sample Corresponding enhanced multi-channel spectrogram samples The first result obtained before the last fully connected layer of the EEG signal classification model dimensional feature vectors It is the total feature dimension. It is an enhancing factor.

[0074] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0075] 1. This invention combines mask autoencoding with conditional diffusion modeling to construct an EEG signal generation model. It can start from the features of the unmasked region and perform high-quality conditional reconstruction of the masked region to generate enhanced samples that conform to the distribution of real data. This effectively expands the scale of training data and alleviates the problem of insufficient EEG data samples.

[0076] 2. This invention designs an EEG signal classification model. By extracting features from spectrogram samples of different channels and then fusing and classifying them, the complementary information between multi-channel EEG signals is fully explored, thereby improving the feature expression ability of the EEG signal classification model.

[0077] 3. This invention introduces self-supervised consistency loss in the fine-tuning stage of the EEG signal classification model, which constrains the feature representations of multi-channel spectrogram samples and enhanced multi-channel spectrogram samples, enabling the EEG signal classification model to learn more robust feature representations on the basis of the classification task, and significantly improving the generalization ability and classification accuracy of the EEG signal classification model.

[0078] 4. This invention constructs a collaborative training framework for an EEG signal generation model and an EEG signal classification model, using the EEG signal generation model as a data augmentation tool to serve the classification task, achieving a positive interaction between generation and classification, and providing a new technical path for EEG signal analysis. Attached Figure Description

[0079] Figure 1 This is a framework diagram of the method of the present invention.

[0080] Figure 2 This is a schematic diagram of mask autoencoding and conditional diffusion modeling.

[0081] Figure 3 This is a schematic diagram of feature consistency constraints. Detailed Implementation

[0082] The present invention will be further described in detail below with reference to the embodiments and accompanying drawings, but the embodiments of the present invention are not limited thereto.

[0083] like Figure 1 As shown, this embodiment discloses a method for classifying EEG data that integrates masked autoencoder and conditional diffusion modeling. The overall process includes EEG data preprocessing, EEG signal classification model pre-training, EEG signal generation model pre-training, sample augmentation, and EEG signal classification model fine-tuning, and includes the following steps:

[0084] 1) EEG data preprocessing:

[0085] First, sleep EEG signal data and its annotation information are read. Based on the annotation information, corresponding signal segments are extracted, the signal segments are resampled, and signal segments corresponding to invalid annotation information are removed to obtain multi-channel time-series signals.

[0086] Subsequently, the multi-channel time-series signal is subjected to time-frequency transformation processing. In this embodiment, short-time Fourier transform is used to obtain the time-frequency representation, calculate the logarithmic power spectrum characteristics, and extract the time-frequency characteristics within a preset frequency band to construct a multi-channel spectrum sample.

[0087] 2) Pre-training of EEG signal classification model:

[0088] An EEG signal classification model is constructed, comprising a classification model encoder, a feature fusion module, and a classification layer. The classification model encoder consists of multiple parallel feature extraction modules, which are used to extract features from spectrogram samples of different channels to obtain spectrogram sample features of different channels. The spectrogram sample features of different channels are fused by the feature fusion module to obtain joint features. The joint features are then output as classification results by the classification layer.

[0089] In this embodiment, the EEG signal classification model is first pre-trained using multi-channel spectrogram samples to obtain pre-trained EEG signal classification model parameters, which includes the following steps:

[0090] 2.1) For the input multi-channel spectrogram sample ,in This represents a single multi-channel spectrogram sample. Represents the first in a single multi-channel spectrogram sample Spectrum samples of each channel , This indicates the number of channels, with each multi-channel spectrogram sample corresponding to a classification label. , Label 0 represents the awakening period, label 1 represents the light sleep period, label 2 represents the deep sleep period, label 3 represents the continued deep sleep period, and label 4 represents the REM sleep period. For the first... Spectrum sample of each channel By adding a position encoding vector, a single-channel spectrogram sample with time and position information is obtained. :

[0091] ;

[0092] ;

[0093] ;

[0094] In the formula, Represents the position encoding vector. Represents the position encoding vector In the middle, at the position index is Dimension index is The value at that location, Represents the position encoding vector In the middle, at the position index is Dimension index is The value at which the even-numbered dimension is located. Using the sine function sin, odd-numbered dimensions Using the cosine function cos, This represents the total number of dimensions of the position vector;

[0095] 2.2) In the EEG signal classification model, the encoder of the Transformer neural network used in the feature extraction module includes a multi-head attention mechanism. The multi-head attention mechanism is used to extract the intrinsic relationship between vectors at different locations. To implement the multi-head attention mechanism, single-channel spectrogram samples with temporal location information are used. By applying three different linear transformation matrices, the corresponding query matrix, key matrix, and value matrix are obtained. The calculation formula is as follows:

[0096] ;

[0097] ;

[0098] ;

[0099] In the formula, , , It is a linear transformation matrix. Represents the query matrix. Represents the key matrix. Represents a value matrix;

[0100] Based on the query matrix Bond matrix Calculate the attention weight matrix :

[0101] ;

[0102] in Key matrix transpose, Representing the query matrix Bond matrix The dimension;

[0103] 2.3) The attention weight matrix AND-value matrix Perform a weighted summation to obtain the single-head eigenvector. :

[0104] ;

[0105] in Indicates the first The calculation results of a single-head self-attention;

[0106] 2.4) Perform steps 2.2) and 2.3) Next, we obtain the multi-head self-attention context-aware feature set. ,in, Indicates the first The calculation results of each single-head self-attention are concatenated along the feature dimension and then linearly mapped to obtain a multi-head fused feature vector with multi-head self-attention. :

[0107] ;

[0108] in Represents the learnable projection matrix. Indicates the total number of heads of attention;

[0109] 2.5) The obtained multi-head fusion feature vector Compared with single-channel spectrogram samples with time and location information Perform residual connections, and then obtain intermediate representations through layer normalization. Then, it is input into a feedforward neural network for nonlinear transformation, and the transformation result is compared with the intermediate representation. Residual connection and normalization are performed to obtain the single-channel spectrogram sample features finally output by the feature extraction module. :

[0110] ;

[0111] ;

[0112] in Indicates the normalization layer. This represents a feedforward neural network. This represents the spectrogram sample features of the i-th channel;

[0113] 2.6) Perform steps 2.1), 2.2), 2.3), 2.4), and 2.5). This process yields the feature set of each channel in a single multi-channel spectrogram sample. The spectrogram sample features of each channel are concatenated, layer-normalized, and then input into the feature fusion module, where they are normalized again to obtain the joint features. :

[0114] ;

[0115] in This refers to the random deactivation regularization technique, which prevents the model from overfitting. Indicates the feature fusion module, Represents the position encoding vector;

[0116] 2.7) Joint features Classification is achieved using two fully connected layers and Softmax, with multi-channel spectrogram samples. Classification results Represented as:

[0117] ;

[0118] in This represents the activation function. and This represents two fully connected layers;

[0119] 2.8) The model is trained using backpropagation, and the optimal model is selected based on the preset validation set accuracy. The loss function of the EEG signal classification model is... for:

[0120] ;

[0121] in This indicates the number of multi-channel spectrogram samples processed in a batch. This represents the sample index in a batch of multi-channel spectrogram samples. This represents the total number of categories in the classification task. Indicates category index, Indicates the first The true label distribution of the nth multi-channel spectrogram sample The element, if the element The multi-channel spectrogram sample belongs to the first... Class, then It is 1 if it is 1, otherwise it is 0. The first number predicted by the EEG signal classification model The multi-channel spectrogram sample belongs to the first... The probability values ​​of each category.

[0122] 3) such as Figure 2 As shown, the EEG signal generation model integrates masked autoencoder and conditional diffusion modeling, and the training process is as follows:

[0123] 3.1) During the encoding stage, the generative model encoder will generate multi-channel spectrogram samples. Divide into non-overlapping segments a small piece and all Flattened Composition Sequence :

[0124] ;

[0125] In the formula, express Total number of blocks Indicates the first a small piece ;

[0126] Set the mask ratio ,generate Random noise, The random noise is arranged in ascending order to obtain a binary mask matrix. Based on the binary mask matrix The corresponding position in The sample blocks of the mask spectrum are divided into segments. and unmasked spectrogram sample blocks ;

[0127] For unmasked spectrogram sample blocks After layer normalization, the data is fed into the attention mechanism and... Perform residual connection to obtain intermediate results For intermediate results After undergoing layer normalization again, the data is fed into a multilayer perceptron and compared with intermediate results. Perform residual connections to obtain unmasked spectrogram sample blocks. Encoding conditional features , means as follows:

[0128] ;

[0129] ;

[0130] in Representation layer normalization, This represents a multilayer perceptron. This represents the attention mechanism;

[0131] 3.2) In the decoding stage, the core of the classic DDPM model consists of the forward diffusion process and the reverse denoising process. During the forward diffusion process, the mask spectrum sample blocks are processed. By gradually adding Gaussian random noise, we obtain the first... Noise sample blocks at time steps The noise addition process satisfies the Markov chain property, and the intensity of the Gaussian random noise is controlled by parameters. The noise addition process can be expressed as:

[0132] ;

[0133] ;

[0134] ;

[0135] ;

[0136] in Indicates the time step of random sampling. , , and Representing the first time step, the second time step, the third time step, and the fourth time step, respectively. The parameter that controls the intensity of the random noise added during the time step. , , , and Representing the first time step, the second time step, the third time step, and the fourth time step, respectively. Gaussian random noise was added at each time step. , , , and These represent the first time step, the second time step, the third time step, and the fourth time step, respectively. Time step and the Noise sample blocks obtained at time step;

[0137] Based on the Markov chain property and the superposition property of Gaussian distributions, the superposition of Gaussian random noise from multiple time steps still results in Gaussian random noise, thus yielding the... Noise sample blocks at time steps and The direct relation:

[0138] ;

[0139] In the formula, , Indicates from the 1st time step to the 2nd time step. Each intermediate time step in a time series, Indicates the first The parameter that controls the intensity of the random noise added during the time step. Indicates from the 1st time step to the 2nd time step. The cumulative product of parameters for the intensity of random noise added during time step control. This represents the superposition of Gaussian random noise at each time step;

[0140] The inverse process of classic DDPM generates samples through iterative denoising. As can be seen from the denoising process, the model needs to predict the Gaussian random noise added at each time step and gradually recover the multi-channel spectrogram samples according to the inverse inference formula. While this stepwise denoising mechanism can generate high-quality samples, it requires iterative computation at multiple time steps, resulting in low inference efficiency. Furthermore, the optimization objective is focused on predicting Gaussian random noise rather than the target sample itself.

[0141] Considering that the present invention aims to locally reconstruct masked spectrogram sample blocks in multi-channel spectrogram samples, while unmasked spectrogram sample blocks can be used as known conditional information to participate in the generation process of EEG signal generation model, it is not necessary to fully execute the stepwise reverse denoising process.

[0142] Based on this, the present invention uses random time steps Below, the conditional decoder module uses unmasked spectrogram sample blocks. Encoding conditional features As a conditional constraint, the cross-attention mechanism guides the study of the first... Noise sample blocks at time steps Denoising and reconstruction are performed to directly predict the reconstructed mask spectrum sample blocks. :

[0143] ;

[0144] in This indicates the condition decoder module;

[0145] The loss function of the final EEG signal generation model for:

[0146] ;

[0147] 4) such as Figure 3 As shown, the sample enhancement and fine-tuning process of the EEG signal classification model is as follows:

[0148] 4.1) Load the pre-trained EEG signal generation model and generate multi-channel spectrogram samples. Input the EEG signal generation model to obtain a reconstructed mask spectrogram sample block. Unmasked spectrogram sample block and binary mask matrix Through a binary mask matrix Reconstruct mask spectrogram sample blocks Compared with unmasked spectrogram sample blocks The samples are fused to obtain enhanced multi-channel spectrogram samples. :

[0149] ;

[0150] In the formula, Represents a binary mask matrix. It represents the Hadamardi (or Hadama) stack;

[0151] 4.2) Load the pre-trained EEG signal classification model and process the multi-channel spectrogram samples. and enhanced multi-channel spectrogram samples Simultaneously, the EEG signal classification model is input, and a self-supervised consistency loss is introduced. Fine-tuning is performed by minimizing the weighted sum of the classification loss and the self-supervised consistency loss. The final loss function of the EEG signal classification model is then determined. It can be represented as:

[0152] ;

[0153] In the formula, It is the first The mask ratio of a multi-channel spectrogram sample. It is the first A multi-channel spectrogram sample The first result obtained before the last fully connected layer of the EEG signal classification model dimensional feature vectors It is the first A multi-channel spectrogram sample Corresponding enhanced multi-channel spectrogram samples The first result obtained before the last fully connected layer of the EEG signal classification model dimensional feature vectors It is the total feature dimension. It is an enhancing factor.

[0154] 5) After the fine-tuning training of the EEG signal classification model is completed, the best-performing EEG signal classification model is obtained. The sleep EEG data to be tested is then input into the best-performing EEG signal classification model to obtain the sleep stage classification results.

[0155] The above embodiments are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the spirit and principle of the present invention shall be considered equivalent substitutions and shall be included within the protection scope of the present invention.

Claims

1. A method for classifying EEG data by integrating masked autoencoders and conditional diffusion modeling, characterized in that, Includes the following steps: S1: Obtain a publicly available sleep EEG dataset and perform time-series preprocessing to obtain multi-channel time-domain signals. Convert the multi-channel time-domain signals into a spectrogram representation through time-frequency transformation to obtain multi-channel spectrogram samples. Then, construct an EEG sample set from all the obtained multi-channel spectrogram samples. S2: The constructed EEG signal classification model and EEG signal generation model are pre-trained using the EEG sample set to obtain pre-trained EEG signal classification and generation models. The pre-trained EEG signal generation model is then used for sampling to output reconstructed masked spectrogram sample blocks. The EEG signal classification model includes a classification model encoder, a feature fusion module, and a classification layer. The classification model encoder consists of multiple parallel feature extraction modules, which are used to extract features from spectrogram samples of different channels to obtain spectrogram sample features of different channels. The spectrogram sample features of different channels are fused by the feature fusion module to obtain joint features. The joint features are then used by the classification layer to output the classification result. The EEG signal generation model adopts an architecture based on a diffusion mask autoencoder, including a generation model encoder, a diffusion noise scheduling module, and a conditional decoder module. The generation model encoder first performs image block division and random masking on the multi-channel spectrogram samples to obtain masked spectrogram sample blocks and unmasked spectrogram sample blocks. Then, the unmasked spectrogram sample blocks are encoded to obtain encoded conditional features. The diffusion noise scheduling module adds noise to the mask spectrum sample blocks according to the random sampling time step to obtain noise sample blocks; the conditional decoder module takes the encoded conditional features and the noise sample blocks as input to decode and obtain the reconstructed mask spectrum sample blocks. S3: Fuse the reconstructed masked spectrogram sample blocks with the unmasked spectrogram sample blocks to obtain enhanced multi-channel spectrogram samples; simultaneously input the multi-channel spectrogram samples and the enhanced multi-channel spectrogram samples into the pre-trained EEG signal classification model, extract the feature representations of the multi-channel spectrogram samples and the enhanced multi-channel spectrogram samples respectively, construct a self-supervised consistency loss based on the feature representation difference on the basis of the classification loss, use the classification loss and the self-supervised consistency loss as a joint loss, fine-tune the pre-trained EEG signal classification model, and obtain the EEG signal classification model with the best performance; S4: Input the sleep EEG data to be tested into the best-performing EEG signal classification model to obtain the sleep stage classification results.

2. The EEG data classification method fusing masked autoencoder and conditional diffusion modeling as described in claim 1, characterized in that, In step S1, the time-series preprocessing includes: reading sleep EEG signal data and its annotation information, extracting corresponding signal segments according to the annotation information, resampling the signal segments, and removing signal segments corresponding to invalid annotation information to obtain multi-channel time-series signals; the time-frequency transformation includes: performing short-time Fourier transform processing on the multi-channel time-series signals and calculating power spectrum characteristics to obtain multi-channel spectrum samples.

3. The EEG data classification method fusing masked autoencoder and conditional diffusion modeling as described in claim 1, characterized in that, In step S2, the feature extraction module and the feature fusion module adopt the encoder in the Transformer neural network, the generative model encoder adopts the Vision Transformer, the conditional decoder adopts the cross-attention network, and the diffusion noise scheduling module adopts the classic DDPM model.

4. The EEG data classification method fusing mask autoencoder and conditional diffusion modeling according to claim 3, characterized in that, The specific steps for step S2 are as follows: S21: In the EEG signal classification model, for the input multi-channel spectrogram samples ,in This represents a single multi-channel spectrogram sample. Represents the first in a single multi-channel spectrogram sample Spectrum samples of each channel , This indicates the number of channels, with each multi-channel spectrogram sample corresponding to a classification label. , Label 0 represents the awakening period, label 1 represents the light sleep period, label 2 represents the deep sleep period, label 3 represents the continued deep sleep period, and label 4 represents the REM sleep period. For the first... Spectrum sample of each channel By adding a position encoding vector, a single-channel spectrogram sample with time and position information is obtained. : ; ; ; In the formula, Represents the position encoding vector. Represents the position encoding vector In the middle, at the position index is Dimension index is The value at that location, Represents the position encoding vector In the middle, at the position index is Dimension index is The value at which the even-numbered dimension is located. Using the sine function sin, odd-numbered dimensions Using the cosine function cos, This represents the total number of dimensions of the position vector; S22: In the EEG signal classification model, the encoder of the Transformer neural network used in the feature extraction module includes a multi-head attention mechanism. To implement the multi-head attention mechanism, single-channel spectrogram samples with temporal location information are... By applying three different linear transformation matrices, the corresponding query matrix, key matrix, and value matrix are obtained. The calculation formula is as follows: ; ; ; In the formula, , , It is a linear transformation matrix. Represents the query matrix. Represents the key matrix, Represents a value matrix; Based on the query matrix Bond matrix Calculate the attention weight matrix : ; In the formula, Key matrix transpose, Representing the query matrix Bond matrix The dimension; S23: Adjust the attention weight matrix AND-value matrix Perform a weighted summation to obtain the single-head eigenvector. : ; In the formula, Indicates the first The calculation results of a single-head self-attention; S24: Perform steps S22 and S23. Next, we obtain the multi-head self-attention context-aware feature set. ,in, Indicates the first The calculation results of each single-head self-attention are concatenated along the feature dimension and then linearly mapped to obtain a multi-head fused feature vector with multi-head self-attention. : ; In the formula, Represents the learnable projection matrix. Indicates the total number of heads of attention; S25: Obtain the multi-head fusion feature vector Compared with single-channel spectrogram samples with time and location information Perform residual connections, and then obtain intermediate representations through layer normalization. Then, it is input into a feedforward neural network for nonlinear transformation, and the transformation result is compared with the intermediate representation. Residual connection and normalization are performed to obtain the single-channel spectrogram sample features finally output by the feature extraction module. : ; ; In the formula, Indicates the normalization layer. This represents a feedforward neural network. This represents the spectrogram sample features of the i-th channel; S26: Perform steps S21, S22, S23, S24, and S25. This process yields the feature set of each channel in a single multi-channel spectrogram sample. The spectrogram sample features of each channel are concatenated, layer-normalized, and then input into the feature fusion module, where they are normalized again to obtain the joint features. : ; In the formula, This refers to the random deactivation regularization technique, which prevents the model from overfitting. This indicates a feature fusion module; S27: Joint Features Classification is achieved using two fully connected layers and Softmax, with multi-channel spectrogram samples. Classification results Represented as: ; In the formula, This represents the activation function. and This represents two fully connected layers; S28: The model is trained using backpropagation, and the optimal model is selected based on the preset validation set accuracy. The loss function for the EEG signal classification model is... for: ; In the formula, This indicates the number of multi-channel spectrogram samples processed in a batch. This represents the sample index in a batch of multi-channel spectrogram samples. This represents the total number of categories in the classification task. Indicates category index, Indicates the first The true label distribution of the nth multi-channel spectrogram sample The element, if the element The multi-channel spectrogram sample belongs to the first... Class, then It is 1 if it is true, otherwise it is 0. The first number predicted by the EEG signal classification model The multi-channel spectrogram sample belongs to the first... The probability values ​​of each category; S29: In the EEG signal generation model, the generator encoder will generate multi-channel spectrogram samples. Divide into non-overlapping segments a small piece and all Flattened Composition Sequence : ; In the formula, express Total number of blocks Indicates the first a small piece ; Set the mask ratio ,generate Random noise, The random noise is arranged in ascending order to obtain a binary mask matrix. According to the binary mask matrix right The corresponding position in The sample blocks of the mask spectrum are divided into segments. and unmasked spectrogram sample blocks ; S210: For unmasked spectrogram sample blocks After layer normalization, the data is fed into the attention mechanism and... Perform residual connection to obtain intermediate results For intermediate results After undergoing layer normalization again, the data is fed into a multilayer perceptron and compared with intermediate results. Perform residual connections to obtain unmasked spectrogram sample blocks. Encoding conditional features , means as follows: ; ; In the formula, Representation layer normalization, This represents a multilayer perceptron. This represents the attention mechanism; S211: The core of the classic DDPM model consists of the forward diffusion process and the reverse denoising process. During the forward diffusion process, the mask spectrum sample blocks are processed. By gradually adding Gaussian random noise, we obtain the first... Noise sample blocks at time steps The noise addition process satisfies the Markov chain property, and the intensity of the Gaussian random noise is controlled by parameters. The noise addition process is expressed as: ; ; ; ; In the formula, Indicates the time step of random sampling. , , and Representing the first time step, the second time step, the third time step, and the fourth time step, respectively. The parameter that controls the intensity of the random noise added during the time step. , , , and Representing the first time step, the second time step, the third time step, and the fourth time step, respectively. Gaussian random noise was added at each time step. , , , and These represent the first time step, the second time step, the third time step, and the fourth time step, respectively. Time step and the Noise sample blocks obtained at time step; Based on the Markov chain property and the superposition property of Gaussian distributions, the superposition of Gaussian random noise from multiple time steps still results in Gaussian random noise, thus yielding the... Noise sample blocks at time steps and The direct relation: ; In the formula, , Indicates from the 1st time step to the 2nd time step. Each intermediate time step in a time series, Indicates the first The parameter that controls the intensity of the random noise added during the time step. Indicates from the 1st time step to the 2nd time step. The cumulative product of parameters for the intensity of random noise added during time step control. This represents the superposition of Gaussian random noise at each time step; During the reverse denoising process, the conditional decoder module uses unmasked spectrogram sample blocks. Encoding conditional features As a conditional constraint, the cross-attention mechanism guides the study of the first... Noise sample blocks at time steps Denoising and reconstruction are performed to directly predict the reconstructed mask spectrum sample blocks. : ; In the formula, This indicates the condition decoder module; S212: Loss function of the final EEG signal generation model for: 。 5. The EEG data classification method fusing masked autoencoder and conditional diffusion modeling as described in claim 4, characterized in that, The specific steps of step S3 are as follows: S31: Through a binary mask matrix Reconstruct mask spectrogram sample blocks Compared with unmasked spectrogram sample blocks The samples are fused to obtain enhanced multi-channel spectrogram samples. : ; In the formula, It represents the Hadamardi (or Hadama) stack; S32: Sample the multi-channel spectrogram and enhanced multi-channel spectrogram samples Simultaneously, the pre-trained EEG signal classification model is input, and a self-supervised consistency loss is introduced. Fine-tuning is performed by minimizing the weighted sum of the classification loss and the self-supervised consistency loss. The final loss function of the EEG signal classification model is then calculated. Represented as: ; In the formula, It is the first The mask ratio of a multi-channel spectrogram sample. It is the first A multi-channel spectrogram sample The first result obtained before the last fully connected layer of the EEG signal classification model dimensional feature vectors It is the first A multi-channel spectrogram sample Corresponding enhanced multi-channel spectrogram samples The first result obtained before the last fully connected layer of the EEG signal classification model dimensional feature vectors It is the total feature dimension. It is an enhancing factor.