Neural Network Modeling and Inference Method for Attention State Recognition Based on EEG Sequences
The neural network model addresses the limitations of existing EEG methods by employing wavelet transform, spatial convolution, and attention mechanisms to enhance attention state recognition in EEG data, achieving improved accuracy and robustness in individual adaptation and transitional state identification.
Patent Information
- Application Number
- CN202510608088.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-13
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2045-05-13
AI Technical Summary
The prior art has limited modeling capabilities in the identification of attention states of EEG signals, insufficient adaptability to individual differences, insensitive to transition state recognition, and lacks dynamic feedback mechanisms, which affects the generalization ability and practicality of the model.
Wavelet transformation is used to process the EEG time series signal, extract multi-scale frequency domain information, and feature extraction is performed through spatial convolution, gated cyclic units and residual connection structures of multi-channel convolutional recurrent neural network model, combining cross-time step attention mechanism and dynamic loss function adjustment to improve the recognition accuracy of attention state.
It significantly improves the accuracy of identification of attention states and generalizes the model, enhances the sensitivity of identification of transition states, interpretability and system robustness of classification results.
Smart Images

Figure CN120123752B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer systems based on a specific computational model, and particularly to a neural network modeling and reasoning method for attention state recognition based on electroencephalogram (EEG) sequences. Background Art
[0002] In the prior art, electroencephalogram (EEG) signals, as an important physiological data form reflecting human brain activities, have been widely used in fields such as attention state recognition, fatigue monitoring, and cognitive assessment. Related research usually adopts machine learning methods or shallow neural network models to classify preprocessed EEG features to achieve the judgment of an individual's attention level. Some methods construct input features by combining frequency domain analysis, time domain statistical features, or power spectral density, etc., and are supplemented with classifiers such as support vector machines (SVMs) and random forests (RFs) to complete the state recognition task.
[0003] However, the prior art generally has problems such as limited modeling ability, insufficient adaptability to individual differences, and insensitivity to the recognition of transitional states. Especially when processing EEG time series, many methods fail to effectively utilize its continuity and spatial distribution information, resulting in insufficient feature expression and unstable classification effects. In addition, there is a lack of a dynamic feedback mechanism during the training process, and it is unable to adaptively adjust the optimization strategy according to the recognition difficulty, which affects the generalization ability and practicality of the model.
[0004] In view of this, there is an urgent need to propose an EEG signal processing and reasoning method based on a specific computational model to more fully explore the spatio-temporal features and individual differences of EEG time series. Summary of the Invention
[0005] The present application provides a neural network modeling and reasoning method for attention state recognition based on EEG sequences to improve the accuracy of attention state recognition.
[0006] The present application provides a neural network modeling and reasoning method for attention state recognition based on EEG sequences, including:
[0007] Performing wavelet transform processing on the sampled EEG time series signal to extract sub-band signals of different frequency bands and obtain frequency domain information with multi-scale resolution;
[0008] Performing time-frequency domain feature extraction on the sub-band signals, and encoding the extracted features into a multi-dimensional input tensor with channel embedding vectors according to the distribution positions of each channel in the scalp space;
[0009] Input the multi-dimensional input tensor into a multi-channel convolutional recurrent neural network model composed of a spatial convolutional unit, a gated recurrent unit, and a residual connection structure. The spatial convolutional unit is used to extract spatial correlation features between different channels, the gated recurrent unit is used to learn the evolution law of time series features, and the residual connection structure is used to alleviate the problem of gradient disappearance during the training of deep networks;
[0010] During the model training process, introduce a cross-time-step attention mechanism to weight and adjust the feature contribution degrees of each time segment, and dynamically adjust the class weight coefficients in the loss function based on the classification confusion degree of the current training batch to enhance the identification sensitivity to the attention transition state;
[0011] After the training is completed, receive target EEG time series data of any length, use the trained neural network model for inference, and output the corresponding attention state classification label and its confidence score value; wherein, the confidence score value is calculated based on the distance between the attention-weighted feature representation and the classification boundary, and is used to quantify the stability and credibility of the classification result.
[0012] The beneficial effects of the technical solution provided by this application include:
[0013] (1) By constructing a deep neural network model integrating spatial convolution, gated recurrent unit, and residual connection structure, it is possible to capture both the spatial dependence relationship between channels and the evolution law of time series, which is significantly better than traditional shallow classifiers, reflecting the technical advantages of the present invention in the design of specific computational model structures and belonging to the deep modeling innovation in the field of intelligent algorithms. (2) By introducing a cross-time-step attention mechanism and combining the dynamic loss weight adjustment strategy based on classification confusion during the training process, the model can focus on key segment features and adapt to the discrimination difficulty between samples, effectively solving the problem of fuzzy classification of intermediate states in the prior art and demonstrating the intelligent regulation ability of the neural network training mechanism. (3) By combining the attention mechanism-weighted feature representation with the classification boundary distance to output a confidence score, it helps the downstream system to make intelligent decision scheduling based on the recognition credibility, enhancing the interpretability of the neural network inference result and the system robustness. Description of the Drawings
[0014] Figure 1 It is a flowchart of a neural network modeling and inference method for attention state recognition based on EEG sequences provided by the first embodiment of this application. Detailed Implementation Manner
[0015] Numerous specific details are set forth in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar generalizations without departing from the connotation of the present application. Therefore, the present application is not limited by the specific implementations disclosed below.
[0016] The first embodiment of the present application provides a method for neural network modeling and reasoning for attention state recognition based on electroencephalogram (EEG) sequences. Please refer to Figure 1 , which is a schematic diagram of the first embodiment of the present application. The following combines Figure 1 to detail a method for neural network modeling and reasoning for attention state recognition based on electroencephalogram (EEG) sequences provided by the first embodiment of the present application.
[0017] Step S101: Perform wavelet transform processing on the EEG time series signal obtained through sampling to extract sub-band signals of different frequency bands and obtain frequency domain information with multi-scale resolution.
[0018] The core of step S101 is to perform wavelet transform processing on the continuously sampled EEG time series signal to obtain sub-band signals with multi-scale frequency domain information. First, the EEG signal is continuously collected by setting a reasonable sampling frequency (such as 256 Hz) to obtain time series data reflecting brain electrical activity. This signal usually comes from multiple electrode channels arranged on the scalp surface, and the data collected by each channel is independent and synchronous, forming an original data matrix containing signals of multiple channels.
[0019] The collected signal contains multiple frequency components, covering from extremely low-frequency delta waves to relatively high-frequency beta or gamma waves. To effectively extract the characteristic information of these different frequency bands, wavelet transform is used to process the original EEG signal. Wavelet transform is a method commonly used in time-frequency analysis, which can decompose the original signal layer by layer from high to low frequency, and each layer corresponds to a specific frequency interval, thus obtaining multiple sub-signals. These sub-signals respectively represent the change trends of the original EEG signal in different frequency bands, and retain the characteristics of the signal in both the time and frequency dimensions.
[0020] In the present invention, a three-layer wavelet decomposition structure is preferably adopted, which can effectively cover the main EEG frequency bands, such as the delta, theta, alpha, and beta bands. In each layer, the signal is decomposed into an approximate signal representing the low-frequency trend and a detailed signal representing the high-frequency details, and the iteration is performed layer by layer until the set decomposition depth is reached. The result of such processing is a set of sub-band signals with shortened time lengths and different frequency distributions.
[0021] After wavelet decomposition is completed, to unify the data scale and enhance the convergence of subsequent models, it is recommended to normalize each sub-band signal. For example, the overall amplitude of each sub-band signal can be adjusted to a certain fixed range, or the DC offset and energy fluctuations can be removed, so that the signals in all frequency bands have a unified numerical feature standard, facilitating the subsequent processing of the neural network.
[0022] In summary, step S101 obtains a set of sub-band signals with clear spectral distribution and good time resolution by performing wavelet transform and normalization on the original EEG time series signal, laying a solid foundation for feature extraction and neural network modeling in subsequent steps. This processing method not only retains the multi-frequency information in the EEG signal but also enhances the model's ability to recognize complex attention states, which is a preprocessing step for intelligent computing.
[0023] Furthermore, the wavelet transform processing of the EEG time series signal obtained by sampling to extract sub-band signals in different frequency bands and obtain frequency domain information with multi-scale resolution includes:
[0024] After receiving the EEG time series signal, based on a predefined frequency sensitivity mapping function, determine the target frequency band group associated with the current task, and select the wavelet basis function with the strongest adaptability as the mother wavelet for wavelet transform of the current sample according to the response entropy difference of each frequency band group to the change of attention state in the training sample. The frequency sensitivity mapping function is obtained by analyzing the discriminant information gain of the attention state annotation samples in the training set in each sub-frequency band and is used to guide the wavelet function to match the feature expression structure;
[0025] Perform multi-scale decomposition on the EEG time series signal using the selected wavelet basis function, generating five types of sub-band signals including waves, waves, waves, waves, and waves. Introduce a band-pass energy gating operation for each type of sub-band signal to filter out low-amplitude non-significant frequency bands, output an enhanced sub-band signal set, and use the enhanced sub-band signal set as the frequency domain information with multi-scale resolution;
[0026] Input the enhanced sub-band signal set into the time-frequency feature extraction module, and construct a frequency band-channel weight matrix based on the average energy density and channel signal-to-noise ratio of each sub-band. The frequency band-channel weight matrix is used to weight the expression ratio of different sub-band signals in the multi-channel structure, constituting a time-frequency feature tensor reflecting the spatial heterogeneity of frequency bands.
[0027] Use the time-frequency feature tensor as the basic input for constructing a multi-dimensional input tensor and input it into the multi-channel convolutional recurrent neural network model composed of a spatial convolutional unit, a gated recurrent unit, and a residual connection structure, to enhance the attention transition sensitivity of feature expression and the channel heterogeneity modeling ability.
[0028] In this embodiment, before the electroencephalogram time series signal enters the deep neural network model, it needs to go through a process of extracting multi-scale frequency domain features to improve the sensitivity and discrimination ability of the model to changes in the attention state. This processing flow performs time-frequency analysis on the original electroencephalogram signal based on the wavelet transform method, aiming to obtain a set of sub-band signals with high resolution and multi-band structure, and optimizes the selection of wavelet functions and their decomposition strategies through multiple information guidance mechanisms.
[0029] First, when the system receives the original electroencephalogram time series signal, it will call a pre-constructed frequency sensitivity mapping function to screen the frequency band range required for focusing on the current task. This mapping function is constructed by statistically analyzing the discriminant information gain of samples with attention state labels in each frequency band in the training set. The calculation method of information gain can refer to the principle of information entropy difference, that is, calculate the mutual information between the spectral features of samples in each frequency band and their labels, and use it to quantify the discriminant contribution degree of this frequency band to the classification task. According to the results of this function, the system will select several target frequency band groups that are most informative for the current classification task.
[0030] After determining the target frequency bands, the system will further analyze the response entropy of the samples corresponding to these frequency bands, that is, evaluate the stability and concentration of the attention state discrimination of the samples in this frequency band. Among all available wavelet basis function libraries (such as Daubechies, Symlet, Coiflet, etc.), the system combines multiple indicators such as frequency coverage, time domain compactness, and computational stability, and selects a wavelet basis function that is most suitable for the current frequency band expression as the mother wavelet. This wavelet basis function will be used as the mother function in the wavelet decomposition process of the current sample to ensure that the signal has stronger feature retention ability in the frequency focusing area.
[0031] Subsequently, the system performs multi-scale decomposition on the original EEG time series using the selected wavelet basis function. This process unfolds the original signal at different scales, generating several sub-band signals covering from low frequency to high frequency, typically including standard EEG frequency bands such as delta waves (0.5–4 Hz), theta waves (4–8 Hz), alpha waves (8–13 Hz), beta waves (13–30 Hz), and gamma waves (30–100 Hz). During this process, the system further introduces a band-pass energy gating operation to perform energy statistics on each sub-band signal and sets a gating threshold to filter out frequency components with signal intensity significantly lower than the baseline. This operation can be achieved by comparing the local energy with the global average energy and setting a dynamic threshold, with the aim of removing noise-dominated frequency bands and outputting an enhanced set of sub-band signals with a clearer structure.
[0032] The above-mentioned enhanced set of sub-band signals is input into the subsequent time-frequency feature extraction module. In this module, the system constructs a frequency band-channel weight matrix based on the average energy density exhibited by each sub-band across different channels and the signal-to-noise ratio (SNR) index in the historical record. The energy density reflects the stable activation degree of the signal in a specific channel for a certain frequency band, and the SNR reflects the reliability of the signal in that channel. After normalization, the two indices are combined into a weight factor to form a matrix structure for weighted fusion between different frequency bands across channels. This matrix will be applied to the structural construction process of the sub-band signals, generating a set of tensors that reflect the spatial heterogeneity of the frequency bands and the distribution state of the signal characteristics, called time-frequency feature tensors. This frequency band-channel weight matrix can be simply understood as a two-dimensional table, where each row corresponds to a frequency band, such as delta waves, theta waves, alpha waves, beta waves, gamma waves, etc., and each column corresponds to an EEG channel, such as standard electrode positions like F3, F4, C3, C4, Pz, etc. Each element in the matrix is a weight value, indicating the importance of that frequency band in that channel. These weight values are obtained by combining two factors: one is how strong the overall energy of that frequency band is in that channel, and the other is whether the signal quality in that channel has been stable historically, such as whether there is too much noise. The system will normalize and mix these two indices to obtain a final weight. The larger the weight value, the more important that channel is for the recognition of the attention state in that frequency band.
[0033] Finally, this time-frequency feature tensor is input as a structural input into the backbone structure of the neural network, namely a multi-channel convolutional recurrent neural network model composed of spatial convolutional units, gated recurrent units, and residual connection structures. Since the construction of this tensor fully encodes task-related information in both the frequency dimension and the channel dimension, it can effectively enhance the network's response ability to the attention state transition interval, improve the expression and understanding of the feature heterogeneity between channels, and thus provide a feature input basis with a clear structure and strong discriminative ability for the final inference process.
[0034] The implementation process of the frequency sensitivity mapping function is as follows. During the training phase, the system sequentially performs multi-band decomposition on all labeled samples and initially divides them into standard EEG frequency bands such as and so on. Within each frequency band, statistical features such as energy density, spectral entropy, and power center are extracted, and a shallow classifier (such as a linear support vector machine or a lightweight neural network) is trained using these features in that frequency band to estimate its classification performance within that frequency band. The system then calculates the output entropy difference or mutual information gain between different classes of this classifier and sorts all frequency bands. This sorting result constitutes the frequency sensitivity mapping function, and its output is a set of values corresponding to the discriminative efficacy scores of each frequency band. The higher the score of a frequency band, the more sensitive its spectral structure is to changes in the attention state, that is, it contains more discriminative neural activity signals. With the frequency sensitivity scores, the system then selects a set of target frequency bands with the most discriminative value based on this. After that, to match the spectral characteristics of these frequency bands, the system will select the most suitable mother wavelet function from a preset wavelet basis function library. To achieve a scientific and reasonable selection, the system needs to evaluate each candidate wavelet function in three dimensions: frequency coverage, time-domain compactness, and computational stability.
[0035] Frequency coverage represents the fitting ability of the wavelet function to the target frequency band in the frequency domain, that is, whether its main frequency energy band covers and focuses on the sensitive frequency band of the current task. The evaluation method can be to perform a Fourier transform on the spectral response of the wavelet function to obtain the main energy frequency band interval and evaluate the intersection coverage rate with the task frequency band. Time-domain compactness reflects the local concentration characteristics of the wavelet function on the time axis. The higher the compactness, the easier it is for the wavelet function to capture instantaneous local features and be more sensitive to sudden EEG state switches. This index is usually measured by calculating the non-zero support width or the length of the energy concentration interval of the wavelet function on the time axis. The narrower the support, the higher the time-domain compactness.
[0036] Computational stability focuses on whether the wavelet function is prone to abnormal behaviors such as edge effects, singular values, or numerical overflows during actual decomposition. This index can be estimated by recording the error distribution and numerical stability (such as the maximum coefficient value range, boundary leakage degree) in a large number of wavelet decomposition experiments of samples. Usually, smoother wavelets (such as Symlet) are more stable than Daubechies, but their frequency focusing ability may be relatively weak. After each wavelet function is scored under these three types of indexes, the system will comprehensively normalize these scores, sort them according to the weighted scores, and select the function with the highest score as the mother wavelet for wavelet transform of the current EEG sample. In actual engineering implementation, this score can adopt a weight combination method, for example, 40% for frequency coverage, 30% for time-domain compactness, and 30% for computational stability, to reconcile the importance of each dimension.
[0037] The selected mother wavelet will be used to perform multi-scale wavelet decomposition on the EEG time series and extract sub-band signals covering multiple frequency bands from δ to γ. This process combines task adaptability analysis and function adaptability search, thereby achieving signal enhancement based on classification requirements optimization in the frequency domain decomposition stage, laying a solid foundation for subsequent channel modeling and neural network reasoning.
[0038] Step S102: extracting time-frequency domain features from the sub-band signals, and encoding the extracted features into a multi-dimensional input tensor with channel embedding vectors according to the distribution position of each channel in the scalp space.
[0039] In step S102, the sub-band signals of each frequency band obtained after the wavelet transform processing will be used as the basis for feature extraction. It is necessary to further explore its discriminative features in the time-frequency dimension, and encode it in combination with the spatial layout of the EEG channel on the scalp surface, and finally generate a multi-dimensional input tensor that can be processed by the neural network. The core goal of this step is to organically integrate the multi-frequency bands, time continuity and spatial distribution information in the EEG signal, and construct structured input data to support the training and reasoning of subsequent deep models.
[0040] First, for each subband signal, common time-frequency domain feature parameters including but not limited to short-time energy, spectral entropy, root mean square amplitude, bandwidth center frequency, instantaneous phase, etc. can be extracted. The sliding time window method can be used to locally intercept the signal, and the corresponding statistical eigenvalues are calculated in each window to ensure that the dynamic changes of the EEG signal can be characterized. This window processing method can form a feature vector in each time slice, describing the activity pattern of the time period within a specific frequency range. It is usually recommended to set the window length to 256 milliseconds and the step size to 64 milliseconds to obtain sufficient frequency domain stability while ensuring time resolution.
[0041] Next, the channel position information is introduced into the extracted feature vector. Since the spatial distribution of EEG acquisition channels has a certain physiological correspondence, for example, the F3, F4, Pz and other electrodes in the international 10-20 system correspond to different areas of the cerebral cortex, which directly affects the spatial dependency structure of the EEG signal, it is necessary to encode the channel position into an embedding vector that can be used for model calculation. For example, the channel number can be mapped to a fixed-dimensional spatial position vector, or an embedding representation that reflects the spatial adjacency relationship can be constructed using methods such as Gaussian position mapping, so that the model can explicitly perceive the physical distance and topological structure between different channels.
[0042] Finally, the time series features extracted based on frequency bands are fused with the channel embedding vectors to form a structured three-dimensional input tensor, whose dimensions can be set as "number of time steps × number of channels × feature dimension". Among them, the number of time steps represents the number of consecutive segments segmented in a sliding window manner, the number of channels corresponds to the number of acquisition electrodes, and the feature dimension includes all the extracted time-frequency features and channel embedding vectors. The constructed tensor can be directly used as the input of a deep neural network, ensuring that the input data not only retains the spectral information and temporal structure but also encodes the spatial topological relationship, thus providing a basis for subsequent spatial convolution and recurrent modeling.
[0043] Through this processing process, the original EEG signals are transformed from unstructured one-dimensional time series into high-dimensional input data that integrates temporal, frequency-domain, and spatial information, greatly improving the neural network's ability to model the differences in attention states and effectively supporting the implementation path of the neural network modeling and inference method in the present invention.
[0044] Furthermore, the time-frequency domain feature extraction of the sub-band signals and encoding the extracted features into a multi-dimensional input tensor with channel embedding vectors according to the distribution positions of each channel in the scalp space includes:
[0045] Convert the distribution position of each channel in the scalp space into a three-dimensional Cartesian coordinate form, and construct a channel space adjacency matrix based on this three-dimensional coordinate to reflect the physical proximity relationship between channels;
[0046] Input the channel space adjacency matrix as the edge connection weight of the graph structure into the graph convolutional network. The graph convolutional network takes the frequency-domain features of each channel as the initial node input, performs graph embedding modeling on each channel feature, and generates the first channel embedding vector that fuses the channel time-frequency response and spatial structure;
[0047] Based on the average signal-to-noise ratio and power intensity index of each channel in the target sub-band frequency band recorded during the training stage, extract the feature quality descriptor of this channel in this frequency band and encode it into a group of spectral characteristic vectors;
[0048] Fuse the first channel embedding vector and the corresponding spectral characteristic vectors in dimension to form a second channel embedding vector that contains multimodal representation contents such as spatial position information, frequency-domain response structure, and signal-to-noise characteristics, and use this second channel embedding vector as the basis for representing each channel dimension in the construction of the multi-dimensional input tensor to enhance the neural network structure's ability to model channel heterogeneity and task-related features in the subsequent stage.
[0049] In this embodiment, in-depth modeling is carried out for the differential and structural characteristics of each channel in the electroencephalogram (EEG) time series signal. To construct a multi-dimensional input tensor with high expression ability, a method for constructing an embedding vector that fuses channel spatial position, time-frequency characteristics, and signal-to-noise information is proposed. First, using the actual geometric arrangement of each EEG channel on the acquisition cap or electrode array, the position of each channel is projected into three-dimensional Cartesian coordinates. For example, its three-dimensional coordinate values are obtained through scalp normalization grid or polar coordinate transformation in the international 10-20 system. Based on the Euclidean distance between all channel coordinates, a preset distance threshold or Gaussian kernel function is used to construct the spatial adjacency matrix between channels, so as to quantitatively describe the physical proximity relationship between each channel and other channels, thereby constituting the graph adjacency weight reflecting the channel topology structure.
[0050] After that, this channel spatial adjacency matrix is used as the structural input of the graph convolutional network to control the edge connection relationship in the graph convolutional operation. In the graph convolutional network, the frequency-domain sub-band features obtained after the aforementioned wavelet transform for each channel are used as the initial graph node features for input, and the node dimension is the same as the sub-band feature dimension. The graph convolutional operation realizes the feature propagation and fusion between channels through the connection weights defined by the adjacency matrix, captures the local and global patterns that influence each other in the physical space in the channel frequency spectrum structure, and thus obtains the first channel embedding vector that fuses the channel time-frequency characteristics and spatial position relationship. This embedding vector retains the response pattern of the original channel in a specific frequency band and introduces spatial coupling information, which helps the subsequent network to accurately identify the EEG signal characteristics under different spatial structures.
[0051] After the graph embedding is generated, to further improve the task sensitivity of the embedding representation, hierarchical information of spectral characteristics is introduced to encode the quality of each channel. Specifically, during the training stage, the signal-to-noise ratio (SNR) and average power of each channel in the selected sub-band frequency band are recorded and normalized to generate a spectral characteristic vector representing the signal quality of the channel in this frequency band. This spectral characteristic vector can contain multiple dimensions, including but not limited to indicators such as the maximum spectral amplitude, the central energy density distribution of the frequency band, and the power spectrum entropy, and they are vectorized and encoded.
[0052] Finally, the first-channel embedding vector is concatenated and fused with its corresponding spectral feature vector in the feature dimension to form the second-channel embedding vector. This vector not only contains the spatial structure relationship and spectral response, but also further introduces factors such as channel stability and information credibility, constituting a multi-modal composite embedding representation. This second-channel embedding vector is then used to construct the channel dimension representation in the final multi-dimensional input tensor. All time-step inputs for each channel will share this vector as the spatial embedding basis, which is used to enhance the neural network model's ability to model channel heterogeneity features and the basis for channel weight inference in the attention mechanism, thereby improving the accuracy of cross-channel contrast judgment and state recognition in subsequent models. This structure not only performs structural prior encoding on the input data, but also provides a basis for channel-level feature confidence adjustment, which helps to improve the model's robustness and generalization ability to local abnormal channels. The following is the reference implementation code:
[0053] import numpy as np
[0054] import torch
[0055] import torch.nn as nn
[0056] import torch.nn.functional as F
[0057] # -------- 1. Define the graph convolution unit (for channel embedding) --------
[0058] class GraphConvolution(nn.Module):
[0059] def __init__(self, in_features, out_features):
[0060] super(GraphConvolution, self).__init__()
[0061] self.linear = nn.Linear(in_features, out_features)
[0062] def forward(self, x, adj):
[0063] x: Initial channel features [num_channels, in_features]
[0064] adj: Channel adjacency matrix [num_channels, num_channels]
[0065] support = self.linear(x) # Linear transformation
[0066] out = torch.matmul(adj, support) # Graph convolution propagation
[0067] return out
[0068] # -------- 2. Build channel spatial adjacency matrix --------
[0069] def build_channel_adjacency(channel_coords, sigma=1.0):
[0070] The input is the three-dimensional Cartesian coordinates of each channel, and constructs the adjacency matrix between channels.
[0071] channel_coords: numpy array, shape [num_channels, 3]
[0072] num_channels = channel_coords.shape[0]
[0073] adj = np.zeros((num_channels, num_channels))
[0074] for i in range(num_channels):
[0075] for j in range(num_channels):
[0076] if i != j:
[0077] dist = np.linalg.norm(channel_coords[i] - channel_coords[j])
[0078] adj[i, j] = np.exp(-dist ** 2 / (2 * sigma ** 2)) # Gaussian kernel weighting
[0079] adj = torch.FloatTensor(adj)
[0080] return adj
[0081] # -------- 3. Build multimodal embedding vectors (fusion space + spectral quality) --------
[0082] def build_multimodal_embedding(gcn_output, spectral_descriptors):
[0083] Concatenate the graph convolution output and spectral quality descriptors to form a multimodal embedding.
[0084] gcn_output: [num_channels, gcn_dim]
[0085] spectral_descriptors: [num_channels, spectral_dim]
[0086] return torch.cat([gcn_output, spectral_descriptors], dim=1)
[0087] # -------- 4. Channel attention module (for subsequent network) --------
[0088] class ChannelAttention(nn.Module):
[0089] def __init__(self, embedding_dim):
[0090] super(ChannelAttention, self).__init__()
[0091] self.score_fn = nn.Linear(embedding_dim, 1)
[0092] def forward(self, channel_embeddings):
[0093] # Score each channel embedding to obtain normalized attention weights
[0094] scores = self.score_fn(channel_embeddings) # [num_channels,1]
[0095] attention_weights = F.softmax(scores, dim=0) # Normalize attention
[0096] return attention_weights
[0097] # -------- 5. Inference Output Module (Classification + Confidence Score) --------
[0098] class ClassifierWithConfidence(nn.Module):
[0099] def __init__(self, input_dim, num_classes):
[0100] super(ClassifierWithConfidence, self).__init__()
[0101] self.classifier = nn.Linear(input_dim, num_classes)
[0102] def forward(self, fused_representation):
[0103] logits = self.classifier(fused_representation) # [batch_size, num_classes]
[0104] probs = F.softmax(logits, dim=-1)
[0105] confidence = torch.max(probs, dim=-1).values # Probability of the maximum class as the confidence score
[0106] return probs, confidence
[0107] The above code first receives the three-dimensional coordinates and corresponding spectral features of each channel in the EEG signal as input. In the initial stage, by calculating the three-dimensional geometric distances between channels and using the Gaussian kernel function to transform the distances into connection strengths, a channel spatial adjacency matrix is constructed to reflect the physical proximity relationship between electrodes. This adjacency matrix is fed into the graph convolutional network as a graph structure, together with the frequency-domain features of each channel in a specific frequency band, to jointly generate the first-layer channel embedding representation that fuses spatial structure and spectral response.
[0108] Subsequently, the system further introduces quality description information such as spectral signal-to-noise ratio and power statistically calculated for each channel during the training phase, and encodes them as spectral feature vectors. These vectors are concatenated with the embedding vectors generated by the aforementioned graph convolution to obtain multi-modal channel embedding vectors that simultaneously contain spatial structure, frequency response, and signal quality. Before entering the subsequent network, the model performs weighted scoring on these embedding vectors through a channel attention mechanism to identify the channel features most relevant to the target classification task. The attention weights are normalized and used to perform weighted fusion on all channel embeddings, outputting a fused representation tensor that represents the integrated features of the whole brain region.
[0109] Finally, this fused representation is fed into a fully connected classifier for inference and prediction of the attention state, and the output is the probability distribution of the classification labels and its maximum probability value, with the latter serving as the confidence score for this prediction to measure the reliability of the current output result.
[0110] Step S103: Input the multi-dimensional input tensor into a multi-channel convolutional recurrent neural network model composed of a spatial convolutional unit, a gated recurrent unit, and a residual connection structure. The spatial convolutional unit is used to extract the spatial correlation features between different channels, the gated recurrent unit is used to learn the evolution law of time series features, and the residual connection structure is used to alleviate the problem of gradient disappearance during the training of deep networks.
[0111] In step S103, the multi-dimensional input tensor constructed in the previous stage is input into a neural network model with a specific structure, which is jointly composed of a spatial convolutional unit, a gated recurrent unit, and a residual connection structure. The overall architecture has the ability to simultaneously model the spatial dependence and time dynamic features of EEG signals and can alleviate the training degradation problem caused by the increase in network depth.
[0112] First, the input tensor is fed into the spatial convolution unit. The main function of this unit is to identify the spatial correlation patterns between different channels, that is, to learn the synchronous or cooperative change relationships exhibited by the EEG channels corresponding to each electrode position at different frequency bands. In implementation, the spatial convolution operation is carried out in the "channel dimension", and a two-dimensional convolution kernel is used to perform sliding convolution on the feature vectors of multiple channels, thereby extracting local spatial structure features. The size of the convolution kernel is generally set to 3×1 or 5×1 to ensure capturing the interactions between adjacent channels without disturbing the temporal structure. To enhance the non-linear expression ability, the ReLU activation function can be connected after the convolution operation.
[0113] Subsequently, the extracted spatial feature sequence is input into the gated recurrent unit for modeling the feature evolution law in the time dimension. Specifically, the gated recurrent unit (GRU) or long short-term memory unit (LSTM) structure can be adopted. These recurrent neural network units can effectively handle the forward and backward dependencies in the time series and avoid the problem of gradient vanishing when the sequence is long. In actual operation, the spatial feature vector at each time step is sequentially input into the recurrent unit. After recursive propagation through multiple time steps, the model can learn the change pattern of the attention state over time. It is recommended to set the number of recurrent layers to 1 to 2 layers, and the hidden state dimension should not be less than 128 to balance the modeling ability and training efficiency.
[0114] To further improve the training stability of the deep network and accelerate convergence, a residual connection mechanism is introduced into the model structure. Residual connection means introducing a skip connection between multiple network layers, directly adding the input features of the previous layer to the output of the current layer, thereby constructing a shortcut path of "identity mapping". This structure can effectively prevent the continuous attenuation of gradients in the deep network, enabling the model to maintain good training feasibility when facing high-dimensional input data and complex classification tasks. Residual connection is mainly applied between the recurrent network and the output layer in this model, used to connect the original spatio-temporal features and the high-order extraction results.
[0115] Through the collaborative work of the above structures, the neural network model can perceive and model the internal laws of EEG data at multiple scales, especially the spatio-temporal feature change process corresponding to the attention state. This network structure has been verified by multi-task experiments and has stable, accurate and generalization ability recognition performance, which can provide a solid feature basis for subsequent attention state classification and credibility scoring.
[0116] For example, the entire network model can be divided into three sequentially connected modules: a spatial convolutional unit, a gated recurrent unit, and a residual connection structure. The input data is a three-dimensional tensor collected and processed from EEG channels, with dimensions of "time steps × number of channels × number of features", assumed to be 128 × 32 × 20, indicating that the sample consists of 128 time segments, collected from 32 EEG channels, and each channel contains 20-dimensional frequency domain or spatio-temporal features at each time step.
[0117] First, the input to the spatial convolutional unit is the entire tensor, and convolution is mainly performed in the "channel" dimension. A set of two-dimensional convolutional kernels with a size of 1 × 3 can be selected, that is, for the data at each time step, the feature vectors of adjacent 3 channels are taken for sliding window convolution. The output dimension of the convolution can be set to 64 or 128 channels, indicating the number of spatial features formed after convolution. After the convolution operation, the ReLU function is used to activate the non-linear response, and Batch Normalization is connected to normalize the output, improving the convergence speed. The shape of the convolution output is 128 × 30 × 64 (the number of time steps remains 128, the number of channels after convolution is reduced to 30, and the feature dimension is the number of output channels of the convolution).
[0118] This output is used as a time series input and fed into the gated recurrent unit frame by frame. It is recommended to use a bidirectional GRU structure, and the hidden state dimension of each GRU unit is set to 256. The introduction of the bidirectional structure enables the model to simultaneously perceive the evolution laws of time features in the past and future, improving the context consistency of state judgment. At each time step, the GRU unit receives a 30 × 64-dimensional tensor, unfolds it into a one-dimensional feature vector and inputs it into the network, and the GRU gradually updates the hidden state. After 128 time steps of iteration, the output is a sequence tensor with a dimension of 128 × 512, representing the comprehensive representation of each time step after the fusion of context information before and after.
[0119] To further enhance the model's expressive power, a residual connection is added at the end of the GRU output. The implementation method is as follows: First, perform a dimension transformation on the feature representation before the spatial convolutional unit is input into the GRU (for example, map the original features to the same 512 dimensions as the GRU output through a fully connected layer), and then perform an element-wise addition operation with the GRU output step by step over time to form a sequence output with enhanced residuals. This mechanism not only improves the training stability but also enables the original features to be retained and participate in the final classification in the deep network, helping to improve the model's recognition ability at complex state boundaries.
[0120] Finally, the residual output is input into the attention module or pooling operation, and depending on the subsequent structure, a global context vector is generated, multi-label classification is performed, or a confidence score is output.
[0121] Furthermore, the step of inputting the multi-dimensional input tensor into a multi-channel convolutional recurrent neural network model composed of a spatial convolution unit, a gated recurrent unit, and a residual connection structure includes:
[0122] Based on the multidimensional input tensor, a channel correlation matrix is constructed, where the channel correlation matrix is obtained by calculating the cosine similarity between channel embedding vectors corresponding to different channels in the multidimensional input tensor, and is weighted in combination with the distance information of the channels in the scalp space, so as to reflect the time-frequency feature synergy and spatial neighbor relationship between the channels;
[0123] The channel correlation matrix is used as a parameter to dynamically generate a convolution kernel weight of a spatial convolution unit, wherein the spatial convolution unit performs a two-dimensional convolution operation on the channel dimension of the multidimensional input tensor to extract spatial dependency features between channels and output a spatial correlation feature tensor, wherein the spatial correlation feature tensor enhances cross-channel coupling structure information based on the original multidimensional input tensor;
[0124] The spatial correlation feature tensor is input into a gated recurrent unit, which adopts a gated recurrent structure to recursively process the spatial correlation feature tensor of each time step, and introduces a channel attention gating mechanism. The channel attention gating mechanism calculates the channel weight coefficient based on the average correlation of each channel in the channel correlation matrix, which is used to adjust the state transfer ratio of each channel in the recursive update of each time step, and outputs the time series evolution feature tensor;
[0125] The time series evolution feature tensor is input into the residual connection structure. While the residual connection structure transmits the processing result in the main branch network path, batch normalization and nonlinear transformation operations are introduced in the jump path. The batch normalization is used to standardize the distribution of the time series evolution feature tensor. The nonlinear transformation operation adopts the ReLU activation function to improve the signal expression ability. Finally, the output of the jump path is element-by-element added with the output of the main branch path to generate a residual fusion feature tensor, which serves as the input basis for the subsequent attention mechanism and classification reasoning steps.
[0126] In the neural network modeling and reasoning method for attention state recognition based on EEG sequences described in the present invention, in order to effectively model the channel spatial structure and temporal dynamic changes of EEG signals, a multi-channel convolutional recurrent neural network model consisting of a spatial convolution unit, a gated recurrent unit and a residual connection structure is adopted. In order to ensure that the model still has generalization ability and structural adaptability under different individuals and different channel arrangement conditions, the neural network model introduces a set of dynamic calculation mechanisms with a channel correlation matrix as the core, and executes multiple data processing steps in sequence, forming a high-dimensional feature tensor with semantic expression layer by layer.
[0127] First, the received multi-dimensional input tensor consists of eigenvectors with multiple channels and multiple time steps. Each channel corresponds to a specific EEG acquisition point and has been assigned a channel embedding vector through the feature encoding step. The system quantifies the similarity of time-frequency information between channels by calculating the cosine similarity between each pair of channel embedding vectors. At the same time, the system also calls a predefined scalp spatial position mapping table to obtain the geometric distance between any two channels, and converts the distance information into a distance weight through a Gaussian attenuation function. On this basis, the system performs a weighted average of the cosine similarities to construct a channel correlation matrix. Each element of this matrix is used to characterize the overall synergy between channel pairs. The higher the value, the more highly consistent the two channels are in the spectral structure and the closer they are physically.
[0128] Next, the channel correlation matrix not only serves as an evaluation metric but also directly participates in the generation process of the convolutional kernel in the spatial convolutional unit. Specifically, based on the channel correlation matrix, the system adaptively adjusts the weight distribution of the convolutional kernel in combination with the variance of the features of each channel in the current input tensor, enabling the convolutional kernel to preferentially capture the information flow path between highly correlated channels during the sliding operation. The convolutional operation is carried out in a two-dimensional manner in the channel dimension of the input tensor, and each convolutional kernel processes vectors of multiple channels, thereby extracting the feature structure representing the channel spatial interaction pattern. The tensor output after convolution is called the spatial correlation feature tensor. This tensor emphasizes the cross-channel collaborative structure information more than the original input and is regarded as the original basis for temporal modeling in subsequent stages.
[0129] The spatial correlation feature tensor is then input into a gated recurrent unit. The gated recurrent unit adopts a recurrent neural network architecture based on a gating mechanism, such as GRU (Gated Recurrent Unit) or LSTM (Long Short-Term Memory Network), and can be recursively updated over multiple time steps to capture the feature evolution law in the time dimension. In the present invention, a channel attention gating mechanism is introduced on the basis of the traditional recursive framework. This mechanism calculates the average correlation degree of each channel with reference to the previously constructed channel correlation matrix and normalizes it as the channel weight coefficient. These weight coefficients are applied to the input gate and update gate of the state transition at each time step to dynamically regulate the transmission intensity of the state information of each channel, thereby ensuring that the network pays more attention to the historical evolution trajectory of highly correlated channels during the temporal modeling process. The output time series evolution feature tensor contains the fusion information of spatial dependence and time dynamics and has a high feature recognition ability.
[0130] Finally, the time series evolution feature tensor is input into the residual connection structure to enhance network stability. In this structure, the main path of the network continues to perform standard linear transformations or further neural layer processing, while the skip path directly passes the initial input and sequentially processes it through batch normalization operations and non-linear transformation functions during the transmission. Batch normalization is used to standardize the distribution of features in each training batch and alleviate the problem of internal covariate shift, while the non-linear transformation uses the ReLU activation function to ensure the non-linear expression ability of the signal. The outputs of the main path and the skip path are fused into a residual fusion feature tensor by element-wise addition at the end of the structure, which not only retains the original information but also introduces deep features. This fusion tensor is then used in the subsequent attention mechanism weighting and classification inference steps to provide a structurally complete and fully expressive feature input for identifying the attention state. The reference implementation code is as follows:
[0131] import torch
[0132] import torch.nn as nn
[0133] import torch.nn.functional as F
[0134] class EEGAttentionNetwork(nn.Module):
[0135] def __init__(self, num_channels, time_steps, embedding_dim,hidden_dim, num_classes, scalp_distance_matrix):
[0136] super(EEGAttentionNetwork, self).__init__()
[0137] self.num_channels = num_channels
[0138] self.embedding_dim = embedding_dim
[0139] self.hidden_dim = hidden_dim
[0140] self.time_steps = time_steps
[0141] # Initialize the embedding vectors for each channel
[0142] self.channel_embeddings = nn.Parameter(torch.randn(num_channels, embedding_dim))
[0143] # Channel spatial position distance matrix: Shape [number of channels, number of channels]
[0144] self.register_buffer('distance_matrix', scalp_distance_matrix)
[0145] # BatchNorm and ReLU for the residual path
[0146] self.bn = nn.BatchNorm1d(num_channels)
[0147] self.relu = nn.ReLU()
[0148] # GRU unit for temporal modeling
[0149] self.gru = nn.GRU(input_size=embedding_dim * num_channels,
[0150] hidden_size=hidden_dim,
[0151] batch_first=True)
[0152] # Attention mechanism parameters
[0153] self.attn_layer = nn.Linear(hidden_dim, 1)
[0154] # Final classifier
[0155] self.classifier = nn.Linear(hidden_dim, num_classes)
[0156] def compute_channel_correlation(self):
[0157] # Normalize the channel embeddings and compute the cosine similarity between channels
[0158] normed_embeddings = F.normalize(self.channel_embeddings, dim=1) # [C, D]
[0159] cosine_similarity = torch.matmul(normed_embeddings, normed_embeddings.T) # [C, C]
[0160] # Distance weighting: Use Gaussian decay function to simulate spatial proximity
[0161] gaussian_weight = torch.exp(-self.distance_matrix ** 2)
[0162] # Channel correlation matrix = similarity × distance weighting
[0163] channel_corr = cosine_similarity * gaussian_weight # [C, C]
[0164] return channel_corr
[0165] def dynamic_spatial_aggregation(self, input_tensor, correlation_matrix):
[0166] # Use the correlation matrix as attention weights and weight the input by channel
[0167] B, C, T = input_tensor.shape
[0168] aggregated = torch.einsum('bcf,cd->bdf', input_tensor,correlation_matrix) # [B, T, D]
[0169] return aggregated
[0170] def forward(self, input_tensor):
[0171] # Input: input_tensor [B, C, T]
[0172] B, C, T = input_tensor.shape
[0173] input_tensor = input_tensor.permute(0, 2, 1) # Convert to [B, T, C]
[0174] # Construct the channel correlation matrix
[0175] channel_corr = self.compute_channel_correlation() # [C, C]
[0176] # Construct the dynamic channel features [C, D]
[0177] fused_embeddings = torch.matmul(channel_corr, self.channel_embeddings) # [C, D]
[0178] # Expand the time-step input into features with embedding dimension [B, T, C, D]
[0179] input_tensor_expanded = input_tensor.unsqueeze(-1) * fused_embeddings.view(1, 1, C, -1)
[0180] # Convert [B, T, C, D] -> [B, T, C * D]
[0181] input_tensor_flat = input_tensor_expanded.view(B, T, C * self.embedding_dim)
[0182] # Residual path preparation: BN + ReLU
[0183] residual = input_tensor_flat.clone()
[0184] normed = self.bn(input_tensor_flat.view(-1, C * self.embedding_dim)).view(B, T, -1)
[0185] activated = self.relu(normed)
[0186] fused = activated + residual # Tensor after residual connection
[0187] # GRU processes time series, and the output shape is [B, T, H]
[0188] rnn_out, _ = self.gru(fused)
[0189] # The attention mechanism calculates the importance weights for each time step
[0190] attn_weights = F.softmax(self.attn_layer(rnn_out), dim=1) #[B, T, 1]
[0191] context_vector = torch.sum(attn_weights * rnn_out, dim=1) # Shape after weighted summation is [B, H]
[0192] # Classification output
[0193] logits = self.classifier(context_vector) # [B, number of classes]
[0194] probs = F.softmax(logits, dim=1) # Convert to probability distribution
[0195] # Confidence score = probability value of the largest class
[0196] confidence = torch.max(probs, dim=1)[0]
[0197] return probs, confidence
[0198] The above code implements a multi-channel convolutional recurrent neural network structure for EEG time series, aiming to identify the attention states in different time periods and output classification results and confidence scores. The model first represents the feature distributions of each EEG channel through predefined channel embedding vectors, and further calculates the cosine similarity between all channels to quantify their correlations in the feature space. To introduce physical structure information, the model also introduces the channel distances in the scalp space and converts them into weight coefficients through a Gaussian function to weightedly adjust the correlations between channels, thereby constructing a channel correlation matrix.
[0199] This correlation matrix is used to dynamically generate the weighted structure of the spatial convolution kernel and perform feature aggregation operations on the channel dimension of the input data. The aggregated result is used as the input sequence for the gated recurrent neural network for time series modeling. The model can learn the attention change pattern over time through recursive updates at each time step. In the residual structure, the original time series features are skip-connected with the features that have been normalized and processed by the activation function, enhancing the information expression ability and maintaining the network stability. Next, the model calculates the contribution weights of each time step to the final classification through the attention mechanism and generates the context vector as the classification basis. The final output is the classification probability of the attention state and the confidence score based on the maximum class probability, which is used to reflect the stability and reliability of the classification result.
[0200] Step S104: During the model training process, introduce the cross-time-step attention mechanism to weight and adjust the feature contribution degrees of each time segment, and dynamically adjust the class weight coefficient in the loss function based on the classification confusion degree of the current training batch to enhance the identification sensitivity to the attention transition state.
[0201] In step S104, two key mechanisms are introduced during the model training process, namely the cross-time-step attention mechanism and the dynamic loss weight adjustment strategy based on the classification confusion degree. These two mechanisms work together to improve the model's ability to identify the fuzzy boundaries or transition states during the attention state change process and enhance the robustness and adaptability of the training process.
[0202] The introduction of the attention mechanism is to enable the model to automatically identify and focus on those segments in the time series that are more discriminative for judging the attention state. In electroencephalogram (EEG) signals, the contribution degrees of different time segments to the final state classification are not equal. Especially during the transition of attention from concentration to dispersion (or vice versa), the signal features may show low amplitude, low stability, or local perturbations. If the model treats all time steps equally, it is easy to mask the recognition effect of these key segments. Therefore, during the training phase, a learnable weight is assigned to each time segment, and the weight value is calculated by the attention module embedded in the network. This module usually consists of a fully connected network layer or a dot-product attention structure. The input is the feature representation corresponding to this time step, and the output is the attention score of this time step. In each round of training, these attention scores are normalized and then used as the weighting coefficients for the feature representations of each time step, enabling the model to focus on the parts with higher information content during backpropagation and effectively improving the pertinence of feature extraction and the separability of the classification boundary.
[0203] Meanwhile, to further address the issues of imbalance between sample categories or inaccurate recognition of transitional states, this step also introduces a dynamic loss function adjustment mechanism based on classification confusion. During the actual training process, certain categories may have a high misclassification rate due to a small number of samples or low distinctiveness. To avoid the problem that the model overfits to easily classified samples and under-learns difficult-to-classify samples during training, after the forward calculation of each batch of training data, the system will automatically analyze the prediction accuracy and confusion matrix distribution of each category in the current batch. If it is found that certain categories are frequently misjudged by other categories, the system will increase the weight of that category in the loss function, making the error of that category have a greater impact on the update of model parameters during backpropagation, thus prompting the model to more actively correct its judgment strategy. The adjustment of the weight can be dynamically calculated according to the set rules. For example, the growth rate can be set according to the misjudgment rate of that category, or the exponential decay method can be used to balance historical information and current performance.
[0204] Through the combined action of the attention mechanism and the dynamic loss adjustment mechanism, the model can not only finely capture the discriminative power of temporal features at different stages, but also adaptively guide the learning focus towards those difficult-to-identify transitional state samples, enabling the final attention state classifier to have stronger stability and generalization ability when facing real complex EEG data.
[0205] For example, during the model training stage, first for each time series sample, the structure of the input tensor is: if it is set that there are time steps after the time window is divided, the number of EEG channels is , and the feature dimension of each step is , then the dimension of the input tensor is . After processing by spatial convolution and gated recurrent unit, each time step will obtain a high-order representation that fuses spatial and temporal features, denoted as , where is the hidden state dimension, usually set to 128 or 256.
[0206] Next, the cross-time-step attention mechanism is introduced. The specific approach is to map each to a scalar attention score. It is recommended to use a simple and differentiable attention function, that is, use a shared fully connected layer to implement a linear transformation, and then connect the hyperbolic tangent function for non-linear transformation. This calculation process can be expressed as:
[0207] 1. The feature of each time step passes through the weight vector and the bias term to calculate the attention score ;
[0208] 2. For all time steps of Normalized by the softmax function to obtain the normalized attention weights , where , and , where is the total number of time steps; is the th attention score at the time step;
[0209] After obtaining the attention weights for each time step, these weights are used to perform a weighted sum of the feature representations of all time steps to obtain the context feature vector of the entire sequence , which will be used as the input to the subsequent classification layer for predicting the final state label. Among them, is the total number of time steps.
[0210] The above attention mechanism enables the model to concentrate more learning resources on key time segments during backpropagation, such as the unstable states before and after attention conversion, by automatically learning the importance of each time period for the overall classification judgment, thereby improving the sensitivity and boundary accuracy of classification.
[0211] On this basis, a dynamic loss function weighting mechanism is also introduced to enhance the robustness against class imbalance and ambiguous samples. In each mini-batch of each round of training, the system will first complete the forward propagation, record the confusion situation between the prediction results and the true labels, and form the confusion matrix for this batch. The confusion matrix is a two-dimensional array that records the number of times each actual class is misjudged as other classes.
[0212] For classes with a high confusion rate, for example, if more than of the samples of a "transition attention state" are misjudged as "low attention state" in the current batch, then the loss weight of this class is increased. A feasible strategy is:
[0213] Let the base class weight be 1.0. If the misjudgment rate of a certain class exceeds the threshold (such as ), then an additional misjudgment rate multiplied by the adjustment coefficient (recommended to be set from 1.5 to 2.0) is added, that is, the final class loss weight is: weight of class i misjudgment rate
[0214] Among them, is an empirically set adjustment factor that controls the sensitivity of the model response. For example, if the misjudgment rate of a certain class is , then the error of this class in the final loss function will be amplified to about 1.6 times, guiding the model to more actively optimize the classification boundary of this class.
[0215] The weight adjustment process does not affect the convergence of the training process because the standard cross-entropy loss function is still used as the basic loss structure, and only the sample class weighting term is dynamically updated. This mechanism calculates and adapts to the current model performance in real time at each batch level, without presetting class weights or manual intervention.
[0216] The attention mechanism and the dynamic loss weight adjustment mechanism can be executed synchronously in the main training loop. The former enhances the discriminative ability of temporal local features, and the latter improves the learning efficiency of the model at class imbalance and fuzzy boundaries. The combination of the two forms a complete optimization strategy.
[0217] All operations in this step can be directly coded and implemented in the deep learning framework. The functions relied on only include basic linear transformations, activation functions, softmax normalization, weighted summation, and cross-entropy loss calculation. The required parameters can all be automatically optimized through gradient descent during the training process.
[0218] Furthermore, during the model training process, a cross-time-step attention mechanism is introduced to weightedly adjust the feature contribution degrees of each time segment, and based on the classification confusion degree of the current training batch, the class weight coefficient in the loss function is dynamically adjusted to enhance the discrimination sensitivity to the attention transition state, including:
[0219] By analyzing the attention distribution of each sample at each time step, calculate its attention entropy value as an index to measure the attention concentration degree and time segment uncertainty of the sample;
[0220] Mark the samples with higher attention entropy as potential uncertain samples, and count the confidence fluctuation of their corresponding class distributions in the model output as a measure of the discriminative instability of this class;
[0221] Set a higher weight for the class with frequent occurrence of uncertain samples in the loss function. At the same time, introduce a specific amplitude of input perturbation to the samples of this class, observe the change amplitude of its output confidence, and determine the perturbation sensitivity accordingly;
[0222] According to the magnitude of the perturbation sensitivity, dynamically adjust the learning rate update factor for this class to achieve a smoother and more focused optimization path for the class with high discriminative instability, thereby improving the model's identification ability in the attention state boundary region.
[0223] In the method for modeling and reasoning of an attention state recognition neural network based on EEG sequences described in the present invention, in order to improve the model's identification ability for the attention state transition region, a training optimization process centered on uncertainty recognition, combined with an attention mechanism, loss adjustment, and learning rate control, is designed during the model training stage.
[0224] First, during the training process, the model obtains the contribution degree of each time segment to the final classification result through the cross-time-step attention mechanism. These attention weights are calculated for the feature representations of each time step in each sample sequence, forming a set of normalized weight distributions. On this basis, in order to quantify the concentration degree of the attention distribution of the sample, the system takes the attention weight distribution of each sample as a probability distribution input and obtains its attention entropy value through the standard information entropy calculation method. The attention entropy reflects the degree of dispersion of the attention of this sample: if the attention weights are concentrated on a few time steps, the entropy value is low, indicating that the model has a clear discrimination basis for this sample; if the weights are evenly distributed among multiple time steps, the entropy value is high, indicating that the model has not yet been able to locate the key information area and there is a strong uncertainty. This attention entropy can be directly used as the uncertainty score of the current sample.
[0225] Subsequently, the model marks the samples with higher attention entropy in the current training batch and further analyzes the fluctuation of the classification output confidence of these samples. This analysis is based on the probability distributions of various categories output by the model for each prediction of the sample, and extracts the maximum category confidence and its variance fluctuation in consecutive training cycles. If a certain category frequently appears in the prediction results of high-entropy samples and the confidence corresponding to this category fluctuates greatly, it can be regarded as the discrimination boundary of this category is not yet stable and the model has not effectively learned its key criteria.
[0226] To deal with such categories with higher discrimination instability, the system will temporarily increase the category weight of this category in the loss function in the current training cycle, so that this category occupies a higher gradient proportion in the model parameter update, thereby guiding the model to further learn its discrimination features. At the same time, in order to more accurately identify the robustness of the model to this category, it is also necessary to introduce a certain amount of input perturbation to conduct a sensitivity test on the samples of this category. The perturbation can be achieved by adding a small random perturbation or a perturbation mask to the original input features, and observing the response change of the model output confidence on the premise of not changing the label attributes. By comparing the change amplitude of the model output confidence before and after the perturbation, a perturbation sensitivity index can be obtained, indicating the response intensity of this category to small input changes.
[0227] Finally, the system dynamically sets the learning rate adjustment factor for each category based on the perturbation sensitivity. For categories with high perturbation sensitivity, the system automatically reduces the magnitude of their learning rate changes to reduce the drastic fluctuations caused by unstable samples to the model parameters and maintain the smooth progress of the optimization path; while for categories with low perturbation sensitivity, the learning rate update speed is appropriately increased to ensure that the model does not stagnate on easily classifiable samples. Without changing the main training logic, this strategy introduces a multi-layer adaptive adjustment mechanism driven by uncertain samples to the training process, which can significantly improve the classification performance of the model on boundary samples and fuzzy states, while avoiding overfitting to stable categories.
[0228] The following is the reference implementation code for the uncertainty training optimization strategy centered on attention entropy:
[0229] import torch
[0230] import torch.nn.functional as F
[0231] import numpy as np
[0232] # ========== Input assumptions ==========
[0233] # attention_weights: Tensor[batch_size, T] represents the attention weights of each sample across T time steps
[0234] # predictions: Tensor[batch_size, num_classes] represents the class prediction probability distribution of each sample
[0235] # labels: Tensor[batch_size] represents the true label of each sample
[0236] # inputs: Tensor[batch_size, channels, T, features] represents the original input tensor
[0237] # model: The defined neural network model (with attention structure)
[0238] # past_confidences: List[List[float]], the confidence records of each category in the previous few epochs, used to evaluate category instability
[0239] # Step 1: Calculate the attention entropy
[0240] def compute_attention_entropy(attention_weights, epsilon=1e-8):
[0241] The entropy formula is: H = -Σ(p_t * log(p_t)), where p_t is the attention weight at the t-th time step.
[0242] The larger the entropy value, the more dispersed the attention is, that is, the more uncertain the sample is.
[0243] log_weights = torch.log(attention_weights + epsilon)
[0244] entropy = -torch.sum(attention_weights * log_weights, dim=1) # Calculate once for each sample
[0245] return entropy # [batch_size]
[0246] # Step 2: Mark high-uncertainty samples
[0247] def identify_uncertain_samples(entropy, quantile=0.75):
[0248] # Use the quantile of the attention entropy as the threshold to select high-entropy samples as uncertain samples
[0249] threshold = torch.quantile(entropy, quantile)
[0250] mask = entropy >= threshold
[0251] return mask # [batch_size], boolean
[0252] # Step 3: Update the class weights in the loss function
[0253] def update_class_weights(predictions, labels, uncertain_mask, past_confidences, alpha=1.5):
[0254] # Dynamically increase the weight of the loss function for categories with high occurrence frequency and large confidence fluctuations
[0255] num_classes = predictions.shape[1]
[0256] class_weights = torch.ones(num_classes) # Initially all 1.0
[0257] # Filter out the prediction results of uncertain samples
[0258] uncertain_indices = torch.where(uncertain_mask)[0]
[0259] if uncertain_indices.numel() == 0:
[0260] return class_weights # If there are no uncertain samples, return the default weights
[0261] predicted_classes = torch.argmax(predictions[uncertain_indices],dim=1)
[0262] for c in range(num_classes):
[0263] count_c = (predicted_classes == c).sum().item()
[0264] if count_c > 0:
[0265] # Introduce the historical fluctuation of confidence
[0266] conf_var = np.var(past_confidences[c]) if len(past_confidences[c]) > 1 else 0.0
[0267] # Class weight increment = α × sample proportion × (1 + volatility)
[0268] class_weights[c] += alpha * (count_c / len(uncertain_indices)) * (1 + conf_var)
[0269] return class_weights # Tensor[num_classes]
[0270] # Step 4: Compute perturbation sensitivity
[0271] def compute_perturbation_sensitivity(model, inputs, labels, num_classes, epsilon=0.01):
[0272] # Perturb samples of each class and observe the change in confidence to measure perturbation sensitivity
[0273] sensitivity = torch.zeros(num_classes)
[0274] lr_factors = torch.ones(num_classes)
[0275] for c in range(num_classes):
[0276] idx = (labels == c)
[0277] if idx.sum() == 0:
[0278] continue
[0279] original = inputs[idx]
[0280] perturb = original + epsilon * torch.randn_like(original) # Add perturbation
[0281] with torch.no_grad():
[0282] pred_original = F.softmax(model(original), dim=1)
[0283] pred_perturb = F.softmax(model(perturb), dim=1)
[0284] conf_orig = torch.max(pred_original, dim=1)[0]
[0285] conf_pert = torch.max(pred_perturb, dim=1)[0]
[0286] delta = torch.abs(conf_orig - conf_pert).mean()
[0287] # Set the sensitivity metric
[0288] sensitivity[c] = delta
[0289] # Learning rate scaling: high sensitivity → slow; low sensitivity → fast
[0290] lr_factors[c] = 1.0 / (1.0 + delta.item()) # Ensure the scaling factor is in the range (0,1]
[0291] return lr_factors # [num_classes]
[0292] # Comprehensive application (example process during training):
[0293] # attention_entropy = compute_attention_entropy(attention_weights)
[0294] # uncertain_mask = identify_uncertain_samples(attention_entropy)
[0295] # class_weights = update_class_weights(predictions, labels, uncertain_mask, past_confidences)
[0296] # lr_factors = compute_perturbation_sensitivity(model, inputs, labels, num_classes=predictions.size(1))
[0297] # The class_weights can be used to weight the cross-entropy loss function
[0298] # The lr_factors can be used to adjust the learning rate for samples related to each class
[0299] As can be seen from the above code, the operations of introducing the cross-time-step attention mechanism, dynamic loss function adjustment, and class-adaptive learning rate control during model training include the following steps:
[0300] Based on the attention mechanism, obtain the attention weight distribution of each training sample at each time step, and normalize this distribution into a probability distribution form that satisfies the sum of 1. Let the attention distribution of the th sample be , where is the time-step index, is the total number of time steps, and calculate its attention entropy according to the following formula 1 :
[0301]
[0302] Among them, represents the attention weight of sample at time step , which is output by the network attention layer, reflecting the concentration or dispersion degree of the attention distribution of this sample;
[0303] According to the preset quantile threshold , select the samples that satisfy as the uncertain samples, and count the proportion of the number of uncertain samples predicted for each category in the current training batch. Combine the historical confidence data of the corresponding category in the previous set period to calculate the confidence fluctuation variance of this category to obtain the adjustment weight of this category in the loss function, which is calculated by the following formula 2:
[0304]
[0305] Among them, is a preset proportionality coefficient, for example; is obtained by statistical prediction results of uncertain samples, and is calculated based on the historical confidence sequence output by the current model;
[0306] For each category , introduce a random perturbation with an amplitude of to act on the input features of the samples corresponding to this category, and calculate the maximum confidence and of the output prediction before and after the perturbation respectively to obtain the perturbation sensitivity index , which is calculated according to the following formula 3:
[0307]
[0308] Among them, represents all training samples with the label of category ; and are the maximum prediction probability values before and after perturbation respectively; according to the perturbation sensitivity index , set the learning rate adjustment factor of category , and its calculation method is:
[0309]
[0310] The category learning rate adjustment factor is used to proportionally control the gradient update amplitude related to category in the optimizer, so as to use a slower update rate for the category with strong perturbation response, in order to improve the robustness and convergence stability of the model to the boundary samples of this category.
[0311] Step S105: After the training is completed, receive the target EEG time series data of any length, use the trained neural network model for inference, and output the corresponding attention state classification label and its confidence score value; among them, the confidence score value is calculated based on the distance between the attention-weighted feature representation and the classification boundary, and is used to quantify the stability and credibility of the classification result.
[0312] In step S105, after the neural network model is trained, it will be used to perform actual inference operations on new EEG time series data, so as to realize the automatic recognition and credibility evaluation of the attention state. The core of this step is to ensure that the model has the ability to process variable-length input data in actual applications, and can output stable and interpretable classification results and confidence scores for subsequent system decision-making or feedback.
[0313] First of all, when receiving new EEG time series data, there is no need to limit its time length. This means that the EEG signals generated by users at different time periods and under different tasks can be directly fed into the model as input without prior truncation or fixed-length padding processing. This ability comes from the recurrent structure and attention mechanism introduced in the previous training process, making the model naturally adaptable to variable-length sequences. To be consistent with the training stage, the new data needs to go through the same wavelet transform and time-frequency feature extraction processing as the original data, and be embedded in the channel position and tensor construction in the same way to ensure that the structure and feature space of the input tensor are exactly the same as the training data.
[0314] After the input data is constructed into a compliant multi-dimensional tensor, it is input into the trained neural network model. The model will sequentially pass through the spatial convolution layer, gated recurrent unit, residual connection path, and attention weighting module to fully extract and integrate the spatio-temporal joint features in the input sequence. During this process, the attention mechanism will recalculate the attention scores for each time step, automatically identify the time segments in the current EEG sequence that are highly correlated with the attention state, and give higher influence weights in the inference results. Finally, the high-dimensional features of the entire sequence are compressed into a context vector representing global information and sent to the output layer for classification prediction.
[0315] The final output of the model consists of two parts: one is the attention state classification label, usually one of the states such as "highly concentrated", "slightly distracted", or "severely distracted"; the other is the corresponding confidence score value, which is used to reflect the stability and credibility of the model's prediction result. The generation of the confidence score is based on the matching degree between the attention-weighted features inside the model and the discriminant boundaries learned during the training process. The specific implementation method is that the model measures the proximity of the current input's distribution position in the feature space to the boundaries of each category. If the current feature has a significant discriminability near a certain category boundary, a higher confidence score is output, otherwise a lower value is output. This scoring mechanism provides a quantitative means for the reliability of the model inference without the need for artificial labels and can be used as an important reference basis for judging whether the result is credible.
[0316] The entire inference process can be automatically implemented in a standard deep learning framework without modifying the network structure or parameters. All that is required is a trained and saved model parameter file, and an EEG signal processing and preprocessing module connected to the input end. This step is clearly designed, with a stable process and clear parameters, ensuring industrial-level deployment conditions and can be directly applied to multiple scenarios such as real-time monitoring of attention states, fatigue warning systems, and brain-computer interface feedback.
[0317] Furthermore, the use of the trained neural network model for inference and outputting the corresponding attention state classification label and its confidence score value includes:
[0318] Based on the distances between the last hidden feature vector in the neural network model and each predefined classification hyperplane, calculate the geometric projection distance of the hidden feature vector relative to the classification boundary in the feature space. This geometric projection distance is used to construct a continuous confidence score value for each sample at the current moment. The larger the value of this confidence score, the closer the sample is to the center of the target category in the feature space, and the more credible the classification result.
[0319] Record the sequence of confidence score values corresponding to each consecutive time step, and calculate the sliding standard deviation and the maximum amplitude change value of this sequence, which are used to represent the confidence fluctuation trend of the current sample within this time interval. This fluctuation trend is used as an indicator to evaluate the stability of the model's time series judgment for this sample;
[0320] When the confidence fluctuation trend exceeds a preset threshold, the model is automatically triggered to perform a secondary recognition operation on this sample. The secondary recognition operation includes reactivating the attention mechanism for feature weighting and performing a second classification prediction, which is used to improve the recognition accuracy of unstable samples;
[0321] In the secondary recognition result, if the confidence score is still lower than the confidence rejection threshold, a rejection flag is output instead of a classification label, which is used to enhance the robustness of the system and reduce the risk of misjudgment in critical states or for fuzzy samples. This rejection flag is provided for external systems to trigger further judgment or manual review processes.
[0322] In the neural network modeling and inference method for attention state recognition based on EEG sequences described in the present invention, the final inference step not only outputs the classification label of the attention state, but also constructs a continuous confidence score value to achieve the measurement of the credibility of the classification result and the reinforcement of the subsequent decision-making mechanism. This inference step consists of multiple closely related sub-processes, and the output of each sub-process serves as the basis for subsequent judgment and decision-making, forming a classification decision-making process with robustness and judgment fineness.
[0323] In the inference stage, first, the trained neural network model is used to extract the hidden feature representation of the input sample in the last layer of the network structure. This hidden feature vector is located in a high-dimensional feature space and represents the semantic distribution state of the current input sample from the perspective of network discrimination. For each target classification category, the system has pre-trained the corresponding classification hyperplane representation. By calculating the geometric projection distance from the hidden feature vector to each classification hyperplane, the spatial distance of this sample relative to the discrimination boundaries of different categories can be obtained. The system selects the distance from this sample to the hyperplane of its predicted category as the basis for its confidence score. This score is a continuous value that reflects the "confidence level" of this sample being judged as the current category. The larger the projection distance, the closer this sample is to the category center region in the feature space, the clearer the discrimination result, and the higher the score.
[0324] This scoring mechanism not only works on a single time point. In the continuous EEG time series analysis, the system records the confidence scores calculated at each time step in order to form a set of scoring value sequences that change over time. In order to further evaluate the judgment stability of the sample throughout the time series, the system calculates the sliding standard deviation and the maximum value change amplitude of the scoring sequence to determine the fluctuation trend of the confidence score. The more drastic the score fluctuation, the less stable the model's judgment of the sample in the time dimension, and there are problems with unclear identification of boundary samples or fuzzy states. This fluctuation trend is used to trigger a more stringent judgment process.
[0325] Once the score fluctuation trend indicator exceeds the stability threshold set by the system, the system will automatically start a secondary recognition process for the sample. This process does not simply repeat the initial judgment, but reactivates the attention mechanism in the model. The attention mechanism will re-weight the importance of different time steps, different channels, or different feature areas according to the feature structure of the current sample, and re-integrate features and classify predictions accordingly. This method can guide the model to perform a more focused and detailed judgment process when facing the initial recognition of unstable samples, thereby improving the reliability of the final classification results.
[0326] If, in the result of the second recognition, the confidence score corresponding to the target category still does not reach the minimum trust threshold defined by the system, the system will not output the classification label of the sample, but will output a rejection sign. The rejection sign is a clear logical signal that tells the system that the current sample is in a cognitive fuzzy zone and lacks sufficient basis for judgment. In this case, the system submits the sample to an external module for further processing, including but not limited to delayed judgment, manual confirmation, or activation of other auxiliary models for collaborative judgment, to avoid systemic risks caused by misjudgment.
[0327] This reasoning and confidence mechanism not only enhances the model's ability to perceive critical state samples, but also realizes the self-steady-state regulation and rejection ability of the classification system through a structured scoring and judgment process, greatly improving the reliability and generalization ability of the neural network model for high-risk identification tasks in practical applications.
[0328] A second embodiment of the present application provides an electronic device, the electronic device comprising:
[0329] processor;
[0330] The memory is used to store a program. When the program is read and executed by the processor, it executes a neural network modeling and reasoning method for attention state recognition based on EEG sequences provided in the first embodiment of the present application.
[0331] The third embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it executes a method for modeling and reasoning of an attention state recognition neural network based on an electroencephalogram sequence provided in the first embodiment of the present application.
[0332] Although the present application is disclosed above in preferred embodiments, it is not intended to limit the present application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the protection scope of the present application should be subject to the scope defined by the claims of the present application.
Claims
1. A neural network modeling and inference method for attention state recognition based on EEG sequences, characterized in that, Including: Performing wavelet transform processing on the EEG time series signal obtained through sampling to extract sub-band signals of different frequency bands and obtain frequency domain information with multi-scale resolution; Performing time-frequency domain feature extraction on the sub-band signals, and encoding the extracted features into a multi-dimensional input tensor with channel embedding vectors according to the distribution positions of each channel in the scalp space; Inputting the multi-dimensional input tensor into a multi-channel convolutional recurrent neural network model composed of a spatial convolution unit, a gated recurrent unit, and a residual connection structure, where the spatial convolution unit is used to extract spatial correlation features between different channels, the gated recurrent unit is used to learn the evolution law of time series features, and the residual connection structure is used to alleviate the problem of gradient disappearance during the training process of deep networks; During the model training process, introducing a cross-time-step attention mechanism to weight and adjust the feature contribution degrees of each time segment, and dynamically adjusting the class weight coefficients in the loss function based on the classification confusion degree of the current training batch to enhance the recognition sensitivity to the attention transition state; After the training is completed, receiving target EEG time series data of any length, using the trained neural network model for inference, and outputting the corresponding attention state classification label and its confidence score value; wherein, the confidence score value is calculated based on the distance between the feature representation weighted by attention and the classification boundary, and is used to quantify the stability and credibility of the classification result; The using the trained neural network model for inference and outputting the corresponding attention state classification label and its confidence score value includes: Based on the distance between the last-layer hidden feature vector in the neural network model and each predefined classification hyperplane, calculating the geometric projection distance of the hidden feature vector relative to the classification boundary in the feature space, and the geometric projection distance is used to construct a continuous confidence score value for each sample at the current moment, and the larger the value of this confidence score value, the closer the sample is to the target class center in the feature space, and the more credible the classification result; Recording the sequence of confidence score values corresponding to each continuous time step, and calculating the sliding standard deviation and the maximum amplitude change value of this sequence, which are used to represent the confidence fluctuation trend of the current sample in this time interval, and the fluctuation trend is used as an index to evaluate the stability of the model's time series judgment on this sample; When the confidence fluctuation trend exceeds a preset threshold, automatically triggering the model to perform a secondary recognition operation on this sample, and the secondary recognition operation includes reactivating the attention mechanism for feature weighting and performing a second classification prediction to improve the recognition accuracy of unstable samples; In the secondary recognition result, if the confidence score is still lower than the confidence rejection threshold, outputting a rejection flag instead of a classification label, which is used to enhance the robustness of the system and reduce the misjudgment risk in critical states or fuzzy samples, and the rejection flag is used for the external system to trigger further judgment or manual review process.
2. The method for neural network modeling and reasoning of attention state recognition based on EEG sequences according to claim 1, wherein The performing time-frequency domain feature extraction on the sub-band signals, and encoding the extracted features into a multi-dimensional input tensor with channel embedding vectors according to the distribution positions of each channel in the scalp space includes: Convert the distribution positions of each channel in the scalp space into the form of three-dimensional Cartesian coordinates, and construct a channel space adjacency matrix based on the three-dimensional coordinates to reflect the physical proximity relationship between channels; Input the channel space adjacency matrix as the edge connection weight of the graph structure into the graph convolutional network. The graph convolutional network takes the frequency domain features of each channel as the initial node input, performs graph embedding modeling on the features of each channel, and generates the first channel embedding vector that fuses the channel time-frequency response and spatial structure; Based on the average signal-to-noise ratio and power intensity index of each channel in the target sub-band frequency band recorded in the training phase, extract the feature quality descriptor of the channel in this frequency band and encode it into a set of spectral characteristic vectors; Connect and fuse the first channel embedding vector and the corresponding spectral characteristic vector in dimension to form a second channel embedding vector containing multi-modal representation contents such as spatial position information, frequency domain response structure, and signal-to-noise characteristics. Use this second channel embedding vector as the basis for constructing the representation of each channel dimension in the multi-dimensional input tensor to enhance the modeling ability of the subsequent neural network structure for channel heterogeneity and task-related features.
3. The neural network modeling and reasoning method for attention state recognition based on EEG sequences according to claim 1, characterized in that Inputting the multi-dimensional input tensor into a multi-channel convolutional recurrent neural network model composed of a spatial convolutional unit, a gated recurrent unit, and a residual connection structure includes: Based on the multi-dimensional input tensor, construct a channel correlation matrix. The channel correlation matrix is calculated according to the cosine similarity between the channel embedding vectors corresponding to different channels in the multi-dimensional input tensor, and is weighted by combining the distance information of the channels in the scalp space to reflect the time-frequency feature synergy and spatial proximity relationship between channels; Use the channel correlation matrix as the parameter to dynamically generate the convolutional kernel weight of the spatial convolutional unit. The spatial convolutional unit performs a two-dimensional convolutional operation on the channel dimension of the multi-dimensional input tensor to extract the spatial dependence features between channels, and outputs a spatial correlation feature tensor. The spatial correlation feature tensor enhances the cross-channel coupling structure information on the basis of the original multi-dimensional input tensor; Input the spatial correlation feature tensor into the gated recurrent unit. The gated recurrent unit adopts a gated recurrent structure to recursively process the spatial correlation feature tensor at each time step, and at the same time introduces a channel attention gating mechanism. The channel attention gating mechanism calculates the channel weight coefficient based on the average correlation degree of each channel in the channel correlation matrix, and is used to adjust the state transfer ratio of each channel in the recursive update at each time step, and outputs a time series evolution feature tensor; Input the time series evolution feature tensor into the residual connection structure. While the residual connection structure transmits the processing result in the main branch network path, batch normalization and non-linear transformation operations are introduced in the skip path. The batch normalization is used to standardize the distribution of the time series evolution feature tensor, and the non-linear transformation operation uses the ReLU activation function to enhance the signal expression ability. Finally, an element-wise addition operation is performed on the output of the skip path and the output of the main branch path to generate a residual fusion feature tensor, which serves as the input basis for the subsequent attention mechanism and classification inference steps.
4. The neural network modeling and reasoning method for attention state recognition based on EEG sequences according to claim 1, wherein During the model training process, a cross-time-step attention mechanism is introduced to weight and adjust the feature contribution degrees of each time segment, and based on the classification confusion degree of the current training batch, the class weight coefficient in the loss function is dynamically adjusted to enhance the discrimination sensitivity to the attention transition state, including: By analyzing the attention distribution of each sample at each time step, calculate its attention entropy value as an index to measure the attention concentration degree and time segment uncertainty of the sample; Mark the samples with higher attention entropy as potential uncertain samples, and count the confidence degree fluctuation of their corresponding class distributions in the model output as a measure of the discrimination instability of this class; Set a higher weight for the class with frequent occurrence of uncertain samples in the loss function. At the same time, introduce a specific amplitude of input perturbation to the samples of this class, observe the change amplitude of its output confidence degree, and determine the perturbation sensitivity accordingly; According to the size of the perturbation sensitivity, dynamically adjust the learning rate update factor for this class to achieve a smoother and more focused optimization path for the class with high discrimination instability, thereby improving the model's discrimination ability in the attention state boundary region.
5. The neural network modeling and reasoning method for attention state recognition based on EEG sequences according to claim 1, characterized in that Perform wavelet transform processing on the sampled EEG time series signal to extract sub-band signals of different frequency bands and obtain frequency domain information with multi-scale resolution, including: After receiving the EEG time series signal, based on a predefined frequency sensitivity mapping function, determine the target frequency band group associated with the current task, and select the wavelet basis function with the strongest adaptability as the mother wavelet for wavelet transform of the current sample according to the response entropy difference of each frequency band group to the attention state change in the training samples. The frequency sensitivity mapping function is obtained by analyzing the discrimination information gain of the attention state labeled samples in each sub-frequency band in the training set and is used to guide the wavelet function to match the feature expression structure; Perform multi-scale decomposition on the EEG time series signal using the wavelet basis function obtained by the above selection, generating five types of sub-band signals including waves, waves, waves, waves and waves. And introduce a band-pass energy gating operation for each type of sub-band signal to filter out low-amplitude non-significant frequency bands, outputting an enhanced sub-band signal set, and taking the enhanced sub-band signal set as the frequency-domain information with multi-scale resolution.
Citation Information
Patent Citations
Auxiliary diagnosis system for patients with disturbance of consciousness based on automatic sleep staging
CN116687422A
Method and system for optimizing few-view-angle neural radiation field based on object pose probe
CN118552615A