# Welding Image Data Augmentation Method Based on LRGAN Model
## 2 LRGAN Model
### The Discriminator Part of the LRGAN Model
#### 2.1.2 Loss Function
The objective functions of the generative network and the discriminator network are as follows:  
\[\min V_{LRGAN}(D)=\frac{1}{2}E_{x-p_{data}(x)}\left[\left(D(x)-b\right)^{2} \right]+\frac{1}{2}E_{z-p_{z}(z)}\left[\left(D(G(z,y))-a\right)^{2}\right] \tag{7}\]  
\[\min V_{LRGAN}(G)=\frac{1}{2}E_{z-p_{z}(z)}\left[\left(D(G(z,y))-c\right)^{2}\right] \tag{8}\]  
Here, E represents the expectation; a and b represent the labels of the generated data and real data, respectively, and c indicates that the generative network tries to make the discriminator believe the input has the label of the generated data; z is a random noise, drawn from the distribution p(z); \(V_{LRGAN}(D)\) represents the least squares loss function for the discriminator; and the \(V_{LRGAN}(G)\) represents the least squares loss function for the generator. The meanings of the other symbols are the same as in the previous formula and are not repeated. To overcome the gradient vanishing problem and make the training  
\[\min V_{LRGAN}(D)=\frac{1}{2}E_{x-p_{\text{data}}(x)}\Big{[}\big{(}D(x)-b)^{2 }\Big{]}+\frac{1}{2}E_{z-p_{z}(z)}\Big{[}\big{(}D(G(z,y))-a\big{)}^{2}\Big{]} \tag{2}\]0 Loss function comparison diagram. process more stable, the \(\frac{1}{2}E_{x-p_{data}(x)}\)\(\left[\left(D(X)-d\right)^{2}\right]\) will be added to Formula (3), as it does not contain any generator parameters, so it does not affect the optimal solution. The following formula is obtained:  
\[\min V_{LRGAN}(D)=\frac{1}{2}E_{x-p_{\text{data}}(x)}\Big{[}\big{(}D(x)-b)^{2 }\Big{]}+\frac{1}{2}E_{z-p_{z}(z)}\Big{[}\big{(}D(G(z,y))-a\big{)}^{2}\Big{]} \tag{2}\]1  
By fixing the generative network as constant, the optimal discriminator network can be derived:  
\[\min V_{LRGAN}(D)=\frac{1}{2}E_{x-p_{\text{data}}(x)}\Big{[}\big{(}D(x)-b)^{2 }\Big{]}+\frac{1}{2}E_{z-p_{z}(z)}\Big{[}\big{(}D(G(z,y))-a\big{)}^{2}\Big{]} \tag{2}\]2  
Then, the generative network formula becomes:  
\[ \begin{array}{ll}2C(G)&=\mathrm{E}_{x\sim p_{data}(x)}\left[\left(D^{*}(x) -c\right)^{2}\right]+E_{x\sim p_{g}(x)}\left[\left(D^{*}(x)-c\right)^{2}\right] \\ &=\mathrm{E}_{x\sim p_{data}(x)}\left[\left(\frac{bp_{data}(x)+ap_{g}(x)}{ p_{data}(x)+p_{g}(x)}-c\right)^{2}\right]+\mathrm{E}_{x\sim p_{g}(x)}\left[ \left(\frac{bp_{data}(x)+ap_{g}(x)}{p_{data}(x)+p_{g}(x)}-c\right)^{2}\right] \\ &=\int_{x}p_{data}(x)\left[\frac{\left(b-c\right)p_{data}(x)+\left(a-c \right)p_{g}(x)}{p_{data}(x)+p_{g}(x)}\right]^{2}dx+\int_{x}p_{g}(x)\left[ \frac{\left(b-c\right)p_{data}(x)+\left(a-c\right)p_{g}(x)}{p_{data}(x)+p_{g} (x)}\right]^{2}dx\\ &=\int_{x}\frac{\left(\left(b-c\right)p_{data}(x)+\left(a-c\right)p_{g}(x) \right)^{2}}{p_{data}(x)+p_{g}(x)}\,dx\\ &=\int_{x}\frac{\left(\left(b-c\right)\left(p_{data}(x)+p_{g}(x)\right)-\left( b-a\right)p_{g}(x)\right)^{2}}{p_{data}(x)+p_{g}(x)}\,dx\\ \end{array}  \tag{11}\]  
Set b - c=1, b - a=2; then:  
\[ \begin{array}{ll}2C(G)&=\int_{x}\frac{\left(2p_{g}(x)-\left(p_{data}(x)+p_ {g}(x)\right)\right)^{2}}{p_{data}(x)+p_{g}(x)}\,dx\\ &=\chi_{Pearson}^{2}\big{(}p_{data}(x)+p_{g}(x)\|2p_{g}(x)\big{)}\end{array}  \tag{12}\]  
Here, \(x_{Pearson}^{2}\) is the Pearson \(x^{2}\) distance, which is zero only when \(P_{\mathrm{data}}(x)=P_{\mathrm{g}}(x)\) are the same. In practice, the distribution of data generated by the generative network cannot exactly match the distribution of the real data. Therefore, it can be said that the least squares loss function, when replacing cross-entropy, significantly addresses the gradient vanishing problem in the training of generative adversarial networks at a theoretical level.