A seizure prediction system based on CNN and self-attention mechanism
By using a CNN-based and self-attention mechanism-based epileptic seizure prediction system, which utilizes S-transform and convolutional neural networks to process EEG signals, the system solves the problems of high analysis difficulty and high model complexity in existing technologies, and achieves efficient and accurate epileptic seizure prediction and real-time early warning.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANDONG INST OF ADVANCED TECH CHINESE ACAD OF SCI CO LTD
- Filing Date
- 2022-09-29
- Publication Date
- 2026-05-26
AI Technical Summary
Existing epilepsy seizure prediction technologies suffer from challenges in analyzing electroencephalogram (EEG) signals, high complexity of deep learning models, and a lack of comprehensive early warning systems, resulting in insufficient prediction efficiency and accuracy.
An epileptic seizure prediction system based on CNN and self-attention mechanism is adopted. The EEG signal is processed by S-transform, and an initial prediction neural network is constructed by combining convolutional neural network and self-attention mechanism to perform feature extraction and prediction, including sample acquisition, feature matrix determination, network training and real-time prediction.
It improves the accuracy and efficiency of epileptic seizure prediction, achieves prediction with fewer parameters and faster speed, has high accuracy and strong generalization ability, and supports real-time epileptic seizure early warning.
Smart Images

Figure CN115381407B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of signal feature analysis, and in particular to an epileptic seizure prediction system based on CNN and self-attention mechanism. Background Technology
[0002] Epilepsy is one of the most common neurological disorders in the world, and people with epilepsy are three times more likely to die prematurely than the general population. A recent report from the World Health Organization indicates that nearly a quarter of epilepsy cases are preventable, and 70% of people with epilepsy can achieve seizure-free status through low-cost and effective medications.
[0003] In recent years, with the development of machine learning (deep learning), classification-based epilepsy seizure prediction technology has also been rapidly developing towards higher accuracy, higher sensitivity, and lower false alarm rates. The main process involves segmenting the EEG (Electroencephalogram) signal into the interictal and preictal phases; extracting features using time-domain, frequency-domain, or time-frequency-domain methods; then feeding the extracted features into a machine learning or deep learning model for classification; and finally, performing post-processing operations for early warning.
[0004] However, to date, the following challenges remain to be overcome in epileptic seizure prediction technology:
[0005] First, EEG signals are typical non-stationary signals, containing a large amount of information. The statistical information contained in the signal is random at different times, which increases the difficulty of EEG signal analysis and feature extraction.
[0006] Second, although deep learning models have high accuracy and low false positive rate, their large number of parameters leads to complex space complexity; therefore, it is necessary to propose models with higher accuracy and fewer parameters.
[0007] Third, most epilepsy prediction studies only include a preliminary classification of EEG signals and do not have a complete epilepsy seizure early warning system, so there are still many difficulties before the clinical application of epilepsy seizure prediction.
[0008] Based on the above problems, there is an urgent need for a new method to predict epileptic seizures in order to improve prediction efficiency and accuracy. Summary of the Invention
[0009] The purpose of this invention is to provide an epileptic seizure prediction system based on CNN and self-attention mechanism, which can improve the prediction efficiency and accuracy of epileptic seizures.
[0010] To achieve the above objectives, the present invention provides the following solution:
[0011] A seizure prediction system based on CNN and self-attention mechanism, comprising:
[0012] The sample acquisition unit is used to acquire a sample dataset. The sample dataset includes sample EEG signals from multiple patients at multiple historical time periods and label information for each sample EEG signal. Each sample EEG signal includes sample channel signals from multiple EEG channels. The label information includes 0 and 1, where 0 indicates that the corresponding sample EEG signal is an interictal EEG signal and 1 indicates that the corresponding sample EEG signal is a preictal EEG signal.
[0013] The first transformation unit is connected to the sample acquisition unit and is used to perform S-transform on the signals of each sample channel for any patient at any time period to obtain the sample feature set corresponding to each sample channel signal.
[0014] The sample feature matrix determination unit, connected to the first transformation unit, is used to determine the sample feature matrix for any patient at any time period based on each sample feature set.
[0015] Network building unit, used to construct an initial prediction neural network based on convolutional neural networks and self-attention mechanisms;
[0016] The training unit is connected to the sample feature matrix determination unit, the sample acquisition unit and the network construction unit respectively. It is used to train the initial prediction neural network based on the sample feature matrix of each patient at each time period and the label information of the sample EEG signal corresponding to each sample feature matrix to obtain the epileptic seizure prediction model.
[0017] The signal acquisition unit is used to acquire the EEG signals of the patient in multiple EEG channels in real time during the current period;
[0018] The second transformation unit is connected to the signal acquisition unit and is used to perform S-transformation on each EEG signal to be tested to obtain the feature set corresponding to each EEG signal to be tested.
[0019] The feature matrix determination unit is connected to the second transformation unit and is used to determine the feature matrix to be measured in the current time period based on each feature set to be measured.
[0020] The prediction unit is connected to both the training unit and the test feature matrix determination unit, and is used to determine whether the current time period is the pre-seizure phase based on the epileptic seizure prediction model and the test feature matrix.
[0021] Optionally, the sample acquisition unit includes:
[0022] The initial sample acquisition module is used to acquire initial sample channel signals from multiple EEG channels of multiple patients within a continuous historical time period;
[0023] The slicing module, connected to the initial sample acquisition module, is used to slice the initial sample channel signal of any patient's EEG channel at a set time interval to obtain sample channel signals of multiple time periods corresponding to the EEG channel; the sample channel signal of the same time period is the sample EEG signal of the corresponding time period.
[0024] The annotation module, connected to the slicing module, is used to annotate the EEG signals of each patient at each time period and determine the label information corresponding to each sample EEG signal.
[0025] Optionally, the transformation unit includes:
[0026] The S-transform module, connected to the sample acquisition unit, is used to perform S-transform on the signals of each sample channel for any patient at any time period, transforming the signals of each sample channel from the time domain to the time-frequency domain, and obtaining the time-frequency matrix corresponding to each sample channel signal.
[0027] The partitioning module, connected to the S-transform module, is used to divide the time-frequency matrix of the sample channel signal into multiple blocks according to the frequency and time segment of the sample channel signal for any sample channel signal of any patient at any time period, and sum the results for each block to obtain multiple sample feature values of the sample channel signal.
[0028] The sample feature set determination module, connected to the segmentation module, is used to determine the sample feature set of any sample channel signal for any patient at any time period based on multiple sample feature values of the sample channel signal.
[0029] Optionally, the sample feature set of each sample channel signal includes multiple sample feature values;
[0030] The sample feature matrix determination unit includes:
[0031] An initial matrix determination module, connected to the first transformation unit, is used to determine an initial sample feature matrix for any patient at any time period based on each sample feature set; the initial sample feature matrix includes multiple sample feature values.
[0032] The calculation module, connected to the initial matrix determination module, is used to calculate the mean and standard deviation of the initial sample feature matrix for each patient at each time period.
[0033] The standardization module is connected to the calculation module and the initial matrix determination module respectively. It is used to standardize the sample feature values in the initial sample feature matrix for any patient at any time period based on the mean and standard deviation of the initial sample feature matrix for that time period, so as to obtain the corresponding standardized sample feature values.
[0034] The feature matrix determination module, connected to the standardization module, is used to determine the sample feature matrix for any patient at any time period based on the standardized sample feature values of each time period.
[0035] Optionally, the i-th sample feature value in the initial sample feature matrix can be standardized using the following formula:
[0036]
[0037] in, Let D be the feature value of the i-th standardized sample. i Let D be the feature value of the i-th sample. mean D is the mean of the initial sample feature matrix. std denoted as the standard deviation of the initial sample feature matrix.
[0038] Optionally, the training unit includes:
[0039] A convolutional neural network is used to extract features from a sample feature matrix of any patient at any time period to obtain three-dimensional feature data.
[0040] A dimension conversion module, connected to the convolutional neural network, is used to convert the three-dimensional feature data into two-dimensional feature data;
[0041] The self-attention module, connected to the dimension transformation module, is used to determine self-attention features based on the two-dimensional feature data and a self-attention mechanism.
[0042] A fully connected layer, connected to the self-attention module, is used to convert the self-attention features into a one-dimensional vector;
[0043] A softmax classifier, connected to the fully connected layer, is used to determine the predicted category of the one-dimensional vector; the predicted category is 0 or 1; 0 indicates that the sample EEG signal corresponding to the sample feature matrix is an interictal EEG signal, and 1 indicates that the sample EEG signal corresponding to the sample feature matrix is a preictal EEG signal.
[0044] The training module, connected to the softmax classifier, the sample acquisition unit, the convolutional neural network, and the self-attention module, is used to determine the loss function based on the predicted category of the sample feature matrix of each patient at each time period and the corresponding label information of the sample EEG signal. The module then adjusts the weights and biases of the convolutional neural network and the weights of the self-attention mechanism according to the loss function until the loss function converges to obtain the optimal prediction neural network. The optimal prediction neural network is the epileptic seizure prediction model.
[0045] Optionally, the self-attention module includes:
[0046] A data partitioning submodule, connected to the dimension transformation module, is used to divide the two-dimensional feature data into multiple sub-data.
[0047] The convolutional block, connected to the data partitioning submodule, is used to perform convolution on each sub-data to obtain the key parameters, query parameters, and value parameters of each sub-data.
[0048] The dot product attention submodule, connected to the convolutional block, is used to determine the dot product attention features corresponding to each sub-data based on the key parameters, query parameters, and value parameters of each sub-data.
[0049] The self-attention submodule, connected to the dot product attention submodule, is used to determine the self-attention features based on the dot product attention features of each subdata.
[0050] Optionally, the dot product attention feature of the j-th subdata point can be calculated using the following formula:
[0051]
[0052] Among them, Q j K is the query parameter for the j-th sub-data. j V is the key parameter of the j-th sub-data. j The value parameter for the j-th sub-data. The key parameter K for the j-th sub-data j transpose, This is the scaling factor.
[0053] Optionally, the seizure prediction system based on CNN and self-attention mechanism further includes:
[0054] An alarm unit, connected to the prediction unit, is used to generate alarm information when multiple consecutive time periods are in the pre-seizure phase.
[0055] According to specific embodiments provided by the present invention, the following technical effects are disclosed: S-transformation of the sample channel signal is performed by a first transformation unit, and S-transformation of the EEG signal to be tested is performed by a second transformation unit, thereby improving the calculation speed. An initial prediction neural network is constructed based on a convolutional neural network and a self-attention mechanism; the network has fewer parameters, is faster, and has higher accuracy, thus improving the prediction accuracy and efficiency of epileptic seizures. Attached Figure Description
[0056] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0057] Figure 1 This is a schematic diagram of the module structure of the epileptic seizure prediction system based on CNN and self-attention mechanism of the present invention;
[0058] Figure 2 This is a diagram illustrating data augmentation.
[0059] Figure 3 A diagram illustrating different stages of an epileptic seizure;
[0060] Figure 4 This is a schematic diagram of single-channel S-transform and data dimensionality reduction;
[0061] Figure 5 This is a schematic diagram of the initial prediction neural network structure;
[0062] Figure 6 A schematic diagram for scaling dot product attention;
[0063] Figure 7 This is a diagram illustrating the relationship between warning time and SPH.
[0064] Symbol explanation:
[0065] Sample acquisition unit-1, first transformation unit-2, sample feature matrix determination unit-3, network construction unit-4, training unit-5, signal acquisition unit-6, second transformation unit-7, test feature matrix determination unit-8, prediction unit-9, verification unit-10, post-processing unit-11, alarm unit-12. Detailed Implementation
[0066] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0067] The purpose of this invention is to provide an epileptic seizure prediction system based on CNN and self-attention mechanism. By performing S-transform on the sample channel signals and the EEG signals to be tested, the computation speed is improved. An initial prediction neural network is constructed based on convolutional neural networks and self-attention mechanism, resulting in a network with fewer parameters, higher speed, and higher accuracy, thus improving the prediction accuracy and efficiency of epileptic seizures.
[0068] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0069] like Figure 1 As shown, the epilepsy seizure prediction system based on CNN and self-attention mechanism of the present invention includes: a sample acquisition unit 1, a first transformation unit 2, a sample feature matrix determination unit 3, a network construction unit 4, a training unit 5, a signal acquisition unit 6, a second transformation unit 7, a test feature matrix determination unit 8, and a prediction unit 9.
[0070] The sample acquisition unit 1 is used to acquire a sample dataset. The sample dataset includes EEG signals from multiple patients at multiple historical time periods, along with label information for each sample EEG signal; each sample EEG signal includes sample channel signals from multiple EEG channels. The label information includes 0 and 1, where 0 indicates that the corresponding sample EEG signal is an interictal EEG signal, and 1 indicates that the corresponding sample EEG signal is a preictal EEG signal.
[0071] The first transformation unit 2 is connected to the sample acquisition unit 1. The first transformation unit 2 is used to perform S-transform on the signals of each sample channel for any patient at any time period to obtain the sample feature set corresponding to each sample channel signal. The sample feature set of each sample channel signal includes multiple sample feature values.
[0072] The sample feature matrix determination unit 3 is connected to the first transformation unit 2. The sample feature matrix determination unit 3 is used to determine the sample feature matrix for any patient at any time period based on each sample feature set.
[0073] The network building unit 4 is used to build an initial prediction neural network based on convolutional neural networks and self-attention mechanisms.
[0074] The training unit 5 is connected to the sample feature matrix determination unit 3, the sample acquisition unit 1 and the network construction unit 4 respectively. The training unit 5 is used to train the initial prediction neural network according to the sample feature matrix of each patient at each time period and the label information of the sample EEG signal corresponding to each sample feature matrix, so as to obtain the epileptic seizure prediction model.
[0075] The signal acquisition unit 6 is used to acquire the EEG signals to be tested from multiple EEG channels of the patient in real time during the current period.
[0076] The second transformation unit 7 is connected to the signal acquisition unit 6. The second transformation unit 7 is used to perform S-transform on each EEG signal to be tested to obtain the feature set corresponding to each EEG signal to be tested.
[0077] The feature matrix determination unit 8 is connected to the second transformation unit 7. The feature matrix determination unit 8 is used to determine the feature matrix of the current time period based on each feature set to be measured.
[0078] The prediction unit 9 is connected to the training unit 5 and the test feature matrix determination unit 8 respectively. The prediction unit 9 is used to determine whether the current time period is the pre-seizure stage based on the epileptic seizure prediction model and the test feature matrix.
[0079] This invention uses only the S-transform to process the raw EEG signal, and uses the block sum of the S-transformed time-frequency matrix as the sole input feature of the neural network. The S-transform has the advantages of both the short-time Fourier transform and the wavelet transform; its window length can be varied with scale, enabling multi-scale time-frequency domain signal analysis. It can be implemented using the fast Fourier transform algorithm, thus greatly accelerating the computation speed.
[0080] Furthermore, an initial prediction neural network is constructed based on convolutional neural networks and the self-attention mechanism. This network has fewer parameters, is faster, and can improve the real-time performance of epileptic seizure prediction. It also has high accuracy and strong generalization ability, which can improve the accuracy of epileptic seizure prediction.
[0081] Furthermore, the sample acquisition unit 1 includes: an initial sample acquisition module, a slicing module, and a labeling module.
[0082] The initial sample acquisition module is used to acquire initial sample channel signals from multiple EEG channels of multiple patients over a continuous historical period.
[0083] In this embodiment, the initial sample acquisition module acquires the CHB-MIT scalp EEG database. Eighteen common EEG channels (FP1-F7, F7-T7, T7-P7, P7-O1, FP1-F3, F3-C3, C3-P3, P3-O1, FP2-F4, F4-C4, C4-P4, P4-O2, FP2-F8, F8-T8, T8-P8, P8-O2, FZ-CZ, CZ-PZ) shared by all patients are selected. EEG data from the pre-ictal period that is less than 30 minutes continuous are spliced and filled in.
[0084] Since interictal data is far more abundant than preictal data, preictal EEG data was extracted first. The CHB-MIT scalp EEG database contains 9 to 42 consecutive .edf files per patient. Hardware limitations cause gaps between consecutively numbered .edf files, during which no signals were recorded. Therefore, preictal EEG data with a continuous 30 minutes was extracted first. For gaps in the data that were less than 30 minutes continuous, the data was first stitched back along the timeline, and then the interrupted periods were filled in with the corresponding extracted 30-minute continuous EEG data to achieve continuity.
[0085] For example, in the chb21_19.edf file of patient chb21, the epileptic seizure began at 1288 seconds, which, according to the definition of preictal seizure, is less than 30 minutes continuous. Since the temporal relationships between the files belonging to each case in the CHB-MIT scalp EEG database have been preserved, the files in chb21_18.edf are spliced together. However, 7 seconds of data are lost between chb21_18.edf and chb21_19.edf. This 7-second data is extracted from an already extracted preictal seizure segment (e.g., chb21_21.edf) between [1288-7:1288] seconds, and then spliced against the timeline to the 505-second data in chb21_18.edf. At this point, the preictal data ([505+7+1288] seconds) in the chb21_19.edf file is complete. Figure 2 As shown.
[0086] Regarding the prediction of epileptic seizures, experts will annotate the data during the seizure period. For example... Figure 3 As shown, the preictal period is defined as the continuous 30 minutes before a seizure, the postictal period is defined as the 5 minutes after the end of the seizure, and the remaining time period is the interictal period. For the EEG data during the interictal period, an equal number of consecutive 30-minute EEG data points were randomly selected to balance the data.
[0087] Specifically, when collecting EEG data, the electrodes on the scalp were positioned according to the international 10-20 standard, and the sampling frequency was 256Hz.
[0088] The slicing module is connected to the initial sample acquisition module. The slicing module is used to slice the initial sample channel signal of any patient's EEG channel according to a set time interval, obtaining sample channel signals for multiple time periods corresponding to the EEG channel; the sample channel signals of the same time period are the sample EEG signals of the corresponding time period. In this embodiment, the set time interval is 6 seconds.
[0089] Specifically, the EEG data during the interictal and preictal periods were sliced into non-overlapping segments of 6 seconds each. The 30-minute EEG data was divided into 300 small samples of 6-second segments, resulting in 300 sample channel signals for different time periods.
[0090] The annotation module is connected to the slicing module. The annotation module is used to annotate the EEG signals of each patient at each time period and determine the label information corresponding to each sample EEG signal.
[0091] Furthermore, the transformation unit includes: an S-transformation module, a partitioning module, and a sample feature set determination module.
[0092] The S-transform module is connected to the sample acquisition unit 1. The S-transform module is used to perform S-transform on the signals of each sample channel for any patient at any time period, transforming the signals of each sample channel from the time domain to the time-frequency domain, and obtaining the time-frequency matrix corresponding to each sample channel signal.
[0093] Electroencephalogram (EEG) signals are typical non-stationary signals, and the statistical information they contain is random at different times. Therefore, EEG signals contain a large amount of information, requiring a high-resolution signal processing method. In epileptic seizure prediction, not only the accuracy of the prediction but also its real-time performance, i.e., the execution time of the algorithm, must be considered. When exploring EEG signals, feature extraction is the first step. Currently, the commonly used time-frequency domain feature extraction method, Short-Time Fourier Transform (SFT), has a fixed window width across all frequencies, which may not provide sufficient frequency resolution at high frequencies. The S-transform inherits the advantages of the SFT, such as fast computation speed, and also inherits the multi-scale resolution advantage of the wavelet transform. Therefore, this invention uses the S-transform for time-frequency feature extraction.
[0094] The S-transform uses a Gaussian window to window and limit the time-domain signal, achieving sufficient frequency resolution at low frequencies and sufficient time resolution at high frequencies. Algorithmically, the S-transform can be used to derive results on a computer using the Fast Fourier Transform, meeting the real-time requirements of epilepsy prediction.
[0095] In this embodiment, the S-transform module performs an S-transform on a 6-second segment of the one-dimensional single-channel EEG signal, generating a two-dimensional complex matrix of frequency × time. This transforms the sample channel signal from the time domain to the time-frequency domain. The 6-second segment of the one-dimensional single-channel EEG signal after the S-transform can be represented as: Among them, D s This is a time-frequency matrix, where f represents the frequency (128Hz) and T represents the time period (6 seconds).
[0096] The partitioning module is connected to the S-transform module. The partitioning module is used to divide the time-frequency matrix of the sample channel signal into multiple blocks according to the frequency and time period of the sample channel signal for any sample channel signal of any patient at any time period, and sum the results for each block to obtain multiple sample feature values of the sample channel signal.
[0097] Specifically, after converting the EEG signal from the time domain to the time-frequency domain, the horizontal axis represents 1-6 seconds, and the vertical axis represents 0-128Hz. To filter out artifacts and power frequency interference, a frequency range of 1-50Hz was selected and divided into six frequency bands: delta (1-4Hz), theta (4-8Hz), alpha (8-12Hz), beta (12-30Hz), gamma01 (30-40Hz), and gamma02 (40-50Hz). The 6-second time axis was divided into three equal segments. The time-frequency matrix was then divided into 18 modules. Only the complex real part of each module was taken, and the summation was performed on the entire module. Each module yielded a feature value. Finally, the modules were concatenated in the order of frequency band first, then time, to obtain the sample feature values corresponding to each module, achieving data dimensionality reduction. Figure 4 As shown.
[0098] The sample feature set determination module is connected to the division module. The sample feature set determination module is used to determine the sample feature set of any sample channel signal for any patient at any time period based on multiple sample feature values of the sample channel signal.
[0099] Furthermore, the sample feature matrix determination unit 3 includes: an initial matrix determination module, a calculation module, a standardization module, and a feature matrix determination module.
[0100] The initial matrix determination module is connected to the first transformation unit 2. The initial matrix determination module is used to determine the initial sample feature matrix for any patient at any time period based on the sample feature set. The initial sample feature matrix includes multiple sample feature values.
[0101] Specifically, the 6-second sample channel signal from a single channel is transformed by S-transform and dimensionality reduction to generate 18 feature values. In this embodiment, a total of 18 EEG channels are selected, thus generating an 18×18 initial sample feature matrix F. own :
[0102] The calculation module is connected to the initial matrix determination module, and the calculation module is used to calculate the mean and standard deviation of the initial sample feature matrix for each patient at each time period.
[0103] The standardization module is connected to the calculation module and the initial matrix determination module respectively. The standardization module is used to standardize the sample feature values in the initial sample feature matrix for any patient at any time period, based on the mean and standard deviation of the initial sample feature matrix of the time period, to obtain the corresponding standardized sample feature values.
[0104] Specifically, the i-th sample feature value in the initial sample feature matrix is standardized using the following formula:
[0105]
[0106] in, Let D be the feature value of the i-th standardized sample. i Let D be the feature value of the i-th sample. i ∈F own D mean D is the mean of the initial sample feature matrix. std denoted as the standard deviation of the initial sample feature matrix.
[0107] The feature matrix determination module is connected to the standardization module. The feature matrix determination module is used to determine the sample feature matrix of any time period for any patient based on the standardized sample feature values of each time period.
[0108] Furthermore, the training unit 5 includes: a convolutional neural network, a dimension transformation module, a self-attention module, a fully connected layer, a softmax classifier, and a training module.
[0109] The convolutional neural network is used to extract features from the sample feature matrix of any patient at any time period to obtain three-dimensional feature data.
[0110] Specifically, such as Figure 5 As shown, the convolutional neural network includes a first two-dimensional convolutional layer, a batch normalization layer, a first leaky_reLU activation layer, a max pooling layer, a second two-dimensional convolutional layer, and a second leaky_reLU activation layer connected in sequence. The first two-dimensional convolutional layer has 1 input channel, 16 output channels, and a kernel size of 3. The max pooling layer has a kernel size of 2. The second two-dimensional convolutional layer has 16 input channels, 32 output channels, and a kernel size of 3. The sample feature matrix input to the convolutional neural network is represented as follows: The three-dimensional feature data output by the convolutional neural network is represented as follows:
[0111] The dimension conversion module is connected to the convolutional neural network, and the dimension conversion module is used to convert the three-dimensional feature data into two-dimensional feature data.
[0112] The self-attention module is connected to the dimension transformation module. The self-attention module is used to determine self-attention features based on the two-dimensional feature data and a self-attention mechanism. The two-dimensional feature data input to the self-attention module is represented as follows: The self-attention features output by the self-attention module are represented as follows: That is, the input and output sizes of the self-attention module are the same.
[0113] The fully connected layer is connected to the self-attention module, and the fully connected layer is used to convert the self-attention features into a one-dimensional vector. The model output is set to 2 to achieve binary classification.
[0114] The softmax classifier is connected to the fully connected layer, and the softmax classifier is used to determine the predicted category of the one-dimensional vector. The predicted category is 0 or 1. 0 indicates that the sample EEG signal corresponding to the sample feature matrix is an interictal EEG signal, and 1 indicates that the sample EEG signal corresponding to the sample feature matrix is a preictal EEG signal.
[0115] The training module is connected to the softmax classifier, the sample acquisition unit 1, the convolutional neural network, and the self-attention module. The training module determines a loss function based on the predicted category of the sample feature matrix for each patient at each time period and the corresponding label information of the sample EEG signals. It then adjusts the weights and biases of the convolutional neural network and the weights of the self-attention mechanism according to the loss function until the loss function converges, thus obtaining the optimal predictive neural network. The optimal predictive neural network is the epileptic seizure prediction model.
[0116] Specifically, the self-attention module includes: a data partitioning submodule, a convolutional block, a dot product attention submodule, and a self-attention submodule.
[0117] The data partitioning submodule is connected to the dimension transformation module, and the data partitioning submodule is used to divide the two-dimensional feature data into multiple sub-data.
[0118] The convolutional block is connected to the data partitioning submodule. The convolutional block is used to convolve each sub-data segment to obtain the key parameters, query parameters, and value parameters of each sub-data segment. Specifically, scaled dot product attention is the core part of the self-attention mechanism, mainly including three parameters: Query, Keys, and Values. Figure 6 As shown, the convolutional block consists of three depthwise separable one-dimensional convolutions. Each depthwise separable one-dimensional convolution has 32 input channels, 32 output channels, a kernel size of 1, a stride of 1, zero padding, and 32 groups. Using depthwise separable convolutions can further reduce model parameters.
[0119] The dot-product attention submodule is connected to the convolutional block. The dot-product attention submodule is used to determine the dot-product attention features corresponding to each subdata item based on the key parameters, query parameters, and value parameters of each subdata item. First, similarity is calculated for the query parameters and key parameters to obtain weights. These weights are then normalized to obtain directly usable weights. Finally, the weights and value parameters are summed using a weighted average.
[0120] Specifically, the dot product attention feature of the j-th sub-data is calculated using the following formula:
[0121]
[0122] Among them, Q j K is the query parameter for the j-th sub-data. j V is the key parameter of the j-th sub-data. j The value parameter for the j-th sub-data. The key parameter K for the j-th sub-data j transpose, This is the scaling factor.
[0123] The self-attention submodule is connected to the dot product attention submodule, and the self-attention submodule is used to determine the self-attention features based on the dot product attention features of each subdata.
[0124] The two-dimensional feature data input to the self-attention module is represented as follows: This is essentially a two-dimensional feature map (32×36). This feature map can be subjected to scaled dot product attention as a whole. Alternatively, a certain dimension can be divided into h equal parts. This invention divides the 36-dimensional dimension into 6 parts (6 sub-data points) head, i.e., h is set to 6. Each part is independently subjected to scaled dot product attention, and then the outputs of each part are concatenated together to obtain the self-attention feature.
[0125] That is, given a Q, K, and V matrix, transform them into Q. j K j and V j The final weighted summation of the submatrix (j∈[1,head]) is obtained by concatenating all h weighted summations.
[0126] The self-attention submodule uses the following formula to determine self-attention characteristics:
[0127]
[0128] Among them, MultiHead(Q,K,V) is a self-attention feature.
[0129] In this embodiment, a two-layer multi-head attention mechanism is used, along with residual connections, to improve network performance.
[0130] To enable timely intervention, the epileptic seizure prediction system based on CNN and self-attention mechanisms of this invention also includes an alarm unit 12. The alarm unit 12 is connected to the prediction unit 9 and is used to generate alarm information during multiple consecutive pre-seizure periods.
[0131] Furthermore, the epilepsy seizure prediction system based on CNN and self-attention mechanism of the present invention also includes a verification unit 10. The verification unit 10 is connected to the training unit 5, and is used to verify the performance of the epilepsy seizure prediction model using a K-fold cross-validation method. In K-fold cross-validation, K represents the number of segments of the selected epilepsy seizure.
[0132] To further improve accuracy, the epilepsy seizure prediction system based on CNN and self-attention mechanism of the present invention also includes a post-processing unit 11. The post-processing unit 11 is connected to the prediction unit 9, and the post-processing unit 11 is used to post-process the prediction results.
[0133] In actual epilepsy prediction, EEG signals are generally continuous. The results of the epilepsy seizure prediction model are post-processed. An output of "0" indicates that a 6-second sample is identified as the interictal period, while an output of "1" indicates the preictal period. In this embodiment, a k-of-n post-processing operation is used, where n represents n consecutive small samples, specifically 10 consecutive 6-second samples in this embodiment, or one minute of continuous data; k represents the number of samples identified as "0" (one minute of data is marked as the interictal period if k or more samples are identified as "0"), and vice versa. In this embodiment, k = 5, i.e., a 5-of-10 post-processing operation is used.
[0134] This invention uses a confusion matrix to determine the evaluation indicators. Since accurate prediction of the preictal phase is crucial for epilepsy prediction, the preictal phase is represented by a positive indicator, and the interictal phase by a negative indicator.
[0135] TP (True Positive): A true positive indicates a value that correctly predicts a positive result from actual positive cases.
[0136] FP (False Positive): A false positive indicates an incorrect positive prediction.
[0137] TN (TrueNegative): True negative means that the value correctly predicts a negative value in actual negative cases.
[0138] FN(False Negative): A false negative indicates an incorrect negative prediction.
[0139] The various evaluation indicators are as follows:
[0140]
[0141]
[0142]
[0143]
[0144]
[0145]
[0146] Where A is classification accuracy, P is precision score, R is recall score, S is specificity score, F1 is F1 score, and FPR is false positive rate.
[0147] Results Analysis: The average results of this study, based on 23 patients from the CHB-MIT scalp EEG database, without post-processing, are as follows:
[0148] A: 93.25, P: 92.91, R: 93.67, S: 92.79, F1: 0.9323, FPR: 0.0721 / h.
[0149] The average result after post-processing is:
[0150] A: 97.48, P: 97.48, R: 98.41, S: 96.52, F1: 0.9752, FPR: 0.0348 / h.
[0151] Event-based evaluation metrics
[0152] First, we define the SPH (seizure prediction horizon) and SOP (seizure occurrence period). Based on the previous definitions of the preictal and interictal periods, the SOP is defined as the epileptic seizure period as indicated by experts 30 minutes after the preictal period; the SPH is defined as the period between the predicted alert time and the start time of the SOP. In addition, the SPH is also called the clinical intervention period, during which appropriate measures can be taken to deal with the epileptic seizure.
[0153] For the evaluation metrics, since the post-processing handles consecutive one-minute data points at a time, a 30-minute window is defined, shifting along the time axis with 29-minute overlaps. For every consecutive 30 minutes of data, i.e., for every 30 predictions, the total number of pre-ictal predictions (marked as "1") is divided by 30 to limit the values to [0,1]. A threshold of 0.85 is then used to determine when to issue an alert. In other words, when 26 out of 30 predictions are pre-ictal, an alert is issued immediately after the 26th prediction.
[0154] Warning time and SPH definition as follows Figure 7 As shown. If the warning occurs during the interictal period or during an ictal period, such as SPH② and SPH③, it is considered a false warning. If the warning occurs in the preictal period, such as SPH①, it is considered a correct warning.
[0155] Therefore, for a correct prediction, SPH is between (0, 30); for an incorrect prediction, the first possibility is that the alarm may occur during the interictal period, and the second possibility is that the alarm has not been issued even during the seizure. Therefore, accuracy (also called sensitivity) is defined as:
[0156]
[0157] False alarm rate is defined as:
[0158]
[0159] Sensitivity represents accuracy, and False Alarm represents false alarm rate. For the epilepsy prediction system, which is based on event analysis, the accuracy can reach 96.6%, the false alarm rate is 0.03 / h, and the average SPH is 4 minutes. This means that the prediction system will issue an alarm 4 minutes before an epileptic seizure, which is enough time to take appropriate measures to deal with the seizure.
[0160] This invention converts raw EEG signals into time-frequency signals using a single-channel S-transform; then, the time-frequency signals are compressed and integrated along the time and frequency axes to extract time-frequency features; next, the time-frequency features of 18 channels shared by all patients are fed into an epilepsy seizure prediction model combining CNN and self-attention; finally, post-processing operations are added, and K-fold cross-validation is used to evaluate the model's performance. The event-based epilepsy prediction accuracy reaches 96.6%. After training and saving the optimal epilepsy seizure prediction model, post-processing operations are added, allowing direct discrimination of EEG signals and issuing early warnings at appropriate pre-seizure stages, thus achieving the goal of epilepsy seizure prediction.
[0161] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. Furthermore, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A seizure prediction system based on CNN and self-attention mechanism, characterized in that, The epileptic seizure prediction system based on CNN and self-attention mechanism includes: The sample acquisition unit is used to acquire a sample dataset. The sample dataset includes sample EEG signals from multiple patients at multiple historical time periods and label information for each sample EEG signal. Each sample EEG signal includes sample channel signals from multiple EEG channels. The label information includes 0 and 1, where 0 indicates that the corresponding sample EEG signal is an interictal EEG signal and 1 indicates that the corresponding sample EEG signal is a preictal EEG signal. The first transformation unit is connected to the sample acquisition unit and is used to perform S-transform on the signals of each sample channel for any patient at any time period to obtain the sample feature set corresponding to each sample channel signal. The sample feature matrix determination unit, connected to the first transformation unit, is used to determine the sample feature matrix for any patient at any time period based on each sample feature set. Network building unit, used to construct an initial prediction neural network based on convolutional neural networks and self-attention mechanisms; The training unit is connected to the sample feature matrix determination unit, the sample acquisition unit and the network construction unit respectively. It is used to train the initial prediction neural network based on the sample feature matrix of each patient at each time period and the label information of the sample EEG signal corresponding to each sample feature matrix to obtain the epileptic seizure prediction model. The signal acquisition unit is used to acquire the EEG signals of the patient in multiple EEG channels in real time during the current period; The second transformation unit is connected to the signal acquisition unit and is used to perform S-transformation on each EEG signal to be tested to obtain the feature set corresponding to each EEG signal to be tested. The feature matrix determination unit is connected to the second transformation unit and is used to determine the feature matrix to be measured in the current time period based on each feature set to be measured. The prediction unit is connected to both the training unit and the test feature matrix determination unit, and is used to determine whether the current time period is the pre-seizure phase based on the epileptic seizure prediction model and the test feature matrix.
2. The CNN and self-attention mechanism based seizure prediction system according to claim 1, wherein, The sample acquisition unit includes: The initial sample acquisition module is used to acquire initial sample channel signals from multiple EEG channels of multiple patients within a continuous historical time period; The slicing module, connected to the initial sample acquisition module, is used to slice the initial sample channel signal of any patient's EEG channel at a set time interval to obtain sample channel signals of multiple time periods corresponding to the EEG channel; the sample channel signal of the same time period is the sample EEG signal of the corresponding time period. The annotation module, connected to the slicing module, is used to annotate the EEG signals of each patient at each time period and determine the label information corresponding to each sample EEG signal.
3. The CNN and self-attention mechanism based seizure prediction system according to claim 1, wherein, The transformation unit includes: The S-transform module, connected to the sample acquisition unit, is used to perform S-transform on the signals of each sample channel for any patient at any time period, transforming the signals of each sample channel from the time domain to the time-frequency domain, and obtaining the time-frequency matrix corresponding to each sample channel signal. The partitioning module, connected to the S-transform module, is used to divide the time-frequency matrix of the sample channel signal into multiple blocks according to the frequency and time segment of the sample channel signal for any sample channel signal of any patient at any time period, and sum the results for each block to obtain multiple sample feature values of the sample channel signal. The sample feature set determination module, connected to the segmentation module, is used to determine the sample feature set of any sample channel signal for any patient at any time period based on multiple sample feature values of the sample channel signal.
4. The epileptic seizure prediction system based on CNN and self-attention mechanism according to claim 1, characterized in that, Each sample channel signal's sample feature set includes multiple sample feature values; The sample feature matrix determination unit includes: An initial matrix determination module, connected to the first transformation unit, is used to determine an initial sample feature matrix for any patient at any time period based on each sample feature set; the initial sample feature matrix includes multiple sample feature values. The calculation module, connected to the initial matrix determination module, is used to calculate the mean and standard deviation of the initial sample feature matrix for each patient at each time period. The standardization module is connected to the calculation module and the initial matrix determination module respectively. It is used to standardize the sample feature values in the initial sample feature matrix for any patient at any time period based on the mean and standard deviation of the initial sample feature matrix for that time period, so as to obtain the corresponding standardized sample feature values. The feature matrix determination module, connected to the standardization module, is used to determine the sample feature matrix for any patient at any time period based on the standardized sample feature values of each time period.
5. The epileptic seizure prediction system based on CNN and self-attention mechanism according to claim 4, characterized in that, The following formula is used to standardize the i-th sample feature value in the initial sample feature matrix: in, Let D be the feature value of the i-th standardized sample. i Let D be the feature value of the i-th sample. mean D is the mean of the initial sample feature matrix. std denoted as the standard deviation of the initial sample feature matrix.
6. The epileptic seizure prediction system based on CNN and self-attention mechanism according to claim 1, characterized in that, The training unit includes: A convolutional neural network is used to extract features from a sample feature matrix of any patient at any time period to obtain three-dimensional feature data. A dimension conversion module, connected to the convolutional neural network, is used to convert the three-dimensional feature data into two-dimensional feature data; The self-attention module, connected to the dimension transformation module, is used to determine self-attention features based on the two-dimensional feature data and a self-attention mechanism. A fully connected layer, connected to the self-attention module, is used to convert the self-attention features into a one-dimensional vector; A softmax classifier, connected to the fully connected layer, is used to determine the predicted category of the one-dimensional vector; the predicted category is 0 or 1; 0 indicates that the sample EEG signal corresponding to the sample feature matrix is an interictal EEG signal, and 1 indicates that the sample EEG signal corresponding to the sample feature matrix is a preictal EEG signal. The training module, connected to the softmax classifier, the sample acquisition unit, the convolutional neural network, and the self-attention module, is used to determine the loss function based on the predicted category of the sample feature matrix of each patient at each time period and the corresponding label information of the sample EEG signal. The module then adjusts the weights and biases of the convolutional neural network and the weights of the self-attention mechanism according to the loss function until the loss function converges to obtain the optimal prediction neural network. The optimal prediction neural network is the epileptic seizure prediction model.
7. The epileptic seizure prediction system based on CNN and self-attention mechanism according to claim 6, characterized in that, The self-attention module includes: A data partitioning submodule, connected to the dimension transformation module, is used to divide the two-dimensional feature data into multiple sub-data. The convolutional block, connected to the data partitioning submodule, is used to perform convolution on each sub-data to obtain the key parameters, query parameters, and value parameters of each sub-data. The dot product attention submodule, connected to the convolutional block, is used to determine the dot product attention features corresponding to each sub-data based on the key parameters, query parameters, and value parameters of each sub-data. The self-attention submodule, connected to the dot product attention submodule, is used to determine the self-attention features based on the dot product attention features of each subdata.
8. The epileptic seizure prediction system based on CNN and self-attention mechanism according to claim 7, characterized in that, The dot product attention feature of the j-th subdata point is calculated using the following formula: Among them, Q j K is the query parameter for the j-th sub-data. j V is the key parameter of the j-th sub-data. j The value parameter for the j-th sub-data. The key parameter K for the j-th sub-data j transpose, This is a scaling factor.
9. The epileptic seizure prediction system based on CNN and self-attention mechanism according to claim 1, characterized in that, The seizure prediction system based on CNN and self-attention mechanism also includes: An alarm unit, connected to the prediction unit, is used to generate alarm information when multiple consecutive time periods are in the pre-seizure phase.