Electroencephalogram emotion recognition method and device based on comparative learning and graph neural network

By combining contrast learning and GraphSAGE algorithm, the time and frequency characteristics of EEG signals are extracted and node characteristics are processed on the undirected graph, the problem of low accuracy of EEG signals in the prior art is solved, and more efficient and accurate emotional recognition is achieved.

CN119622443APending Publication Date: 2025-03-14ZHEJIANG UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411540609.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-31
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

The prior art is difficult to fully capture complex space-time dependencies in EEG signal emotion recognition, easy to overfit, and has large individual differences, resulting in low recognition accuracy.

Method used

Using a method based on contrast learning and graph neural network, the time and frequency characteristics of EEG signals can be extracted through time convolution and depth separation convolution, and the GraphSAGE algorithm is used to sample and aggregate neighbor node features on the undirected graph to generate graph-level features, and optimize feature representations through comparison learning.

Benefits of technology

It improves the accuracy and robustness of emotion recognition, enhances the model's ability to distinguish different emotional states, and solves the problem of low recognition accuracy in traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119622443A_ABST
    Figure CN119622443A_ABST
Patent Text Reader

Abstract

The invention discloses an electroencephalogram emotion recognition method and device based on comparative learning and a graph neural network. The method comprises the steps that firstly, data preprocessing is conducted on electroencephalogram signals, baseline signals are removed, and time sequence segmentation and baseline effect removal are conducted; then constructing a node feature extraction module, and extracting time and space features by using time convolution and depth separable convolution; next, sampling and aggregating neighbor node features on the complete undirected graph by using a GraphSAGE algorithm, and generating graph-level features through a full connection layer; then, constructing a comparative learning module, generating a triple sample pair according to the graph-level features, carrying out triple comparative learning, and selecting a semi-hard negative sample for training; and finally, constructing a classifier through a full connection layer and a softmax function to perform emotion classification. According to the method, the time and space features and the graph structure information of the electroencephalogram signals are effectively extracted and utilized through the method combining comparative learning and the graph neural network, and the accuracy of emotion recognition is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of emotion recognition, and in particular to an electroencephalogram emotion recognition method and device based on contrastive learning and graph neural network. Background Art

[0002] As a non-invasive, physiological means of emotion recognition, electroencephalogram (EEG) has received widespread attention and application in the field of emotion recognition. EEG signals can reflect the activity state of the brain. By analyzing these signals, the emotional state of an individual can be effectively identified. However, EEG signals have the characteristics of high dimensionality, strong noise, and complex time series, which makes it extremely difficult to extract effective features from them. Traditional emotion recognition methods mostly rely on manual feature extraction, such as extracting frequency domain features, time domain features, and time-frequency features, but these methods often require a lot of prior knowledge and professional experience, and perform poorly when dealing with different emotional states and individual differences.

[0003] In recent years, with the development of deep learning technology, researchers have begun to try to use deep neural networks to automatically extract emotional features from EEG signals. Deep learning methods can automatically learn and extract high-order features from data through a multi-layer neural network structure, thereby overcoming the shortcomings of traditional manual feature extraction. In this regard, convolutional neural networks (CNN) and recurrent neural networks (RNN) are widely used in EEG signal processing. However, existing deep learning methods still have some limitations, such as the inability to fully capture the complex spatiotemporal dependencies in EEG signals and easy overfitting. In addition, due to the large individual differences in EEG signals, how to design a robust feature extraction and emotion recognition method remains a challenge.

[0004] In order to overcome the above problems, the application of graph neural networks (GNN) in EEG emotion recognition has gradually attracted attention in recent years. GNN can effectively process non-Euclidean data structures, such as graph structured data, and capture the spatiotemporal dependencies in the data through the interaction of nodes and edges. GraphSAGE is a commonly used GNN algorithm that can efficiently learn node representations on large-scale graph data by sampling and aggregating the features of neighboring nodes. However, there are still some shortcomings in relying solely on GNN for emotion recognition, such as the lack of effective supervision signals and feature optimization mechanisms. Summary of the invention

[0005] In view of the above problems in the prior art, the present invention proposes an EEG emotion recognition method and device based on contrastive learning and graph neural network, aiming to perform more accurate and robust EEG emotion recognition.

[0006] The first aspect of the present invention relates to an EEG emotion recognition method based on contrastive learning and graph neural network, and the specific steps are as follows:

[0007] (1) Data preprocessing: remove the baseline signal before the test, use the sliding window method to sample the EEG signal sequence, and remove the baseline effect by the baseline averaging method;

[0008] (2) constructing a node feature extraction module, including: extracting the time-dependent features of the EEG signal through temporal convolution and extracting frequency-specific spatial information through depthwise separable convolution;

[0009] (3) Construct a graph-level feature extraction module, use the GraphSAGE algorithm to sample and aggregate the features of neighbor nodes on the complete undirected graph, and generate graph-level features through a fully connected layer;

[0010] (4) Construct a contrastive learning module to generate triple sample pairs online based on the sample labels and the graph-level features generated in step (3), and perform triple contrastive learning;

[0011] (5) Construct a classifier to classify emotions in EEG data, wherein the classifier includes a fully connected layer and a softmax function.

[0012] Furthermore, in step (1), a sliding window method is used to sample the EEG signal sequence, and a baseline averaging method is used to remove the baseline effect. The specific steps are as follows:

[0013] (1.1) Use sliding window to sample EEG signal data: For EEG signal data with C electrodes and data length L, D = (d1, d2, ..., d C ),in Use a moving window with a window size of T and a stride size of S to sample the EEG signal data and generate M= Samples

[0014] (1.2) Remove the baseline effect by using the baseline averaging method: The baseline data is also divided into several segments using the same sliding window, and then the average of these baseline segments is used as the baseline average. Represents the basic emotion of the subject at that time. Then, the EEG signal data obtained in (1.1) is sampled and the baseline average is subtracted to remove the baseline effect. The formula is as follows:

[0015] x i =x i -b basemean ,i=1,2…,M (1)

[0016] in It is the EEG signal after removing the baseline effect.

[0017] Furthermore, in step (2), a node feature extraction module is constructed, including: extracting the time-dependent features of the EEG signal through temporal convolution, and extracting frequency-specific spatial information through depth-separable convolution. The specific steps are as follows:

[0018] (2.1) Extracting the temporal dependency features of EEG signals through temporal convolution: The temporal convolution part contains three convolutional layers with different kernel sizes (1×15), (1×7), and (1×3), which are used to learn long-term, medium-term, and short-term temporal dependencies, respectively. In order to maintain the spatial dimension of the input EEG trial, zero padding of sizes (0×7), (0×3), and (0×1) is added. Number of convolution kernels: 30, 60, and 90 per layer. Each convolution layer is followed by batch normalization and parametric rectified linear activation function (PReLU). Three layers of convolution are superimposed for a total of nine convolution operations. The convolution operation can be expressed as:

[0019] y=f(W*x+b) (2)

[0020] Among them, y represents the output feature map, W is the convolution kernel, * represents the convolution operation, x is the input signal, b represents the bias, and f represents the activation function.

[0021] (2.2) Depthwise separable convolution extracts frequency-specific spatial information: The depthwise separable convolution part of the present invention consists of two layers of convolution operations and corresponding activation and normalization layers. First, the features of the input data in the depth dimension are aggregated through a three-dimensional convolution layer. Then, after adjusting to the appropriate dimension, the features in the spatial dimension are extracted through a two-dimensional convolution layer. Next, the output is standardized using a batch normalization layer, and nonlinearity is introduced through the PReLU activation function to improve the expressiveness and training stability of the model.

[0022] Furthermore, in step (3), a graph-level feature extraction module is constructed, and the GraphSAGE algorithm is used to sample and aggregate the features of neighbor nodes on the complete undirected graph, generate an embedded representation for each node, and generate graph-level features through a fully connected layer. The specific steps are as follows:

[0023] (3.1) Constructing an undirected graph: A classic undirected graph G = (V, E, A), where V represents the vertex set, C = |V| represents the number of vertices, E represents the set of edges between nodes, and the adjacency matrix A∈R N×N Middle ij Indicates the importance of the connection between the i-th node and the j-th node. The present invention uses a complete undirected graph, each node is represented by an integer ranging from 0 to C, and these nodes are denoted as a set V = {0, 1, 2...C-1}. It is necessary to generate all the combinations between the nodes, represented as edges. The combination can be represented as:

[0024] E={(i,j)|0 <i<C,0<j<C,i≠j} (3)

[0025] (3.2) Neighbor node sampling: For each node v∈V, randomly sample a portion of its neighbor nodes. Assume that each node samples k neighbor nodes, denoted as N(v). The sampling process can be expressed by the following formula:

[0026] N(v)=sample({u∈V|(v,u)∈E},k) (4)

[0027] The sample function represents randomly sampling k nodes from the set of neighbor nodes.

[0028] (3.3) Feature aggregation: For each node v, aggregate its own features with the sampled neighbor node features. Assume that the initial feature of node v is represented as Sampled neighbor node feature representation Then the aggregation process of layer l can be expressed as:

[0029]

[0030] Among them, σ represents the activation function, W (l) Represents the weight matrix of the lth layer, and the MEAN function represents the mean aggregation operation.

[0031] (3.4) Node embedding generation: Through multi-layer sampling and aggregation, we finally get the embedding representation h of each node v ,These embedding representations contain the structure and feature information of the node itself and its neighborhood.

[0032] (3.5) Graph-level feature generation: The embedded representation of each node is mapped to the graph-level feature space through the fully connected layer. Assume that the weight matrix of the fully connected layer is W g , the bias vector is b g , then the graph-level feature is expressed as:

[0033] h G =σ(W g ·∑ v∈v g v +b g ) (6)

[0034] Among them, ∑ v∈V h v represents the sum of all node embedding representations, and σ represents the activation function.

[0035] Furthermore, in step (4), a contrastive learning module is constructed to generate triple sample pairs online according to the sample labels and the graph-level features generated in step (3), and perform triple contrastive learning; the specific steps are as follows:

[0036] (4.1) Triple sample pair selection: A triple sample pair (a, p, n), where a represents the benchmark sample, p represents the positive sample of the same category as the benchmark sample, and n represents the negative sample of a different category from the benchmark sample. The present invention adopts a strategy method of online generation of sample groups to generate triple sample pairs and selects "semi-hard" negative samples to train the model. Specifically, in a small batch of samples, first, a binary adjacency matrix is ​​constructed according to the label in Indicates that sample i and sample j belong to the same class, Represents different classes. Then, the pairwise distance matrix D of these samples is calculated, where D ij =‖f i -f j ‖2 represents the Euclidean distance between sample i and sample j. i ,f j are the graph-level features generated by samples i and j in step (3). The semi-hard negative samples selected at the end require that the distance between negative samples is greater than the distance between positive samples but as close as possible. Therefore, for each positive sample pair (a, p), a negative sample n is selected to satisfy: D ap <D an However, when there are no negative samples that meet the conditions, the negative sample with the largest distance is selected.

[0037] In the specific implementation, a mask matrix M is constructed, where M an =1 means D an >D ap , otherwise M an = 0. Then select the minimum negative sample distance that satisfies the mask condition.

[0038] (4.2) Calculate triplet loss: For each positive sample pair (a, p) and the corresponding negative sample n, calculate the triplet contrast loss:

[0039] L tcl =max(D ap -D an +margin,0) (7)

[0040] Where margin is a hyperparameter, which represents the minimum difference between the positive and negative sample distances.

[0041] Furthermore, in step (5), a classifier is constructed to classify the EEG data into emotions. The specific steps are as follows:

[0042] (5.1) Fully connected layer: The graph-level features h generated in step (3) are G , input to the fully connected layer and mapped to the classification output space. Assume that the weight matrix of the fully connected layer is W c and the bias vector is bc , then the classification output is expressed as:

[0043]

[0044] (5.2) Softmax function: for classification output Perform softmax transformation to obtain the probability distribution p of each category. Assuming the number of categories is K, the probability of category i is expressed as:

[0045]

[0046] (5.3) Calculate cross entropy loss: Use the cross entropy function to calculate the classification loss. Assume that the one-hot encoding of the true category is represented as , then the cross entropy loss function is expressed as:

[0047]

[0048] The second aspect of the present invention relates to an EEG emotion recognition device based on contrastive learning and graph neural networks, comprising a memory and one or more processors, wherein the memory stores executable code, and when the one or more processors execute the executable code, they are used to implement an EEG emotion recognition method based on contrastive learning and graph neural networks of the present invention.

[0049] The third aspect of the present invention relates to a computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements an EEG emotion recognition method based on contrastive learning and graph neural network of the present invention.

[0050] The advantages of the present invention are:

[0051] First, by introducing the contrastive learning mechanism, the feature representation is effectively optimized, making the feature differences between different emotion categories more significant, thereby improving the accuracy of emotion recognition. Contrastive learning enhances the model's ability to distinguish different emotional states through the generation and training of triplet sample pairs, solving the problem of low recognition accuracy in traditional methods.

[0052] Secondly, the GraphSAGE algorithm is used to process EEG signals, fully capturing the spatiotemporal dependencies in the signals and enhancing the robustness of the model when processing complex data. GraphSAGE effectively handles the high dimensionality and strong noise problems of EEG signals by sampling and aggregating the features of neighboring nodes. Compared with other graph neural network (GNN) methods, GraphSAGE has higher computational efficiency and scalability, and can efficiently learn node representations on large-scale data. In addition, GraphSAGE's neighbor sampling mechanism significantly reduces computational overhead, avoids the tedious process of full-graph calculation, and improves the stability and reliability of emotion recognition.

[0053] In summary, the present invention combines the advantages of contrastive learning and GraphSAGE algorithms to improve the accuracy of emotion recognition while enhancing the robustness of the model, providing an efficient and accurate method for the field of EEG emotion recognition. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 An overall flow chart of an EEG emotion recognition method based on contrastive learning and graph neural network provided in an embodiment;

[0055] Figure 2 A schematic diagram of the structure of a node feature extraction module of an EEG emotion recognition method based on contrastive learning and graph neural network provided in an embodiment;

[0056] Figure 3 A structural schematic diagram of a graph-level feature extraction module of an EEG emotion recognition method based on contrastive learning and graph neural network is provided in an embodiment.

[0057] Figure 4 This is a box plot of the accuracy of emotion recognition on the valence dimension for 32 subjects in the DEAP dataset;

[0058] Figure 5 Box plot of the accuracy of emotion recognition on the arousal dimension for 32 subjects in the DEAP dataset. DETAILED DESCRIPTION

[0059] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0060] Example 1

[0061] Figure 1 : is an overall flow chart of the method of the present invention. The embodiment provides an EEG emotion recognition method based on contrastive learning and graph neural network, which includes the following steps:

[0062] (1) The sliding window method is used to sample the EEG signal sequence, and the baseline effect is removed by the baseline averaging method. The specific steps are as follows:

[0063] (1.1) Use sliding window to sample EEG signal data: For EEG signal data with C electrodes and data length L, D = (d1, d2, ..., d C ),in Use a moving window with a window size of T and a stride size of S to sample the EEG signal data and generate Samples

[0064] (1.2) Remove the baseline effect by using the baseline averaging method: The baseline data is also divided into several segments using the same sliding window, and then the average of these baseline segments is used as the baseline average. Represents the basic emotion of the subject at that time. Then, the EEG signal data obtained in (1.1) is sampled and the baseline average is subtracted to remove the baseline effect. The formula is as follows:

[0065]

[0066] in It is the EEG signal after removing the baseline effect.

[0067] (2) Construct node feature extraction module, such as Figure 2 As shown, it includes: extracting the time-dependent features of EEG signals through temporal convolution, and extracting frequency-specific spatial information through depth-separable convolution. The specific steps are as follows:

[0068] (2.1) Extracting the temporal dependency features of EEG signals through temporal convolution: The temporal convolution part contains three convolutional layers with different kernel sizes (1×15), (1×7), and (1×3), which are used to learn long-term, medium-term, and short-term temporal dependencies, respectively. In order to maintain the spatial dimension of the input EEG trial, zero padding of sizes (0×7), (0×3), and (0×1) is added. Number of convolution kernels: 30, 60, and 90 per layer. Each convolution layer is followed by batch normalization and parametric rectified linear activation function (PReLU). Three layers of convolution are superimposed for a total of nine convolution operations. The convolution operation can be expressed as:

[0069] y=f(W*x+b) (2)

[0070] Among them, y represents the output feature map, W is the convolution kernel, * represents the convolution operation, x is the input signal, b represents the bias, and f represents the activation function.

[0071] (2.2) Depthwise separable convolution extracts frequency-specific spatial information: The depthwise separable convolution part of the present invention consists of two layers of convolution operations and corresponding activation and normalization layers. First, the features of the input data in the depth dimension are aggregated through a three-dimensional convolution layer. Then, after adjusting to the appropriate dimension, the features in the spatial dimension are extracted through a two-dimensional convolution layer. Next, the output is standardized using a batch normalization layer, and nonlinearity is introduced through the PReLU activation function to improve the expressiveness and training stability of the model.

[0072] (3) Construct a graph-level feature extraction module, such as Figure 3As shown in the figure, the GraphSAGE algorithm is used to sample and aggregate the features of neighbor nodes on the complete undirected graph, generate an embedded representation for each node, and generate graph-level features through a fully connected layer. The specific steps are as follows:

[0073] (3.1) Constructing an undirected graph: A classic undirected graph G = (V, E, A), where V represents the vertex set, C = |V| represents the number of vertices, E represents the set of edges between nodes, and the adjacency matrix A∈R N×N Middle ij Indicates the importance of the connection between the i-th node and the j-th node. The present invention uses a complete undirected graph, each node is represented by an integer ranging from 0 to C, and these nodes are denoted as a set V = {0, 1, 2...C-1}. It is necessary to generate all the combinations between the nodes, represented as edges. The combination can be represented as:

[0074] E={(i,j)|0 <i<C,0<j<C,i≠j} (3)

[0075] (3.2) Neighbor node sampling: For each node v∈V, randomly sample a portion of its neighbor nodes. Assume that each node samples k neighbor nodes, denoted as N(v). The sampling process can be expressed by the following formula:

[0076] N(v)=sample({u∈V|(v,y)∈E},k) (4)

[0077] The sample function represents randomly sampling k nodes from the set of neighbor nodes.

[0078] (3.3) Feature aggregation: For each node v, aggregate its own features with the sampled neighbor node features. Assume that the initial feature of node v is represented as Sampled neighbor node feature representation Then the aggregation process of layer l can be expressed as:

[0079]

[0080] Among them, σ represents the activation function, W (l) Represents the weight matrix of the lth layer, and the MEAN function represents the mean aggregation operation.

[0081] (3.4) Node embedding generation: Through multi-layer sampling and aggregation, we finally get the embedding representation h of each node v ,These embedding representations contain the structure and feature information of the node itself and its neighborhood.

[0082] (3.5) Graph-level feature generation: The embedded representation of each node is mapped to the graph-level feature space through the fully connected layer. Assume that the weight matrix of the fully connected layer is W g , the bias vector is b g , then the graph-level feature is expressed as:

[0083] h G =σ(W g ·∑ v∈V h v +b g ) (6)

[0084] Among them, ∑ v∈V h v represents the sum of all node embedding representations, and σ represents the activation function.

[0085] (4) Construct a contrastive learning module to generate triple sample pairs online based on the sample labels and the graph-level features generated in step (3), and perform triple contrastive learning. The specific steps are as follows:

[0086] (4.1) Triple sample pair selection: A triple sample pair (a, p, n), where a represents the benchmark sample, p represents the positive sample of the same category as the benchmark sample, and n represents the negative sample of a different category from the benchmark sample. The present invention adopts a strategy method of online generation of sample groups to generate triple sample pairs and selects "semi-hard" negative samples to train the model. Specifically, in a small batch of samples, first, a binary adjacency matrix is ​​constructed according to the label in Indicates that sample i and sample j belong to the same class, Represents different classes. Then, the pairwise distance matrix D of these samples is calculated, where D ij =‖f i -f j ‖2 represents the Euclidean distance between sample i and sample j. i ,f j are the graph-level features generated by samples i and j in step (3). The semi-hard negative samples selected at the end require that the distance between negative samples is greater than the distance between positive samples but as close as possible. Therefore, for each positive sample pair (a, p), a negative sample n is selected to satisfy: D ap <D an However, when there are no negative samples that meet the conditions, the negative sample with the largest distance is selected.

[0087] In the specific implementation, a mask matrix M is constructed, where M an =1 means D an >D ap , otherwise M an = 0. Then select the minimum negative sample distance that satisfies the mask condition.

[0088] (4.2) Calculate triplet loss: For each positive sample pair (a, p) and the corresponding negative sample n, calculate the triplet contrast loss:

[0089] L tcl =max(D ap -D an +margin,0) (7)

[0090] Where margin is a hyperparameter, which represents the minimum difference between the positive and negative sample distances.

[0091] (5) Construct a classifier to classify emotions based on EEG data. The specific steps are as follows:

[0092] (5.1) Fully connected layer: The graph-level features h generated in step (3) are G , input to the fully connected layer and mapped to the classification output space. Assume that the weight matrix of the fully connected layer is W c and the bias vector is b c , then the classification output is expressed as:

[0093]

[0094] (5.2) Softmax function: for classification output Perform softmax transformation to obtain the probability distribution p of each category. Assuming the number of categories is K, the probability of category i is expressed as:

[0095]

[0096] (5.3) Calculate cross entropy loss: Use the cross entropy function to calculate the classification loss. Assume that the one-hot encoding of the true category is represented as The cross entropy loss function is expressed as:

[0097]

[0098] Based on the above embodiments, the present application has been experimentally verified as follows:

[0099] Experimental environment:

[0100] Operating system: Ubuntu 20.04.1LTS

[0101] Processor: Intel Xeon Silver 4214R

[0102] GPU: NVIDIA GeForce RTX 3090

[0103] Deep learning framework: PyTorch 2.3.1

[0104] Experimental process:

[0105] 1. Dataset:

[0106] DEAP (Database for Emotion Analysis using Physiological Signals) is a physiological signal database for emotion analysis. It contains electroencephalogram (EEG), electrocardiogram (ECG), skin conductance (EDA) and electromyography (EMG) signals of 32 subjects while watching 40 one-minute music videos. After watching each music video clip, the participants rated their emotional experience based on a discrete 9-point scale. These emotions include happiness, excitement, anger, stress, sadness, fear, surprise, calmness and boredom.

[0107] 2. Model training:

[0108] When conducting a single subject's EEG emotion study on the DEAP dataset, a 10-fold cross-validation experimental method was used. Specifically, each subject's EEG signal samples were shuffled and divided into 10 parts, 9 of which were used as training sets and 1 as a test set. The data of the training set and the test set came from the same subject. In order to classify according to the emotional label, 5 was selected as the classification threshold based on the subject's self-assessment score range (1 to 9). In terms of the two emotional dimensions of arousal and valence, the labels were divided into two categories, namely high arousal and low arousal, high valence and low valence.

[0109] The specific parameter settings during the experiment are shown in Table 1:

[0110] Table 1

[0111]

[0112] Among them, the parameter "window_size" indicates the size of the sliding window, and its value 1 indicates that the sliding window size is 1 second; the parameter "overlap" indicates the step size of the sliding window during the sliding process, and its value 0 indicates no overlap; the parameter "batch_size" indicates the number of data samples processed simultaneously during each training process; the parameter "margin" refers to the hyperparameter in the triplet loss that indicates the minimum difference between the positive and negative sample distances; the parameter "epoch" refers to the number of model training times; the parameter "lr" indicates the learning rate; the parameters "a" and "b" refer to the proportion of triplet loss and cross entropy loss, respectively; the parameter "weight_decay" indicates the weight decay value.

[0113] 3. Experimental results

[0114] Table 2 compares the accuracy (ACC%) results of feature extraction and classification of the present invention and the disclosed SFENet algorithm, LResNet algorithm, CSDNN algorithm, MCNN algorithm, DLSTM algorithm, ERDL algorithm, and GLFANet algorithm on the DEAP dataset.

[0115] Table 2

[0116]

[0117] The experimental results are shown in Table 2. The average accuracy of the binary classification of 32 subjects in the two dimensions of valence and arousal was 95.01% and 96.68%, respectively, which are higher than the compared methods. Figure 4 and Figure 5 As shown in the box plots of the accuracy of 32 subjects in the two dimensions of valence and arousal, the classification accuracy of all subjects was above 90%, which shows that the method proposed in the present invention has significant advantages in the EEG emotion recognition task and verifies its effectiveness and superiority.

[0118] Example 2

[0119] The present embodiment relates to an EEG emotion recognition device based on contrastive learning and graph neural network, comprising a memory and one or more processors, wherein the memory stores executable code, and when the one or more processors execute the executable code, they are used to implement an EEG emotion recognition method based on contrastive learning and graph neural network of embodiment 1.

[0120] Example 3

[0121] This embodiment relates to a computer-readable storage medium on which a program is stored. When the program is executed by a processor, an EEG emotion recognition method based on contrastive learning and graph neural network of embodiment 1 is implemented.

[0122] The above description is only an embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent substitution, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of the claims of the present invention.

Claims

1. A method for EEG emotion recognition based on contrastive learning and graph neural network, characterized by: The following steps are involved: (1) Data preprocessing: remove the baseline signal before the test, use the sliding window method to sample the EEG signal sequence, and remove the baseline effect by the baseline averaging method; (2) constructing a node feature extraction module, including: extracting the time-dependent features of the EEG signal through temporal convolution and extracting frequency-specific spatial information through depthwise separable convolution; (3) Construct a graph-level feature extraction module, use the GraphSAGE algorithm to sample and aggregate the features of neighbor nodes on the complete undirected graph, and generate graph-level features through a fully connected layer; (4) Construct a contrastive learning module to generate triple sample pairs online based on the sample labels and the graph-level features generated in step (3), and perform triple contrastive learning; (5) Construct a classifier to classify emotions in EEG data, wherein the classifier includes a fully connected layer and a softmax function.

2. The method for EEG emotion recognition based on contrastive learning and graph neural network according to claim 1, characterized in that: In step (1), the sliding window method is used to sample the EEG signal sequence, and the baseline effect is removed by the baseline averaging method. The specific steps are as follows: (1.1) Sliding window is used to sample EEG signal data: For EEG signal data with C electrodes and data length L, D = (d1, d2, ..., d C ),in Use a moving window with a window size of T and a stride size of S to sample the EEG signal data and generate Samples (1.2) Remove the baseline effect by using the baseline averaging method: The baseline data is also divided into several segments using the same sliding window, and then the average of these baseline segments is used as the baseline average. Represents the basic emotion of the subject at that time; then, the EEG signal data sampled in step (1.1) is subtracted from the baseline average to remove the baseline effect. The formula is as follows: x i =x i -b basemean ,i=1,2…,M (1) in It is the EEG signal after removing the baseline effect.

3. The method for EEG emotion recognition based on contrastive learning and graph neural network according to claim 1, characterized in that: In step (2), a node feature extraction module is constructed, including: extracting the time-dependent features of the EEG signal through temporal convolution, and extracting frequency-specific spatial information through depth-separable convolution; the specific steps are as follows: (2.1) Extracting the temporal dependency features of EEG signals through temporal convolution: The temporal convolution part contains three convolutional layers with different kernel sizes (1×15), (1×7), and (1×3), which are used to learn long-term, medium-term, and short-term temporal dependencies, respectively; in order to maintain the spatial dimension of the input EEG trial, zero padding of sizes (0×7), (0×3), and (0×1) is added; the number of convolution kernels: 30, 60, and 90 per layer; each convolution layer is followed by batch normalization and parametric rectified linear activation function (PReLU); three layers of convolution are superimposed for a total of nine convolution operations; the convolution operation can be expressed as: y=f(W*x+b) (2) Among them, y represents the output feature map, W is the convolution kernel, * represents the convolution operation, x is the input signal, b represents the bias, and f represents the activation function; (2.2) Depthwise separable convolution extracts frequency-specific spatial information: The depthwise separable convolution part consists of two layers of convolution operations and corresponding activation and normalization layers. First, the features of the input data in the depth dimension are aggregated through the three-dimensional convolution layer. Then, after adjusting to the appropriate dimension, the features in the spatial dimension are extracted through the two-dimensional convolution layer. Next, the output is standardized using the batch normalization layer, and nonlinearity is introduced through the PReLU activation function to improve the expressiveness and training stability of the model.

4. The method for EEG emotion recognition based on contrastive learning and graph neural network according to claim 1, characterized in that: In step (3), a graph-level feature extraction module is constructed. The GraphSAGE algorithm is used to sample and aggregate the features of neighbor nodes on the complete undirected graph, generate an embedded representation for each node, and generate graph-level features through a fully connected layer. The specific steps are as follows: (3.1) Constructing an undirected graph: A classic undirected graph G = (V, E, A), where V represents the vertex set, C = |V| represents the number of vertices, E represents the set of edges between nodes, and the adjacency matrix A∈R N×N Middle ij Indicates the importance of the connection between the i-th node and the j-th node; a complete undirected graph is used, each node is represented by an integer ranging from 0 to C, and these nodes are recorded as a set V = {0,1,2...C-1}. It is necessary to generate all the combinations between the nodes, represented as edges; the combination can be expressed as: E={(i,j)|0 <i<C,0<j<C,i≠j} (3) (3.2) Neighbor node sampling: For each node v∈V, randomly sample a portion of its neighbor nodes; assume that each node samples k neighbor nodes, denoted as N(v); the sampling process can be expressed by the following formula: N(v)=sample({u∈V|(v,u)∈E},k) (4) Among them, the sample function represents randomly sampling k nodes from the neighbor node set; (3.3) Feature aggregation: For each node v, aggregate its own features with the sampled neighbor node features; assuming that the initial feature of node v is expressed as Sampled neighbor node feature representation Then the aggregation process of layer l can be expressed as: Among them, σ represents the activation function, W (l) represents the weight matrix of the lth layer, and the MEAN function represents the mean aggregation operation; (3.4) Node embedding generation: Through multi-layer sampling and aggregation, we finally get the embedding representation h of each node v ,These embedding representations contain the structure and feature information of the node itself and its neighborhood; (3.5) Graph-level feature generation: The embedded representation of each node is mapped to the graph-level feature space through a fully connected layer; assuming that the weight matrix of the fully connected layer is W g , the bias vector is b g , then the graph-level feature is expressed as: h G =σ(W g ·∑ v∈V h v +b g ) (6) Among them, ∑ v∈V h v represents the sum of all node embedding representations, and σ represents the activation function.

5. The method for EEG emotion recognition based on contrastive learning and graph neural network according to claim 1, characterized in that: In step (4), a contrastive learning module is constructed to generate triple sample pairs online based on the sample labels and the graph-level features generated in step (3), and perform triple contrastive learning. The specific steps are as follows: (4.1) Triple sample pair selection: A triple sample pair (a, p, n), where a represents the benchmark sample, p represents the positive sample of the same category as the benchmark sample, and n represents the negative sample of a different category from the benchmark sample; the strategy of generating sample groups online is used to generate triple sample pairs, and "semi-hard" negative samples are selected to train the model. Specifically, in the small batch of samples, first, a binary adjacency matrix is ​​constructed according to the label in Indicates that sample i and sample j belong to the same class, Represents different classes; then, calculate the pairwise distance matrix D of these samples, where D ij =‖f i -f j ‖2 represents the Euclidean distance between sample i and sample j; where f i ,f j are the graph-level features generated by samples i and j in step (3) respectively; the semi-hard negative samples selected at the end require that the distance between negative samples is greater than the distance between positive samples but as close as possible; therefore, for each positive sample pair (a, p), a negative sample n is selected to satisfy: D ap <D an ; However, when there is no negative sample that meets the conditions, the negative sample with the largest distance is selected; In the specific implementation, a mask matrix M is constructed, where M an =1 means D an >D ap , otherwise M an =0; then select the minimum negative sample distance that meets the mask condition; (4.2) Calculate triplet loss: For each positive sample pair (a, p) and the corresponding negative sample n, calculate the triplet contrast loss: L tcl =max(D ap -D an +margin,0) (7) Where margin is a hyperparameter, which represents the minimum difference between the positive and negative sample distances.

6. The method for EEG emotion recognition based on contrastive learning and graph neural network according to claim 1, characterized in that: In step (5), a classifier is constructed to classify emotions on EEG data. The specific steps are as follows: (5.1) Fully connected layer: The graph-level features h generated in step (3) are G , input to the fully connected layer and mapped to the classification output space; assuming that the weight matrix of the fully connected layer is W c and the bias vector is b c , then the classification output is expressed as: (5.2) Softmax function: for classification output Perform softmax transformation to obtain the probability distribution p of each category; assuming the number of categories is K, the probability of category i is expressed as: (5.3) Calculate cross entropy loss: Use the cross entropy function to calculate the classification loss; assume that the one-hot encoding of the true category is represented as The cross entropy loss function is expressed as:

7. An EEG emotion recognition device based on contrastive learning and graph neural network, characterized in that: It comprises a memory and one or more processors, wherein the memory stores executable codes, and when the one or more processors execute the executable codes, they are used to implement an EEG emotion recognition method based on contrastive learning and graph neural network as described in any one of claims 1 to 6.

8. A computer-readable storage medium, characterized in that: A program is stored thereon, and when the program is executed by a processor, an EEG emotion recognition method based on contrastive learning and graph neural network as described in any one of claims 1 to 6 is implemented.