# A Symbol Recognition System for Single-Line Diagrams Developed Using a Deep-Learning Approach
## 3 Proposed Method
### Data Generation by GANs
#### 3.3.2 Network Structure of the LSGAN  
Another GAN variation used for this work is the least-squares GAN (LSGAN), which can be seen in Figure 10. The LSGAN has some benefits over other GANs: (a) the LSGAN improves the initial loss function in the GAN by substituting the least-squares loss function for the original cross-entropy loss function. This technique fixes significant traditional GAN issues; and (b) the LSGAN increases the convergence speed and the training process stability and results in greater image clarity. Similar to conventional GANs, ReLU and Leaky ReLU parameters are used in generators and discriminators. On the other hand, a drawback of the LSGAN is that it results in less sample variety due to excessive penalties for outliers. The cost function is readily saturated, so GANs still struggle with the training process's non-convergence. The \"missing modes problems\" or \"modes collapse\" that GANs experience are extremely severe and result in a dearth of variety and generalization. The GAN technique has recently been improved to stabilize training and raise the caliber of the generated samples. For instance, the sigmoid cross-entropy loss used in training caused the gradients in the traditional method to vanish. The least-squares GAN (LSGAN) method [54] replaces the cross-entropy loss by the least-squares function with binary coding to resolve this. Figure 10: Architecture of the LSGAN. (**a**) The generator of the LSGAN. (**b**) The discriminator of the LSGAN. In order to ensure that the generated and real images converge during training, the discriminator's target values for the real and generated images are represented by labels a and b, respectively. The generator's target value for the generated images is represented by label c. To achieve this convergence, it is important to select appropriate values for a, b, and c. An extra term is introduced into the generator equation to accomplish this, and since this term is independent of G, the optimal point for the equation remains the same. The cost function in the LSGAN is given in Equation (9) as:  
\[\mathrm{min_{D}L_{LSGAN}(D)}=\frac{1}{2}\mathrm{E_{x\sim P_{data}(x)}}\Big{[} \big{(}D(x)\ -\ b\big{)}^{2}\Big{]}+\frac{1}{2}\mathrm{E_{z\sim P_{z}(z)}}\Big{[}\big{(}D( G(z))\ -\ a\big{)}^{2}\Big{]} \tag{9}\]  
The discriminator's cost function, which is defined by F(D) in Equation (10), can also be transformed into Equation (11). \[\mathrm{min_{D}L_{LSGAN}(D)}=\frac{1}{2}\int_{x}\mathrm{P_{data}(x)}\big{(}D(x )\ -\ b\big{)}^{2}\ +\ P_{g}(x)\big{(}D(x)\ -\ a\big{)}^{2}\ dx \tag{10}\]  
\[\mathrm{F(D)}=\frac{1}{2}\mathrm{P_{data}(x)}\big{(}D(x)\ -\ b\big{)}^{2}\ +\ P_{g}(x)\big{(}D(x)-a\big{)}^{2} \tag{11}\]  
When the generator is certain and fixed, it is possible to determine the formula for the optimal discriminator as Equation (11) by minimizing the function in Equation (12). \[\mathrm{D^{*}}_{(x)}=\frac{\mathrm{b}\mathrm{P_{data}}+(x)\mathrm{a}\mathrm{P_ {g}(x)}}{\mathrm{P_{data}(x)+P_{g}(x)}} \tag{12}\]  
Then, by substituting \(\mathrm{D^{*}}\)(x), the best generator in terms of optimization can be achieved. \[ \begin{split}& 2\mathrm{L}(G)\ =\ \mathrm{E_{x\sim P_{data}}}\ \big{[}(\mathrm{D^{*}}_{(x)}\ -\ c\big{)}^{2}\big{]}+\mathrm{E_{z\sim P_{z}}}\ \Big{[}\big{(}\mathrm{D^{*}}(G(z))\ -\ c\big{)}^{2}\Big{]} =\mathrm{E_{x\sim P_{data}}}\\ &\big{[}\big{(}\mathrm{D^{*}}_{(x)}\ -\ c\big{)}^{2}\big{]}+ \mathrm{E_{x\sim P_{g}}}\ \big{(}[\mathrm{D^{*}}_{(x)}\ -\ c\big{)}^{2}\big{]}=\\ &\int_{x}(\mathrm{P_{data}(x)+P_{g}(x)})\Bigg{(}\frac{(b-c) \mathrm{P_{data}(x)(a-c)P_{g}(x)}}{\mathrm{P_{data}(x)}\ +\ P_{g}(x)}\Bigg{)}^{2}\mathrm{dx}\ =\\ &\int_{x}\frac{(b-c)(\mathrm{P_{data}(x)P_{g}(x)(b-c)P_{g}(x)}}{ \mathrm{P_{data}(x)}\ +\ P_{g}(x)})2\mathrm{dx}\end{split}  \tag{13}\]  
In reality, there are several sets of viable parameterization options available for LSGANs. A 0-1 binary coding scheme, for instance, can be used to distinguish between generated samples and actual samples when a = 0, b = 1, and c = 1.