# Editable Image Generation with Consistent Unsupervised Disentanglement Based on GAN
## 3 Theoretical Method and Simplified Calculation
### Approximate Computational Procedure and Loss Function  
Considering the Taylor expansion of \(f(x)\), we note that the Hessian matrix appears in the local gradient expansion, and we add the Hessian as a linear operator to the expansion to obtain Equation (12)  
\[\
abla f(x+\Delta x)=\
abla f(x)+H(x)\Delta x+\mathcal{O}\Big{(}\|\ \Delta x\|^{2}\Big{)} \tag{12}\]  
where \(\
abla f(x)\) is the gradient of \(f(x)\), \(H(x)\Delta x\) is the \(f(x)\) incremental value about \(\Delta x\), and the tail term \(\mathcal{O}\big{(}\|\ \Delta x\|^{2}\big{)}\) is the second-order infinitesimal term about \(\Delta x\). To simplify the calculation, we vectorize \(\Delta x\), so that \(\Delta x=\varepsilon v\), substituting into the equation \(H(x)\Delta x\), we have Equation (13).  
\[H(x)\Delta x=H(x)\varepsilon v=\varepsilon H(x)v=\
abla f(x+\varepsilon v)- \
abla f(x)+\mathcal{O}\Big{(}\varepsilon^{2}\Big{)} \tag{13}\]  
In Equation (13), \(\varepsilon\) is the scalar and \(v\) is the vector, and dividing both sides of Equation (13) by \(\varepsilon\), we have \(H(x)v=\frac{1}{\varepsilon}[\
abla f(x+\varepsilon v)-\
abla f(x)]+\mathcal{ O}(\varepsilon)\), and removing the infinitesimal term in Equation (13), the formula is equal to Equation (14).  
\[H(x)v\approx\frac{1}{\varepsilon}[\
abla f(x+\varepsilon v)-\
abla f(x)] \tag{14}\]  
The approximation of the removal of the term(\(\mathcal{O}(\varepsilon)\)) usually brings numerical instability, we need to make \(\mathcal{O}(\varepsilon)\) small enough, and the effect of \(\mathcal{O}(\varepsilon)\) can be ignored in actual calculations, \(\mathcal{O}(\varepsilon)\) is very small, so in the actual calculation, we remove this. The effect of Equation (14) and the calculation procedure is the same as that of the original one.  
In order to apply the present method to GAN training, we only need to modify the loss of G as Equation (15). Referring to the derivation of Equation (6) for \(\mathcal{L}_{H}(G)\) and Equation (9) for \(\mathcal{L}_{I}(G)\), combined with GAN's original \(\mathcal{L}_{G_{v}}=\underset{z\sim p_{z}(z)}{\mathrm{E}}[f(1-D(G(z)))]\), we can obtain Equation (15). Here, the values of \(\lambda_{1}\) and \(\lambda_{2}\) are calculated using game theory. For the specific solution process, refer to Appendix A.1. Likewise, the two parameters of this part are also used in the network architecture; for the network architecture algorithm pseudo-code, refer to Appendix A.2.  
\[\mathcal{L}_{G}=\underset{z\sim p_{z}(z)}{\mathrm{E}}[f(1-D(G(z)))]+\lambda_{ 1}\underset{z\sim p_{z}(z)}{\mathrm{E}}[\mathcal{L}_{H}(G)]+\lambda_{2} \underset{z\sim p_{z}(z)}{\mathrm{E}}[\mathcal{L}_{I}(G)] \tag{15}\]In Equation (15), \(\lambda_{1}\) and \(\lambda_{2}\) are hyperparameters. The inclusion of \(\mathcal{L}_{H}(G)\) and \(\mathcal{L}_{I}(G)\) in GAN training is beneficial to learn the representation and to achieve the generation of controllable images. The specific calculations for the hyperparameters \(\lambda_{1}\) and \(\lambda_{2}\) are shown in Appendix A.1. We found that using these hyperparameters only to adjust the training parameters in the model architecture, without using this disentanglement loss in Equation (15), can mitigate the pattern collapse. The use of the hyperparameters in the model is referenced in Appendix A.2.