# Intelligent Fault Diagnosis of Unbalanced Samples Using Optimized Generative Adversarial Network
## 2 Methods
### Proposed Method
#### 2.2.3 Generative Model  
The generative model as a generator is improved to synthesize high-quality samples from the noise and class label information as input to augment and balance the unbalanced dataset. The structure of the improved generator is illustrated in Figure 5. Because the ability of convolution operation in feature extraction is excellent, the proposed generator mainly uses convolution transpose and convolution layers. Unlike the generator of the traditional CGAN, the input of each convolution block is closely linked with the label data as a fault condition to improve the guidance of the label during the learning process. Each convolution layer uses the kernel size of 3 and the step size of 1. A cross-iteration batch normalization (CBN) [34] layer is also introduced to the generator by connecting the input layer with the following layers directly instead of through a BN layer. In order to mitigate gradient loss, the ReLU function is replaced with PReLU to speed up the convergence.  
Figure 4: Flowchart of proposed model.  
Finally, the synthesized samples are output through a convolution layer and hyperbolic tangent function.  
The loss function of the generator is improved to address the problem of mode collapse and strengthen the stability. Suppose the generator is G, the discriminator is D, the real data are \(y\), and the generated data are \(\hat{y}\). The GAN loss function \(L_{\text{gan}}\) is given by the following:  
\[L_{\text{gan}}=-\frac{1}{N}\overset{N}{\underset{i=1}{\sum}}\log(D(\hat{y}_{ i})) \tag{8}\]  
where \(N\) is the input number.  
For the multi-classification problem with unbalanced samples, the gradient harmonizing mechanism (GHM) loss function \(L_{\text{ghm}}\)[35] is employed to reduce the non-hard-sample loss and increase the hard-sample loss. \(L_{\text{ghm}}\) is formulated as follows:  
\[L_{\text{ghm}}=\frac{1}{N}\overset{N}{\underset{i=1}{\sum}}\frac{L_{\text{ ce}}(p_{i},p_{i}^{*})}{G_{\text{gd}}(g_{i})} \tag{9}\]  
where \(p_{i}\) is the prediction distribution, \(p_{i}^{*}\) is the true distribution, \(L_{\text{ce}}\) is the cross-entropy (CE) loss function with \(p_{i}\) and \(p_{i}^{*}\), and \(G_{\text{gd}}\) is the gradient density function with gradient mode length \(g_{i}\).  
In a traditional GAN, model collapse may lack data diversity, which can improve the generalization ability of the model. To overcome this, the mode seeking loss function \(L_{\text{ms}}\)[36] is generally employed to improve sample diversity, which is expressed as follows:  
\[L_{\text{ms}}=\underset{G}{\max}\left[\frac{||G(c,z_{1})-G(c,z_{2})||_{1}}{||z _{1}-z_{2}||_{1}}\right] \tag{10}\]  
where \(c\) is the condition for the input mode, and \(G(c,z_{1})\) and \(G(c,z_{2})\) are the map modes with the latent codes \(z_{1}\) and \(z_{2}\), respectively.  
Figure 5: Detailed architecture of generative model.  
Then, the final loss can be given by the following:  
\[L_{\text{G}}=L_{\text{ghm}}+L_{\text{sp}}+\alpha L_{\text{ms}} \tag{11}\]  
where \(\alpha\) is the weight of \(L_{\text{ms}}\).