Relativistic GAN的部分数学推导

Relativistic GAN的部分数学推导,自己重新打一遍字加深记忆。
在论文中定义non-saturating GAN的损失函数如下:
L D S G A N = − E x r ∼ P [ l o g ( s i g m o i d ( C ( x r ) ) ) ] − E x f ∼ Q [ l o g ( s i g m o i d ( C ( x f ) ) ) ] L_D^{SGAN}=-\mathbb{E}_{x_r\sim\mathbb{P}}[log(sigmoid(C(x_r)))]-\mathbb{E}_{x_f\sim\mathbb{Q}}[log(sigmoid(C(x_f)))] LDSGAN=ExrP[log(sigmoid(C(xr)))]ExfQ[log(sigmoid(C(xf)))]
L G S G A N = − E x f ∼ Q [ l o g ( s i g m o i d ( C ( x f ) ) ) ] L_G^{SGAN}=-\mathbb{E}_{x_f\sim\mathbb{Q}}[log(sigmoid(C(x_f)))] LGSGAN=ExfQ[log(sigmoid(C(xf)))]
则Standard GAN的梯度如下:
∇ w L D S G A N = − ∇ w E x r ∼ P [ l o g D ( x r ) ] − ∇ w E x f ∼ Q θ [ l o g ( 1 − D ( x f ) ) ] = − ∇ w E x r ∼ P [ l o g ( e C ( x r ) e C ( x r ) + 1 ) ] − ∇ w E x f ∼ Q θ [ l o g ( 1 − e C ( x f ) e C ( x f ) + 1 ) ] = − ∇ w E x r ∼ P [ C ( x r ) − l o g ( e C ( x r ) + 1 ) ] − ∇ w E x f ∼ Q θ [ l o g ( 1 ) − l o g ( e C ( x f ) + 1 ) ] = − E x r ∼ P [ ∇ w C ( x r ) ] + E x r ∼ P [ e C ( x r ) e C ( x r ) + 1 ∇ w C ( x r ) ] + E x f ∼ Q θ [ e C ( x f ) e C ( x f ) + 1 ∇ w C ( x f ) ] = − E x r ∼ P [ ∇ w C ( x r ) ] + E x r ∼ P [ D ( x r ) ∇ w C ( x r ) ] + E x f ∼ Q θ [ D ( x f ) ∇ w C ( x f ) ] = − E x r ∼ P [ ( 1 − D ( x r ) ) ∇ w C ( x r ) ] + E x f ∼ Q θ [ D ( x f ) ∇ w C ( x f ) ] \begin{aligned} \nabla_wL_D^{SGAN}&=-\nabla_w\mathbb{E}_{x_r\sim\mathbb{P}}[logD(x_r)]-\nabla_w\mathbb{E}_{x_f\sim\mathbb{Q}_\theta}[log(1-D(x_f))] \\ &=-\nabla_w\mathbb{E}_{x_r\sim\mathbb{P}}[log(\frac{e^{C(x_r)}}{e^{C(x_r)}+1})] -\nabla_w\mathbb{E}_{x_f\sim\mathbb{Q}_\theta}[log(1-\frac{e^{C(x_f)}}{e^{C(x_f)}+1})] \\ &=-\nabla_w\mathbb{E}_{x_r\sim\mathbb{P}}[C(x_r)-log(e^{C(x_r)}+1)]-\nabla_w\mathbb{E}_{x_f\sim\mathbb{Q}_\theta}[log(1)-log( e^{C(x_f)}+1)] \\ &=-\mathbb{E}_{x_r\sim\mathbb{P}}[\nabla_wC(x_r)]+\mathbb{E}_{x_r\sim\mathbb{P}}[\frac{e^{C(x_r)}}{e^{C(x_r)+1}}\nabla_wC(x_r)]+\mathbb{E}_{x_f\sim\mathbb{Q}_\theta}[\frac{e^{C(x_f)}}{e^{C(x_f)+1}}\nabla_wC(x_f)] \\ &=-\mathbb{E}_{x_r\sim\mathbb{P}}[\nabla_wC(x_r)]+\mathbb{E}_{x_r\sim\mathbb{P}}[D(x_r)\nabla_wC(x_r)]+\mathbb{E}_{x_f\sim\mathbb{Q}_\theta}[D(x_f)\nabla_wC(x_f)] \\ &=-\mathbb{E}_{x_r\sim\mathbb{P}}[(1-D(x_r))\nabla_wC(x_r)]+\mathbb{E}_{x_f\sim\mathbb{Q}_\theta}[D(x_f)\nabla_wC(x_f)] \end{aligned} wLDSGAN=wExrP[logD(xr)]wExfQθ[log(1D(xf))]=wExrP[log(eC(xr)+1eC(xr))]wExfQθ[log(1eC(xf)+1eC(xf))]=wExrP[C(xr)log(eC(xr)+1)]wExfQθ[log(1)log(eC(xf)+1)]=ExrP[wC(xr)]+ExrP[eC(xr)+1eC(xr)wC(xr)]+ExfQθ[eC(xf)+1eC(xf)wC(xf)]=ExrP[wC(xr)]+ExrP[D(xr)wC(xr)]+ExfQθ[D(xf)wC(xf)]=ExrP[(1D(xr))wC(xr)]+ExfQθ[D(xf)wC(xf)]

∇ θ L G S G A N = − ∇ θ E z ∼ P z [ l o g D ( G ( z ) ) ] = − ∇ θ E z ∼ P z [ l o g ( e C ( G ( z ) ) e C ( G ( z ) ) + 1 ) ] = − ∇ θ E z ∼ P z [ C ( G ( z ) ) − l o g ( e C ( G ( z ) ) + 1 ) ] = − E z ∼ P z [ ∇ x C ( G ( z ) ) J θ G ( z ) − ( e C ( G ( z ) ) e C ( G ( z ) ) + 1 ) ∇ x C ( G ( z ) ) J θ G ( z ) ] = − E z ∼ P z [ ( 1 − D ( G ( z ) ) ) ∇ x C ( G ( z ) ) J θ G ( z ) ] \begin{aligned} \nabla_\theta L_G^{SGAN}&=-\nabla_\theta\mathbb{E}_{z\sim\mathbb{P}_z}[logD(G(z))] \\ &=-\nabla_\theta\mathbb{E}_{z\sim\mathbb{P}_z}[log(\frac{e^{C(G(z))}}{e^{C(G(z))}+1})]\\ &=-\nabla_\theta\mathbb{E}_{z\sim\mathbb{P}_z}[C(G(z))-log(e^{C(G(z))}+1)]\\ &=-\mathbb{E}_{z\sim\mathbb{P}_z}[\nabla_x C(G(z))J_\theta G(z)-(\frac{e^{C(G(z))}}{e^{C(G(z))}+1})\nabla_x C(G(z))J_\theta G(z)] \\ &=-\mathbb{E}_{z\sim\mathbb{P}_z}[(1-D(G(z)))\nabla_xC(G(z))J_\theta G(z)] \end{aligned} θLGSGAN=θEzPz[logD(G(z))]=θEzPz[log(eC(G(z))+1eC(G(z)))]=θEzPz[C(G(z))log(eC(G(z))+1)]=EzPz[xC(G(z))JθG(z)(eC(G(z))+1eC(G(z)))xC(G(z))JθG(z)]=EzPz[(1D(G(z)))xC(G(z))JθG(z)]
IPM_based GAN的数学推导相对容易:
∇ w L D I P M = − E x r ∼ P [ ∇ w C ( x r ) ] + E x f ∼ Q θ [ ∇ w C ( x f ) ] \nabla_wL_D^{IPM}=-\mathbb{E}_{x_r\sim\mathbb{P}}[\nabla_wC(x_r)]+\mathbb{E}_{x_f\sim\mathbb{Q}_\theta}[\nabla_wC(x_f)] wLDIPM=ExrP[wC(xr)]+ExfQθ[wC(xf)]
∇ θ L G I P M = − ∇ θ E z ∼ P z [ C ( G ( z ) ) ] = − E z ∼ P z [ ∇ x C ( G ( z ) ) J θ G ( z ) ] \nabla_{\theta}L_G^{IPM}=-\nabla_\theta\mathbb{E}_{z\sim\mathbb{P}_z}[C(G(z))]=-\mathbb{E}_{z\sim\mathbb{P}_z}[\nabla_xC(G(z))J_\theta G(z)] θLGIPM=θEzPz[C(G(z))]=EzPz[xC(G(z))JθG(z)]

你可能感兴趣的:(GAN论文相关)