A method and system for domain adaptation of EEG signals based on cross-attention
Through the EEG signal field adaptation method with cross-attention, the problems of time-consuming and feature loss in the classification of EEG signal across subjects were solved, and high-precision cross-domain EEG signal cognitive load evaluation is achieved, which improves classification accuracy and generalization ability.
Patent Information
- Application Number
- CN202510745554.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2045-06-05
AI Technical Summary
The existing technology has time-consuming and costly problems in the classification of EEG signals across subjects. In addition, traditional methods lead to shallow features loss in deep-domain network training, which cannot effectively solve the contradiction between feature alignment and distribution alignment, affecting classification accuracy.
The domain adaptation method of EEG signals based on cross attention is adopted, and the most similar set of source domains is filtered through the source domain selector, and the global cross attention aligner is aligned with the global cross attention alignment, and the domain edge distribution alignment is achieved through the alternating training of the discriminator and the global cross attention aligner, and the second classifier is finally trained to classify EEG signals.
The accuracy and generalization performance of cross-domain EEG signal cognitive load evaluation is improved, feature alignment and inter-group specific protection are achieved, and the recognition accuracy is high and generalization performance is strong.
Smart Images

Figure CN120257027B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electroencephalogram (EEG) signal analysis, and in particular to an EEG signal domain adaptation method and system based on cross-attention. Background Art
[0002] In recent years, significant progress has been made in feature extraction and classification based on electroencephalogram (EEG). However, due to the significant individual variability of EEG signals, cross-subject feature extraction and classification remain challenging. Traditional cross-subject EEG classification methods often require data re-collection and calibration for each new subject, which is time-consuming, labor-intensive, and costly. Therefore, low-label cross-subject EEG classification is a key issue. Some current studies focus on identifying distinct and stable invariant features across subjects, using machine learning methods to identify distinct and shared features and construct cross-subject models. Many studies have also utilized transfer learning methods to explore distribution alignment between source and target domains. Some methods use statistical metrics such as maximum mean difference (MMD) and correlation alignment to reduce inter-domain differences. Inspired by generative adversarial networks (GANs), adversarial learning-based methods employ a discriminator to automatically reduce distribution differences and learn domain-invariant features. However, these domain adaptation methods align distribution statistics by constraining features or feature similarity. This tends to smooth feature gaps to find a shared feature space, leading to the loss of shallow features during deep domain adaptation network training. They fail to effectively resolve the conflict between distribution alignment and feature preservation, which in turn affects classification accuracy. Therefore, overcoming these challenges and further improving cross-subject classification performance based on EEG signals has become a key technical issue that needs to be addressed urgently. Summary of the Invention
[0003] Technical problem to be solved by the present invention: In response to the above-mentioned problems in the prior art, a method and system for EEG signal domain adaptation based on cross-attention is provided. The present invention aims to solve the problems of feature alignment and inter-group specificity protection in the cognitive load assessment of EEG signals across subjects in the prior art, and to improve the accuracy and generalization performance of cross-domain EEG signal cognitive load assessment.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0005] A method for domain adaptation of EEG signals based on cross-attention includes the following steps:
[0006] S101, obtaining EEG signal data samples of subjects in the target domain and multiple source domains respectively;
[0007] S102, using a source domain selector including a first classifier to select, for each EEG signal data sample of a subject in the target domain, k EEG signal data samples of the subject that are most similar to the EEG signal data sample of the subject in multiple source domains to form an optimal source domain set;
[0008] S103, inputting each EEG signal data sample of the subject in the target domain and its corresponding optimal source domain set into a global cross-attention aligner composed of a feature extraction network and a global adaptation module based on a cross-attention mechanism, using the feature extraction network to extract shallow features of the EEG signal data sample of the subject in the target domain and shallow features of each EEG signal data sample in the optimal source domain set, and using the global adaptation module to guide the conditional alignment of the shallow features of the EEG signal data sample of the subject in the target domain and the shallow features of each EEG signal data sample in the optimal source domain set;
[0009] S104, using the shallow features after conditional alignment as the input of the second classifier and discriminator, and guiding the alignment of the domain edge distribution by alternating adversarial training of the discriminator and the global cross attention aligner;
[0010] S105 , freezing the network parameters of the discriminator and the global cross attention aligner to train a second classifier for EEG signal classification according to the input EEG signal data.
[0011] Optionally, the source domain selector in step S102 is composed of an encoder and a first classifier, both of which are composed of three fully connected layers, and each source domain adopts a source domain selector that is trained separately and whose parameters are not shared.
[0012] Optionally, the feature extraction network in step S103 is a three-cascaded symmetric dual-pathway network, which includes two paths corresponding to the source domain and the target domain respectively, and the size of the EEG signal data samples of the source domain and the target domain input by the two paths is the same. Each channel includes an input layer, a frequency domain convolution layer, a time domain convolution layer, a channel convolution layer, an average pooling layer and a projection layer connected in sequence. The projection layer is used to project the extracted features into a single channel and an embedding sequence of the same dimension suitable for processing based on the attention mechanism as the shallow features finally obtained by the feature extraction network.
[0013] Optionally, in step S103, the conditional alignment of shallow features of the EEG signal data samples of the subjects in the target domain and shallow features of each EEG signal data sample in the optimal source domain set using the global adaptation module includes:
[0014] S201, respectively, splitting the shallow features of the EEG signal data samples of the subjects in the target domain and the shallow features of the EEG signal data samples in the optimal source domain set into multiple slices of the same length, and using a linear layer to generate a key matrix K, a query matrix Q and a value matrix V, wherein the key matrix K and the query matrix Q come from the shallow features of the EEG signal data samples in the optimal source domain set, and the value matrix V comes from the shallow features of the EEG signal data samples of the subjects in the target domain;
[0015] S202, perform attention query through multiple attention heads according to the following formula:
[0016] ,
[0017] ,
[0018] in, For the Attention query results of attention heads, For attention query, is the EEG signal data sample in the source domain, is the EEG signal data sample in the target domain, 、 and Respectively The weight matrices of queries, keys, and values for each attention head, is the dimension of the key matrix K;
[0019] S203, the attention query results of each attention head are spliced together to obtain the shallow features after conditional alignment using the following formula:
[0020] ,
[0021] in, In order to splice the attention query results of each attention head to obtain the shallow features after conditional alignment, ~ They are the attention query results of the 1st to hth attention heads respectively.
[0022] Optionally, before inputting the EEG signal data samples of each subject in the target domain and its corresponding optimal source domain set into the global cross-attention aligner composed of a feature extraction network and a global adaptation module based on the cross-attention mechanism in step S103, the EEG signal data samples of each subject in the target domain are also enhanced: a weight value is generated for each EEG signal data sample of the subject in the target domain and normalized, two EEG signal data samples are randomly selected, and a new EEG signal data sample is generated by weighted combination using the normalized weight value, and the label of the EEG signal data sample adopts the label of the original EEG signal data sample with a larger normalized weight value.
[0023] Optionally, in step S104, when guiding the alignment of the domain edge distribution by adversarial alternating training of the discriminator and the global cross attention aligner, a gradient reversal layer GRL is used to force the feature distribution to converge, and the functional expression of the adopted loss function is:
[0024] ,
[0025] ,
[0026] in, The loss function used for adversarial alternating training of the discriminator and the global cross-attention aligner, Represents EEG signal data samples From the source domain , Represents EEG signal data samples From the target domain , Represents EEG signal data samples respectively From the random interpolation domain , is the discriminator, is the cross attention mechanism, For feature extraction network right The shallow features extracted are For feature extraction network right The shallow features extracted are is a hyperparameter that controls the penalty strength. is the gradient reversal layer GRL The calculated gradient penalty is is the gradient operator, random interpolation domain Sample The construction method is:
[0027]
[0028] in, are random weights, and .
[0029] Optionally, when freezing the network parameters of the discriminator and the global cross attention aligner in step S105 to train the second classifier, the functional expression of the loss function used is:
[0030] ,
[0031] ,
[0032] ,
[0033] in, The loss function used when training the second classifier to freeze the network parameters of the discriminator and the global criss-cross attention aligner, is the classification loss, To combat losses, and are the number of EEG signal data samples in the source domain and target domain respectively, is the number of EEG signal categories, is the label of the ith EEG signal data sample belonging to the EEG signal category c, is the prediction value of the second classifier for the i-th EEG signal data sample belonging to the EEG signal category c, Represents EEG signal data samples From the source domain , is the discriminator, is the cross attention mechanism, For feature extraction network right The shallow features extracted.
[0034] In addition, the present invention also provides an EEG signal domain adaptation system based on cross-attention, comprising a microprocessor and a memory connected to each other, wherein the microprocessor is programmed or configured to execute the EEG signal domain adaptation method based on cross-attention.
[0035] In addition, the present invention also provides a computer-readable storage medium, which stores a computer program or instruction, and the computer program or instruction is programmed or configured to execute the cross-attention-based EEG signal domain adaptation method through a processor.
[0036] In addition, the present invention also provides a computer program product, including a computer program or instructions, which are programmed or configured to execute the cross-attention-based EEG signal domain adaptation method through a processor.
[0037] Compared with the existing technology, the present invention can mainly achieve the following beneficial effects: the EEG signal domain adaptation method based on cross-attention of the present invention includes obtaining EEG signal features of the target domain and multiple source domains; calculating the similarity between the target domain and each source domain through the source domain selector, screening out the Top-k source domains and generating weighted enhanced target domain features; using the global cross-attention aligner (GCA) to extract spatiotemporal features through a multi-stage cascaded symmetric dual-pathway network, while achieving conditional distribution alignment between the source domain and the target domain, retaining key shallow features through the cross-attention mechanism and residual structure; using the domain discriminator for adversarial training to align the marginal distribution; finally, jointly optimizing the classifier to achieve high-precision evaluation of cross-subject cognitive load. The EEG signal domain adaptation method based on cross-attention of the present invention can solve the problems of feature alignment and inter-group specificity protection in the cross-subject cognitive load evaluation of EEG signals in the existing technology, and improve the accuracy and generalization performance of cross-domain EEG signal cognitive load evaluation. To address the difficult trade-off between cross-subject EEG signal feature alignment and preservation, the present invention designs a global cross-attention aligner based on cross-attention, and integrates it with the discriminator, classifier and source domain selector into a complete cross-subject EEG signal classification algorithm, which can achieve the problem of cross-subject EEG signal feature alignment and group-specific protection, and has the advantages of high recognition accuracy and strong generalization performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 Schematic diagram of the basic process of the method of the embodiment of the present invention.
[0039] Figure 2 Schematic diagram of the working principle of the source domain selector in an embodiment of the present invention.
[0040] Figure 3 Schematic diagram of the network structure of the global cross-attention aligner and its back-end part in an embodiment of the present invention.
[0041] Figure 4 Schematic diagram of the network structure of the feature extraction network in an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to enable those skilled in the art to better understand the technical solution of the present invention, the technical solution of the present invention will be further described in detail below with reference to the accompanying drawings in the embodiments of the present invention.
[0043] like Figure 1 As shown, the EEG signal domain adaptation method based on cross attention in this embodiment includes the following steps:
[0044] S101, obtaining EEG signal data samples of subjects in the target domain and multiple source domains respectively;
[0045] S102, using a source domain selector including a first classifier to select, for each EEG signal data sample of a subject in the target domain, k EEG signal data samples of the subject that are most similar to the EEG signal data sample of the subject in multiple source domains to form an optimal source domain set;
[0046] S103, inputting each EEG signal data sample of the subject in the target domain and its corresponding optimal source domain set into a global cross-attention aligner composed of a feature extraction network and a global adaptation module based on a cross-attention mechanism, using the feature extraction network to extract shallow features of the EEG signal data sample of the subject in the target domain and shallow features of each EEG signal data sample in the optimal source domain set, and using the global adaptation module to guide the conditional alignment of the shallow features of the EEG signal data sample of the subject in the target domain and the shallow features of each EEG signal data sample in the optimal source domain set;
[0047] S104, using the shallow features after conditional alignment as the input of the second classifier and discriminator, and guiding the alignment of the domain edge distribution by alternating adversarial training of the discriminator and the global cross attention aligner;
[0048] S105 , freezing the network parameters of the discriminator and the global cross attention aligner to train a second classifier for EEG signal classification according to the input EEG signal data.
[0049] Figure 2 This is a schematic diagram of the working principle of the source domain selector in this embodiment. Figure 2 The target domain contains m subjects (subjects 1 to m). The source domain selector is used to select the EEG data samples of the k subjects (subjects 1 to k) most similar to each target domain subject's EEG data sample from multiple source domains to form an optimal source domain set. Ultimately, m optimal source domain sets are selected, containing a total of m × k EEG data samples from subjects in the source domains. The EEG data samples in step S101 of this embodiment refer to EEG signals containing multiple channels induced by subjects completing a single cognitive load task experiment. When subjects perform a specific task, the cerebral cortex is stimulated by external stimuli, generating associated evoked electrical activity. The method of this embodiment uses EEG signals, an objective physical signal, to implement cognitive load assessment, which can alleviate the subjective influence of interfering tasks brought about by traditional assessment methods such as self-administered questionnaires, effectively improving the accuracy and generalization ability of cognitive load assessment.
[0050] As an optional implementation, the acquisition of EEG signal features in this embodiment includes: denoising the EEG signals of multiple channels of each subject; dividing the denoised EEG signals into windows of fixed-size time; calculating the power spectral density (PSD) of each electrode in the 1-100 Hz frequency band for the EEG data in each time window and normalizing it. Specifically, the EEG frequency domain features of different channels are obtained through fast Fourier transform. The frequency bands include δ (1-3Hz), θ (4-7Hz), α (8-13Hz), β (13-30Hz) and γ (31-50Hz). Therefore, we obtain frequency domain features in sequential time, use the time-frequency data as input for subsequent models, and select a very small number of target domains as labeled data to input the model for training. Denoising can be performed using feasible noise reduction methods as needed. For example, as an optional implementation, the noise reduction in this embodiment includes: bandpass filtering the EEG data to remove low-frequency drift and high-frequency noise. As an optional implementation, in this embodiment, a 0.5-50 Hz bandpass filter is used to process the original EEG signal to remove noise interference; myoelectric, oculoscopic, and electrocardiographic artifacts are removed from the filtered signal. Myoelectric artifacts are detected and removed using the MNE built-in function, and electrooculographic (EOG) and electrocardiographic (ECG) artifacts are removed using independent component analysis (ICA); and the data is downsampled.
[0051] The source domain selector is a classifier that uses a small amount of labeled target domain data to test each other trained source domain model and selects the k source domains with the highest accuracy as the subsequent source domain training set L to maximize the use of positive source domain data. The source domain selector is a classifier that can be used as needed to adopt the required network model, such as Figure 2 As shown, as an optional implementation, the source domain selector in step S102 of this embodiment is composed of an encoder and a first classifier, and the encoder and the first classifier are both composed of three fully connected layers, and the last fully connected layer is used to reduce the feature dimension to the corresponding cognitive load level as the prediction result.
[0052] In order to achieve different cross-domain selection, in this embodiment, each source domain uses a source domain selector that is trained separately and does not share parameters. The parameters of each source domain model are not shared and are trained separately. The loss function used to train the parameters of the optimization network is recorded as , its calculation function expression is:
[0053] ,
[0054] in, N is the total number of EEG signal data samples for each subject, Represents each EEG signal data sample taken from subject S x , and The classifier is respectively for EEG signal data samples x The predicted results and true labels, For cross entropy loss calculation, its calculation function expression is:
[0055] ,
[0056] in, is the true label, For the prediction results.
[0057] Figure 3 The diagram below is a network structure diagram of the global cross-attention aligner and its back-end part in this embodiment. In this embodiment, the global cross-attention aligner is used to align the conditional distribution while retaining the shallow features to the maximum extent. The global cross-attention aligner consists of a feature extraction network and a global adaptation module based on the cross-attention mechanism. The feature extraction network is used to extract the shallow features of the EEG signal data samples of the subjects in the target domain and the shallow features of each EEG signal data sample in the optimal source domain set respectively. The global adaptation module is used to guide the shallow features of the EEG signal data samples of the subjects in the target domain and the shallow features of each EEG signal data sample in the optimal source domain set to be conditionally aligned. Conditional alignment refers to making the feature distribution of the source domain and the target domain as consistent as possible under the condition of a given category label in transfer learning. Its core is to reduce the distribution difference between categories of cross-domain data and avoid the performance degradation of the classifier due to domain offset.
[0058] The three-cascade symmetric dual-pathway network receives two inputs of equal size as the initial feature extractor, capturing the temporal dynamics and spatial dependencies inherent in EEG signals. Figure 4 As shown, the feature extraction network in step S103 of this embodiment is a three-cascade symmetrical dual-pathway network, which includes two paths corresponding to the source domain and the target domain respectively. The EEG signal data samples of the source domain and the target domain input by the two paths are of the same size. Each channel includes an input layer, a frequency domain convolution layer, a time domain convolution layer, a channel convolution layer, an average pooling layer and a projection layer connected in sequence; the projection layer is composed of a 1×1 convolution and vector transformation module, which is used to project the extracted features into a single channel and an embedding sequence of the same dimension suitable for processing based on the attention mechanism, as the shallow features finally obtained by the feature extraction network, and as the input of the subsequent global adaptation module. See. Figure 4The three-cascaded symmetric dual-pathway network acts as the initial feature extractor and receives two inputs of the same size, capturing the temporal dynamics and spatial dependencies inherent in EEG signals. The three-cascaded symmetric dual-pathway network adopts a symmetric dual-path convolution design, alternately modeling the relationship between time and space and space and time, thereby achieving rich feature encoding across domains. This cascade structure enhances the model's ability to retain domain-specific nuances while improving generalizable representations. After a series of convolution, normalization, and pooling operations, the extracted features are projected into a single-channel and dimensional embedding sequence suitable for attention-based processing.
[0059] The global adaptation module is used to achieve a balanced implementation of shallow feature protection and domain conditional distribution alignment. The cross-attention mechanism allows a small number of labeled target samples to guide the source domain representation through dynamic attention weights, achieving effective domain adaptation and feature protection. In step S103 of this embodiment, the global adaptation module is used to guide the shallow features of the EEG signal data samples of the subjects in the target domain and the shallow features of each EEG signal data sample in the optimal source domain set. The two conditions are aligned, including:
[0060] S201, respectively, splitting the shallow features of the EEG signal data samples of the subjects in the target domain and the shallow features of the EEG signal data samples in the optimal source domain set into multiple slices of the same length, and using a linear layer to generate a key matrix K, a query matrix Q and a value matrix V, wherein the key matrix K and the query matrix Q come from the shallow features of the EEG signal data samples in the optimal source domain set, and the value matrix V comes from the shallow features of the EEG signal data samples of the subjects in the target domain;
[0061] S202, perform attention query through multiple attention heads according to the following formula:
[0062] ,
[0063] ,
[0064] in, For the Attention query results of attention heads, For attention query, is the EEG signal data sample in the source domain, is the EEG signal data sample in the target domain, 、 and Respectively The weight matrices of the query, key, and value of each attention head (used by the linear layer to generate the key matrix K, query matrix Q, and value matrix V), is the dimension of the key matrix K;
[0065] S203, the attention query results of each attention head are spliced together to obtain the shallow features after conditional alignment using the following formula:
[0066] ,
[0067] in, In order to splice the attention query results of each attention head to obtain the shallow features after conditional alignment, ~ These are the attention query results for the 1st to hth attention heads, respectively. As an optional implementation, a linear layer can be added at the end to improve the fitting ability.
[0068] In order to ensure the balance of feature representation, a weighted average strategy is adopted in step S103 of this embodiment to enhance a small amount of labeled target domain data to the same sample dimension as the source domain. Specifically, before the EEG signal data samples of each subject in the target domain and their corresponding optimal source domain set are input into the global cross-attention aligner composed of a feature extraction network and a global adaptation module based on the cross-attention mechanism, this embodiment also includes enhancing the EEG signal data samples of each subject in the target domain: generating weight values for the EEG signal data samples of each subject in the target domain and normalizing them, randomly selecting two EEG signal data samples, and using the normalized weight values to perform a weighted combination to generate a new EEG signal data sample, and the label of the EEG signal data sample adopts the label of the original EEG signal data sample with a larger normalized weight value. As Figure 2 As shown, the source domain consists of all the k source domains that have been selected. For each sample in a small number of labeled target sets, a weight value is randomly generated for each sample. Two samples are randomly selected, weighted together using normalized random weights, and their labels are determined based on the weights. This augmentation method effectively enhances the representativeness of the target subset and ensures fair comparison with the source samples for subsequent feature alignment. This augmented target domain data is then fed into the global cross-attention aligner simultaneously with the source domain data.
[0069] This embodiment also includes aligning the marginal distribution of source domain and target domain features by alternately training the global attention domain aligner composed of the feature extractor and multi-head attention in S103 and the domain discriminator in S104 based on the core idea of generative adversarial networks. The aligner is trained to maximize the error of the discriminator, and the discriminator is trained to minimize the classification error between the source domain and target domain features, and they are updated alternately until a Nash equilibrium is reached. The domain discriminator in step S104 of this embodiment is used for adversarial training to align the marginal distribution of the source domain and the target domain. The domain discriminator in S104 contains two fully connected layers, and the second fully connected layer is used to divide the features into the source domain and the target domain.
[0070] When the domain edge distribution alignment is guided by adversarial alternating training of the discriminator and the global cross-attention aligner, the domain edge distribution alignment refers to aligning the overall feature distribution of the source domain and the target domain, ignoring the category information. Its purpose is to eliminate the global differences between the domains (such as device differences and inter-subject variations). Through the adversarial game between the discriminator and the feature generator (global adaptation module), the feature extractor is forced to generate domain-invariant features. In order to ensure the stability of the adversarial learning process, in step S104 of this embodiment, when the domain edge distribution alignment is guided by adversarial alternating training of the discriminator and the global cross-attention aligner, the gradient reversal layer GRL is used to force the feature distribution to converge, and the functional expression of the loss function used is:
[0071] ,
[0072] ,
[0073] in, The loss function used for adversarial alternating training of the discriminator and the global cross-attention aligner, Represents EEG signal data samples From the source domain , Represents EEG signal data samples From the target domain , Represents EEG signal data samples respectively From the random interpolation domain , is the discriminator, is the cross attention mechanism, For feature extraction network right The shallow features extracted are For feature extraction network right The shallow features extracted are is a hyperparameter that controls the penalty strength. is the gradient reversal layer GRL The calculated gradient penalty is is the gradient operator, random interpolation domain Sample The construction method is:
[0074]
[0075] in, are random weights, and .
[0076] In step S105 of this embodiment, after freezing the aligner and the domain discriminator, a classifier (second classifier) is trained separately to further extract features in the aligned space and classify the EEG signals. The second classifier in step S105 includes three fully connected layers, the first two layers are used to extract the domain-invariant features of the aligned signal and reduce the dimension, and the second layer is used to reduce the dimension to the number of categories. It should be noted that this embodiment only involves the application of fully connected layers and convolutional layers, and does not involve related improvements, so its specific implementation details will not be described in detail here. When the network parameters of the discriminator and the global cross-attention aligner are frozen in step S105 of this embodiment to train the second classifier, the functional expression of the loss function used is:
[0077] ,
[0078] ,
[0079] ,
[0080] in, The loss function used when training the second classifier to freeze the network parameters of the discriminator and the global criss-cross attention aligner, is the classification loss, To counter the loss (whose purpose is to ensure domain adaptability and keep confusing the discriminator), and are the number of EEG signal data samples in the source domain and target domain respectively, is the number of EEG signal categories, is the label of the ith EEG signal data sample belonging to the EEG signal category c, is the prediction value of the second classifier for the i-th EEG signal data sample belonging to the EEG signal category c, Represents EEG signal data samples From the source domain , is the discriminator, is the cross attention mechanism, For feature extraction network right The shallow features extracted.
[0081] In order to verify the EEG signal domain adaptation method based on cross-attention in this embodiment, this embodiment uses the publicly available EEG signal data of the N-back task and MATB-II task from the COG-BCI dataset and the EEG signal data of the mental arithmetic task from the Open Access Dataset for EEG+NIRS Single-Trial Classification to test its classification performance and generalization ability on a cognitive load assessment task across subjects.
[0082] The COG-BCI dataset is a publicly available multi-task EEG dataset designed to study EEG signal characteristics under varying cognitive loads. In this dataset, the N-Back task was used to induce low, medium, and high levels of cognitive load using different difficulty levels (0-Back, 1-Back, and 2-Back). Each task consisted of three blocks, each containing 48 trials. A digit (1 to 9) was presented for 500ms, followed by a blank screen for 1500ms. Participants were required to press the spacebar when the current digit matched the digit in the nth position. Each block lasted approximately two minutes, and participants were required to complete three blocks of each difficulty level (a total of nine blocks). The number of hits per trial was fixed at 16 (16 hit trials per block). The EEG signals and task performance of 29 healthy participants were recorded throughout the entire task. The MATB-II task is a multi-task operating environment developed by NASA, designed to simulate realistic cognitive load scenarios. The COG-BCI dataset uses four MATB-II subtasks: system monitoring (SYSMON), tracking (TRACK), communication (COMM), and resource management (RESMAN). Each MATB-II task lasts approximately 5 minutes, and participants complete three separate runs of the task, corresponding to low, medium, and high difficulty. In the low-difficulty condition, participants only completed the system monitoring and tracking tasks; in the medium-difficulty condition, a resource management task was added; and in the high-difficulty condition, a communication task was added, and the tracking task was increased in difficulty. EEG signals and task performance were recorded from 29 healthy participants throughout the entire task. Data for all tasks in the COG-BCI dataset were collected using 64-lead active Ag-AgCl electrodes (ActiCap, Brain Products GmbH), arranged according to the international 10-20 system, with a sampling rate of 500 Hz. Raw data were unfiltered. All tasks were validated at the subjective, behavioral, and physiological levels to ensure their practicality in brain-computer interface research.
[0083] The mental arithmetic dataset contains EEG signals recorded from 29 healthy adults during a mental arithmetic task (MA) and a baseline task (Baseline). It can be used to investigate cognitive load in a binary classification study. The mental arithmetic task began with an initial subtraction equation (e.g., "384 - 8") presented on the screen for 2 seconds. Participants were required to memorize the initial number and repeatedly subtract single digits from the result of the previous subtraction. During the task, a single black fixation cross appeared on the screen, and participants were instructed to mentally perform continuous subtractions. The task lasted 10 seconds. During the baseline task, a single black fixation cross appeared on the screen, and participants were instructed to remain relaxed and refrain from any cognitive activity. Each task cycle was separated by a randomized rest period of 15 to 17 seconds to minimize fatigue. The mental arithmetic and baseline tasks were randomly alternating throughout the experiment, with each task repeated 20 times. EEG data were collected using a 32-lead EEG cap with a sampling rate of 250 Hz.
[0084] Results of the cross-subject cognitive load assessment experiment: In this example, each subject was used as the target domain in turn, and the remaining 28 subjects were used as the source domain. The average accuracy of the 29 subjects was used as the cross-subject cognitive load assessment result. The results are shown in Table 1.
[0085] Table 1 Cognitive load assessment results across subjects (%)
[0086]
[0087] As shown in Table 1, the average recognition accuracy of the method of this embodiment for each subject in the three data sets is above 82%, with the minimum being 82.53% and the maximum being 1%. This fully demonstrates that the method of this embodiment has excellent generalization ability in the cross-subject cognitive load assessment task.
[0088] To further validate the performance of the deep learning model of this embodiment on cross-subject tasks, we compared it with currently advanced existing methods, including DeepConvNet, EEGNeX, ATCNet, MSTNet, CNN+LSTM, and swin Transformer. These existing methods proposed different network architectures and strategies for EEG cognitive load identification. These were applied to the aforementioned MATB and N-back task datasets, as well as the mental arithmetic dataset, to generate results, which were then compared with the cross-subject task results of this embodiment, as shown in Tables 2, 3, and 4.
[0089] Table 2 Comparison of cross-subject task results of the method in this embodiment and other existing methods on the MATB dataset
[0090]
[0091] Table 3 Comparison of cross-subject task results of the method in this embodiment and other existing methods on the N-back dataset
[0092]
[0093] Table 4 Comparison of cross-subject task results between the method in this embodiment and other existing methods on the mental arithmetic dataset
[0094]
[0095] As shown in Tables 2, 3, and 4, the method of this embodiment is superior to other existing methods in terms of accuracy indicators. The comparison results prove the effectiveness of the method of this embodiment in cross-subject tasks.
[0096] In addition, this example also uses ablation experiments to verify the impact of different components on the final performance. To this end, we studied removing the multi-head attention, discriminator, and adversarial loss from the entire model to evaluate the effectiveness of these key components in cross-subject feature extraction. The experimental results on three datasets are shown in Table 5.
[0097] Table 5 Ablation study based on cross-subject cognitive load assessment
[0098]
[0099] Referring to Table 5, the ablation experiments in this embodiment analyze the following: 1) The domain discriminator further aligns the marginal distributions of the source and target domains through adversarial training. The results show that when the discriminator is removed, the average classification accuracy of the algorithm on the MATB, N-back, and MA datasets decreases by 4.43%, 6.51%, and 18.36%, respectively, while the variance of the classification accuracy increases by 3.21%, 6.91%, and 10.74%, respectively, demonstrating that the discriminator module also improves the classification stability. 2) The multi-head attention component is the most critical part of the global cross-attention aligner framework. It preserves low-level features through attention weights and residual connections, while reweighting the target domain using the source domain attention score to align the conditional distribution between domains, thereby balancing shallow feature preservation and domain adaptation. When we remove the multi-head attention component, the average classification accuracy on the MATB, N-back, and MA datasets decreases by 1.93%, 1.75%, and 1.25%, respectively. Meanwhile, the variance of the classification accuracy increases by 0.91%, 0.44%, and 0.41%, respectively, demonstrating improved classification stability. 3) To ensure domain adaptability, during classifier training, the trained domain discriminator is used to evaluate the accuracy of source domain classification, ensuring that it is consistently confused. This example conducts ablation tests to verify whether the adversarial loss in this component can maintain domain adaptability. The results show that compared to the adversarial loss, the average classification accuracy on the three datasets decreases by 0.6%, 0.76%, and 0.91%, respectively. The variance decreases by 0.23% on the MATB dataset and increases by 0.02% and 0.35% on the N-back and MA datasets, respectively. Therefore, the addition of the adversarial loss does not significantly improve classification stability, but it does improve the average classification accuracy to a certain extent, demonstrating its effectiveness in maintaining domain adaptability.
[0100] In summary, the cross-attention-based EEG signal domain adaptation method of this embodiment includes collecting multi-channel signals for the corresponding analysis task; preprocessing the signals, extracting signal features, and using a similarity metric between samples to obtain a filtered set of source domain samples and generate weighted enhanced target domain features; using a feature extraction-multi-head attention network, namely a global cross-attention aligner, to achieve conditional alignment and retain key shallow features; adversarial training with a domain discriminator to align marginal distributions; and independently optimizing classifiers to achieve domain-adaptive feature extraction and analysis across EEG signals of subjects, achieving high-precision evaluation on a cognitive load EEG dataset. Finally, a cross-attention-based EEG signal domain adaptation system is obtained. This embodiment method addresses the problem of large differences in EEG patterns between individuals and the inability to balance domain adaptation and specificity preservation. A new multi-source domain adaptation framework, called the global cross-attention aligner, is proposed. This framework consists of a source domain selector, a cascaded dual-path feature extractor with a cross-attention module, a domain discriminator, and a final classifier. This embodiment utilizes the fact that samples with high similarity between source domain subjects and target domain subjects may have the same feature patterns. A source domain selector is used to adaptively identify the most relevant source domain list for a given target domain, thereby improving the efficiency of transfer learning. The aligner extracts source and target domain features separately through a shallow network and captures the local and global dependencies of EEG signals while retaining shallow discriminant features through a cross-attention mechanism, guiding the alignment of domain conditions. A domain discriminant network is built to align the marginal distribution through alternating training with the domain aligner network through adversarial learning. The classifier is trained on the aligned feature space to achieve robust cross-subject classification. The obtained EEG signal domain adaptation system based on cross-attention has achieved excellent performance in experiments on cross-subject EEG cognitive load assessment, with advantages such as high assessment accuracy and strong generalization performance.
[0101] In addition, this embodiment also provides an EEG signal domain adaptation system based on cross-attention, including a microprocessor and a memory connected to each other, and the microprocessor is programmed or configured to execute the EEG signal domain adaptation method based on cross-attention.
[0102] In addition, this embodiment also provides a computer-readable storage medium, which stores a computer program or instructions, and the computer program or instructions are programmed or configured to execute the cross-attention-based EEG signal domain adaptation method through a processor.
[0103] In addition, this embodiment also provides a computer program product, including a computer program or instructions, which are programmed or configured to execute the cross-attention-based EEG signal domain adaptation method through a processor.
[0104] Those skilled in the art should understand that the technical solution provided by the present invention may be in the form of a method, a system, or a computer program product. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes in the flowchart and / or block diagram, may be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the functions described in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including the instruction device, which implements the function specified in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0105] The above description is merely a preferred embodiment of the present invention. The scope of protection of the present invention is not limited to the above embodiment. All technical solutions based on the concept of the present invention are within the scope of protection of the present invention. It should be noted that for those skilled in the art, various improvements and modifications that do not depart from the principles of the present invention should also be considered within the scope of protection of the present invention.
Claims
1. A method for domain adaptation of EEG signals based on cross-attention, characterized in that: The steps include: S101, obtaining EEG signal data samples of subjects in the target domain and multiple source domains respectively; S102, using a source domain selector including a first classifier to select, for each EEG signal data sample of a subject in the target domain, k EEG signal data samples of the subject that are most similar to the EEG signal data sample of the subject in multiple source domains to form an optimal source domain set; S103, inputting each EEG signal data sample of the subject in the target domain and its corresponding optimal source domain set into a global cross-attention aligner composed of a feature extraction network and a global adaptation module based on a cross-attention mechanism, using the feature extraction network to extract shallow features of the EEG signal data sample of the subject in the target domain and shallow features of each EEG signal data sample in the optimal source domain set, and using the global adaptation module to guide the conditional alignment of the shallow features of the EEG signal data sample of the subject in the target domain and the shallow features of each EEG signal data sample in the optimal source domain set; S104, using the shallow features after conditional alignment as the input of the second classifier and discriminator, and guiding the alignment of the domain edge distribution by alternating adversarial training of the discriminator and the global cross attention aligner; S105, freezing the network parameters of the discriminator and the global cross attention aligner to train a second classifier for performing EEG signal classification according to the input EEG signal data; The feature extraction network in step S103 is a three-cascade symmetrical dual-pathway network, which includes two paths corresponding to the source domain and the target domain respectively. The EEG signal data samples of the source domain and the target domain input by the two paths are the same size. Each channel includes an input layer, a frequency domain convolution layer, a time domain convolution layer, a channel convolution layer, an average pooling layer and a projection layer connected in sequence. The projection layer is used to project the extracted features into a single channel and an embedding sequence of the same dimension suitable for processing based on the attention mechanism as the shallow features finally obtained by the feature extraction network.
2. The method for domain adaptation of EEG signals based on cross-attention according to claim 1, characterized in that: The source domain selector in step S102 is composed of an encoder and a first classifier, each of which is composed of three fully connected layers, and each source domain uses a source domain selector that is trained separately and whose parameters are not shared.
3. The method for domain adaptation of EEG signals based on cross-attention according to claim 1, characterized in that: In step S103, the shallow features of the EEG signal data samples of the subjects in the target domain and the shallow features of each EEG signal data sample in the optimal source domain set are guided by the global adaptation module to conditionally align the two, including: S201, respectively, splitting the shallow features of the EEG signal data samples of the subjects in the target domain and the shallow features of the EEG signal data samples in the optimal source domain set into multiple slices of the same length, and using a linear layer to generate a key matrix K, a query matrix Q and a value matrix V, wherein the key matrix K and the query matrix Q come from the shallow features of the EEG signal data samples in the optimal source domain set, and the value matrix V comes from the shallow features of the EEG signal data samples of the subjects in the target domain; S202, perform attention query through multiple attention heads according to the following formula: , , in, For the Attention query results of attention heads, For attention query, is the EEG signal data sample in the source domain, is the EEG signal data sample in the target domain, 、 and Respectively The weight matrices of queries, keys, and values for each attention head, is the dimension of the key matrix K; S203, the attention query results of each attention head are spliced together to obtain the shallow features after conditional alignment using the following formula: , in, In order to splice the attention query results of each attention head to obtain the shallow features after conditional alignment, ~ They are the attention query results of the 1st to hth attention heads respectively.
4. The method for domain adaptation of EEG signals based on cross-attention according to claim 1, characterized in that: In step S103, before the EEG signal data samples of the subjects in each target domain and their corresponding optimal source domain sets are input into the global cross-attention aligner composed of a feature extraction network and a global adaptation module based on the cross-attention mechanism, the EEG signal data samples of the subjects in each target domain are enhanced: weight values are generated for the EEG signal data samples of the subjects in each target domain and normalized, two EEG signal data samples are randomly selected, and a new EEG signal data sample is generated by weighted combination using the normalized weight values, and the label of the EEG signal data sample adopts the label of the original EEG signal data sample with a larger normalized weight value.
5. The method for domain adaptation of EEG signals based on cross-attention according to claim 1, characterized in that: In step S104, when the domain edge distribution is aligned by adversarial alternating training of the discriminator and the global cross attention aligner, the gradient reversal layer GRL is used to force the feature distribution to converge, and the functional expression of the loss function used is: , , in, The loss function used for adversarial alternating training of the discriminator and the global cross-attention aligner, Represents EEG signal data samples From the source domain , Represents EEG signal data samples From the target domain , Represents EEG signal data samples respectively From the random interpolation domain , is the discriminator, is the cross attention mechanism, For feature extraction network right The shallow features extracted are For feature extraction network right The shallow features extracted are is a hyperparameter that controls the penalty strength. is the gradient reversal layer GRL The calculated gradient penalty is is the gradient operator, random interpolation domain Sample The construction method is: in, is a random weight, and .
6. The method for domain adaptation of EEG signals based on cross-attention according to claim 1, characterized in that: When freezing the network parameters of the discriminator and the global cross attention aligner in step S105 to train the second classifier, the functional expression of the loss function used is: , , , in, The loss function used when training the second classifier to freeze the network parameters of the discriminator and the global criss-cross attention aligner, is the classification loss, To combat losses, and are the number of EEG signal data samples in the source domain and target domain respectively, is the number of EEG signal categories, is the label of the ith EEG signal data sample belonging to the EEG signal category c, is the prediction value of the second classifier for the i-th EEG signal data sample belonging to the EEG signal category c, Represents EEG signal data samples From the source domain , is the discriminator, is the cross attention mechanism, For feature extraction network right The shallow features extracted.
7. A cross-attention-based EEG signal domain adaptation system, comprising a microprocessor and a memory connected to each other, characterized in that: The microprocessor is programmed or configured to execute the cross-attention-based EEG signal domain adaptation method according to any one of claims 1 to 6.
8. A computer-readable storage medium having a computer program or instruction stored therein, characterized in that: The computer program or instruction is programmed or configured to execute the cross-attention-based EEG signal domain adaptation method according to any one of claims 1 to 6 through a processor.
9. A computer program product comprising a computer program or instructions, characterized in that The computer program or instruction is programmed or configured to execute the cross-attention-based EEG signal domain adaptation method according to any one of claims 1 to 6 through a processor.
Citation Information
Patent Citations
Electroencephalogram signal classification model training method, intention recognition method, equipment and medium
CN115169384A
Domain self-adaptive intelligent emotion recognition method and device based on electroencephalogram signals
CN115444419A