# A Short Note on Physics-Guided GAN to Learn Physical Models without Gradients
## 3 PG-GAN Model
### Formulation of PG-GAN  
Generated data should be considered as true if they are physically reasonable. To judge the physical reasonableness, a physical model is used. Suppose that the physical model is described as \(P(\mathbf{x}\mid\theta)=0\), and the value of \(P(\mathbf{x}\mid\theta)\) is treated as a residual. We treat datapoint \(\mathbf{\hat{x}}\) as true if \(P(\mathbf{\hat{x}}\mid\hat{\theta})\leq\varepsilon\). Hence, the input of our discriminator is given by generated data \(\mathbf{x}^{\prime}\), and the output is whether data are physically reasonable or not. For a given \(\varepsilon\), let a set \(\mathcal{D}_{\varepsilon}\) represent a set of data whose residual is equal to, or less than, \(\varepsilon\). \[\mathcal{R}_{\varepsilon}=\{\mathbf{x}\mid P(\mathbf{x}\mid\theta)\leq\varepsilon\}, \ \mathcal{F}_{\varepsilon}=\{\mathbf{x}\mid P(\mathbf{x}\mid\theta)>\varepsilon\}\]  
In this case, the loss function becomes  
\[V_{\varepsilon}(G,D)=E_{G(z)\in\mathcal{R}_{\varepsilon}}[\log D(x)]+E_{G(z) \in\mathcal{F}_{\varepsilon}}[\log(1-D(G(z)))]. \tag{2}\]  
The optimization problem for the discriminator is \(\max_{D}V_{\varepsilon}(G,D)\). The discriminator tries to mimic the physical model to judge physical reasonableness. If we minimize \(V_{\varepsilon}(G,D)\) with respect to \(G\), the generator is not trained as desired. In the ordinal GAN loss function, the first term of \(V(G,D)\) is not a function of \(G\), and the generator optimization problem becomes  
\[\min_{G}\ E_{z\sim p_{z}}[\log(1-D(G(z)))].\]  
However, in Equation (2), both the first and second terms were functions of \(G\). Therefore, the generator optimization problem uses only the second term of \(V_{\varepsilon}(G,D)\), and is  
\[\min_{G}E_{G(z)\in\mathcal{F}_{\varepsilon}}[\log(1-D(G(z)))],\]  
instead of \(\min_{G}\ V_{\varepsilon}(G,D)\). The architecture of the proposed model is illustrated in Figure 3. The physics-guided GAN model uses a physics model as a referee to judge whether the generated data are physically reasonable or not. The discriminator is a surrogate model of the physical model. Figure 2: Overview of PG-GAN. If we could use the physical model itself as a discriminator, the generator would be trained much more efficiently. However, if we use the physical model in the architecture, back propagation would stop at the physical model, because we are assuming that the physical model's software is a black-box. This is also a feature of the PG-GAN: the training data no longer appear in the model. The real data are not necessary, because their being true/false is judged by the physical model. The PINN can be coupled with the PG-GAN by adding the residual into the loss function of the generator; the resulting architecture is called PG-PI-GAN. The loss function is modified as  
\[\min_{G}E_{G(z)\in\mathcal{F}_{\varepsilon}}[\log(1-D(G(z)))]+ \lambda r.\]  
Training the PG-GAN without pre-training is not efficient, because in the early epochs, the generator cannot generate physically reasonable data and \(\mathcal{R}_{\varepsilon}\) always becomes an empty set. In such a case, both the generator and discriminator are not well-trained, because the discriminator always outputs 0 (fake), whereas the generator has no clue to generate reasonable data. Hence, it is necessary to start from a pre-trained generator that generates non-empty \(\mathcal{R}_{\varepsilon}\). To obtain such a pre-trained generator, an ordinal GAN model is used. Data generated by the pre-trained generator exhibits a large residual of physical equation \(P(\boldsymbol{x}^{\prime}\mid\theta)\). \(\varepsilon\) must be large enough so that both sets \(\mathcal{R}_{\varepsilon}\) and \(\mathcal{F}_{\varepsilon}\) are not empty sets. However, it is not desirable to terminate with large \(\varepsilon\). Hence, \(\varepsilon\) is reduced as training proceeds, until it reaches the target value \(\varepsilon\). In the following numerical example, \(\varepsilon\) was constant for 10,000 epochs and then changed.