# EEG Data Augmentation for Emotion Recognition with a Task-Driven GAN
## 3 The Proposed Method
### EEG Data Augmentation for Emotion Recognition
#### 3.2.2 The Task-Driven CWGAN  
First, we built an EEG data generation network based on GAN, then introduce a classifier suitable for EEG emotion recognition to guide the generator during the generative adversarial training. The generator generates false samples for the discriminator and task network, both of which provide gradients for parameter optimization. The former promotes the generation of realistic EEG data, while the latter promotes the generation of clearer data classification so that the network has task awareness and can generate more effective EEG data for emotion recognition tasks. The framework of the network in the proposed method is shown in Figure 2. The emotion recognition task network is added to the original CWGAN. The generator generates fake samples for the discriminator and task network, both of which provide gradients for parameter optimization. \begin{table}
\begin{tabular}{c c} \hline \hline  & (a) \\ Layer (type) & Output Shape \\ Linear-1 & [64; 324] \\ ReLU-2 & [64; 4; 9; 9] \\ Conv2d-3 & [64; 64; 9; 9] \\ ReLU-4 & [64; 64; 9; 9] \\ Conv2d-5 & [64; 32; 9; 9] \\ ReLU-6 & [64; 32; 9; 9] \\ Conv2d-7 & [64; 16; 9; 9] \\ Conv2d-8 & [64; 4; 9; 9] \\ Layer (type) & Output Shape \\ Conv2d-1 & [64; 32; 9; 9] \\ LeakReLU-2 & [64; 32; 9; 9] \\ MaxPool2d-3 & [64; 32; 4; 4] \\ Conv2d-4 & [64; 64; 4; 4] \\ LeakReLU-5 & [64; 64; 4; 4] \\ MaxPool2d-6 & [64; 64; 2, 2] \\ Linear-7 & [64; 256] \\ LeakReLU-8 & [64; 256] \\ Linear-9 & [64; 1] \\ \multirow{2}{*}{Layer (type)} & \multirow{2}{*}{(c)} \\ \cline{2-2} \cline{4-  
The EEG-based data augmentation network designed for emotion recognition tasks takes into account the quality of the generated data (the similarity between generated data and real data) as well as the clarity of generated data classifications so that the performance of emotion recognition tasks on the current dataset can influence the parameter optimization process of the generator. This ensures the improvement of the performance of recognition tasks after data augmentation, and there will be no waste of computing resources. The network loss function is defined as Formula (4), including the discriminator correlation loss \(\min\limits_{G}\max\limits_{D}L(X_{r},X_{g},Y)\) and classifier correlation loss \(\min\limits_{G}\min\limits_{T}L(X_{r},X_{g},Y)\). The term \(\lambda\mathbb{E}_{\vec{x}\sim\vec{X},y\sim Y}\Big{[}\Big{(}\Big{\|}\
abla_{ \vec{x}|y}D(\vec{x}|y)\Big{\|}_{2}-1\Big{)}^{2}\Big{]}\) in Formula (5) (discriminator correlation loss) is a gradient penalty term [22] used to make the training process more stable and the convergence speed faster. The classifier correlation loss is the cross-entropy loss. The coefficient \(\rho\) in Formula (4) is used to adjust the proportion of the classifier's correlation loss:  
\[L_{G,D,T}=\min\limits_{G}\max\limits_{D}L\big{(}X_{r},X_{g},Y\big{)}+\rho\min \limits_{G}\min\limits_{T}L\big{(}X_{r},X_{g},Y\big{)} \tag{4}\]  
\[ \begin{split}\min\limits_{G}\max\limits_{D}L\big{(}X_{r},X_{g},Y \big{)}&=\mathbb{E}_{x_{r}\sim X_{r},y\sim Y}[D(x_{r}|y)]-\mathbb{ E}_{x_{g}\sim X_{g},y\sim Y}\big{[}D(x_{g}|y)\big{]}\\ &-\lambda\mathbb{E}_{\vec{x}\sim\vec{X},y\sim Y}\bigg{[}\Big{(} \Big{\|}\
abla_{\vec{x}|y}D(\vec{x}|y)\Big{\|}_{2}-1\Big{)}^{2}\bigg{]}\end{split}  \tag{5}\]  
Then the training process is involved. In response to the structure above, the classifier also needs to be trained in each iterative training process of the generator and discriminator, and guide the generator to generate clearer data by providing classification loss-related gradients. The training process is shown in Algorithm 1:  
``` Training discriminator and classifier (update the parameters of the discriminator and classifier): * Calculate the discriminator loss: 1: Place the real sample into the discriminator to obtain the true-or-fake loss of the real sample. 2: Place the fake sample generated by the generator into the discriminator to obtain the true-or-fake loss of the fake sample.