## 2 Materials and Methods
### Training Generative Adversarial Networks  
Generative adversarial networks (GANs) are a novel type of unsupervised learning model that has shown better performance compared to traditional neural network models, making them one of the hottest artificial intelligence technologies in recent years. GANs were first proposed by [PERSON] et al., in October 2014 [36] and have since been widely applied in the field of image processing. GANs consist of two components: the generator and the discriminator. The generator takes random noise as input to generate images, while the discriminator is responsible for judging whether the input image is real or fake by outputting the probability of the image being real. A smaller probability indicates a higher likelihood of the generated image being fake. The goal of the generator is to generate more realistic images to deceive the discriminator and increase the probability of being classified as real. On the other hand, the discriminator aims to distinguish between real and fake images and lower the probability  
Figure 2: The proposed framework of the WGAN-GP-Bi-LSTM algorithm. of being classified as real. Through this dynamic game process, a Nash equilibrium is reached, and training is performed using deep neural networks [37]. The objective function of GANs is defined as:  
\[\min_{G}\max_{D}\!V(D,G)=E_{x\sim p_{data}(x)}[\log D(x)]+E_{z\sim p_{z}(z)}[ \log(1-D(G(z)))], \tag{2}\]  
In (2), data represents real data, \(p_{data}\) represents the distribution of the real data, \(z\) represents random noise (input data), \(p_{z}\) represents the distribution of the original noise, \(G()\) represents the generator mapping function, and \(D()\) represents the discriminator mapping function. The generator and discriminator models compete against each other to reach a global optimum. Specifically, given \(G\), the goal is to maximize the evaluation of the distance between \(p_{G}\) and \(p_{data}\) using \(V(D,G)\). \(p_{G}\) represents the data distribution obtained after generating data using the generator. As shown in Figure 3, the yellow solid line represents the discriminative distribution, while the black dashed line and the blue solid line represent the generated real and fake samples, respectively. The horizontal line z is the sampled region. The upward arrow represents the mapping relationship of \(x=G(z)\), and \(G\) contracts in the high-density area of \(p_{G}\) while expanding in the low-density area. When \(G\) and \(D\) reach a point where neither can improve, the discriminator is unable to distinguish between the two distribution classes. WGAN-GP Feature Extraction Model  
The generator and discriminator of the traditional GAN model, guided by the loss function, continuously play the game of max-min and update by learning against each other until the output is 0.5, at which point the network reaches a stable state and ends the training. The generator's loss function is denoted as \(G_{loss}\), while the discriminator's loss function is denoted as \(D_{loss}\). The definitions are as follows:  
\[D_{loss}=\frac{1}{m}{\sum_{i=1}^{m}{[\log D(x^{(i)})}+\log(1-D(G(z^{(i)})))]}, \tag{3}\]  
\[G_{loss}=\frac{1}{m}{\sum_{i=1}^{m}{\log(1-D(G(z^{(i)})))}}, \tag{4}\]  
In Equations (3) and (4), \(m\) is the batch size of 64, \(x\) is the original STFT of the EEG signal, and \(z\) is sampled from the distribution \(U(-1,1)\). When the network is stable, the data generated by the generator is close to the real time-frequency distribution, and the discriminator has feature extraction ability; that is, the network layers of the discriminator form a feature extractor [28]. Therefore, network training is crucial for improving feature extraction abilities. However, traditional GANs suffer from problems of gradient vanishing and unstable training [30; 38]. As shown in Figure 4, the generator minimizes the Jensen-Shannon divergence (\(JS\) divergence) between the generated distribution \(p_{G}\) and the real distribution \(p_{data}\) using a loss function.