AAE

Adversarial Autoencoders

本文将AE转化为一个生产模型,其目标函数有两部分,一个是常见的重建部分,另一个部分是将隐变量的aggregated posterior distribution向任意预设的先验靠近的对抗部分。具体模型如下所示。Adversarial Autoencoders是一个结合对抗训练和自动编码机的模型,其上半部分为一个标准的自动编码机,下半部分为GAN的判别器。判别器的作用就是判断隐变量 z \mathbf z z是否来自自动编码机还是一个人为定义的先验分布 p ( z ) p(\mathbf z) p(z)。也就是我们的目的是让隐变量 z \mathbf z z既能保持重建能力,又能和人为设定的先验 p ( z ) p(\mathbf z) p(z)一致。 q ( z ) = ∫ x q ( z ∣ x ) p d ( x ) d x → p ( z ) q(\mathbf{z})=\int_{\mathbf{x}} q(\mathbf{z} | \mathbf{x}) p_{d}(\mathbf{x}) d \mathbf{x}\rightarrow p(\mathbf z) q(z)=xq(zx)pd(x)dxp(z)
在这里插入图片描述
它们的训练方式跟GAN一样,采用两步的训练方式。交替优化重构误差和判别器的正则项。
In the reconstruction phase, the autoencoder updates the encoder andthe decoder to minimize the reconstruction error of the inputs. In the regularization phase, the adversarial network first updates its discriminative network to tell apart the true samples (generated using the prior) from the generated samples (the hidden codes computed by the autoencoder). The adversarial network then updates its generator (which is also the encoderof the autoencoder) to confuse the discriminative network.
对于 q ( z ∣ x ) q(\mathbf z|\mathbf x) q(zx)有以下三种选择:
1.Deterministic: Here we assume that q ( z ∣ x ) q(\mathbf z|\mathbf x) q(zx)is a deterministic function of x \mathbf x x. In this case, the encoder is similar to the encoder of a standard autoencoder and the only source of stochasticity in q ( z ) q(\mathbf z) q(z) is the data distribution, p d ( x ) p_d(\mathbf x) pd(x).
2.Gaussian posterior: Here we assume that q ( z ∣ x ) q(\mathbf z|\mathbf x) q(zx) is a Gaussian distribution whose mean and variance is predicted by the encoder network: z i ∼ N ( μ i ( x ) , σ i ( x ) ) z_{i} \sim \mathcal{N}\left(\mu_{i}(\mathbf{x}), \sigma_{i}(\mathbf{x})\right) ziN(μi(x),σi(x)). In this case, the stochasticity in q ( z ) q(\mathbf z) q(z) comes from both the data-distribution and the randomness of the Gaussian distribution at the output of the encoder. We can use the same re-parametrization trick for back-propagation through the encodernetwork.
3.Universal approximator posterior: Adversarial autoencoders can be used to train the q ( z ∣ x ) q(\mathbf z|\mathbf x) q(zx) as the universal approximator of the posterior. Suppose the encoder network of the adversarial autoencoder is the function f ( x , η ) f(\mathbf{x}, \eta) f(x,η) that takes the input x \mathbf x x and a random noise η \eta η with a fixed distribution (e.g., Gaussian). We can sample from arbitrary posterior distribution q ( z ∣ x ) q(\mathbf z|\mathbf x) q(zx), by evaluating f ( x , η ) f(\mathbf{x}, \eta) f(x,η) at different samples of η \eta η. In other words, we can assume q ( z ∣ x , η ) = δ ( z − f ( x , η ) ) q(\mathbf{z} | \mathbf{x}, \eta)=\delta(\mathbf{z}-f(\mathbf{x}, \eta)) q(zx,η)=δ(zf(x,η)) and the posterior q ( z ∣ x ) q(\mathbf z|\mathbf x) q(zx) and the aggregated posterior q ( z ) q(\mathbf z) q(z) are defined as follows: q ( z ∣ x ) = ∫ η q ( z ∣ x , η ) p η ( η ) d η ⇒ q ( z ) = ∫ x ∫ η q ( z ∣ x , η ) p d ( x ) p η ( η ) d η d x q(\mathbf{z} | \mathbf{x})=\int_{\eta} q(\mathbf{z} | \mathbf{x}, \eta) p_{\eta}(\eta) d \eta \quad \Rightarrow \quad q(\mathbf{z})=\int_{\mathbf{x}} \int_{\eta} q(\mathbf{z} | \mathbf{x}, \eta) p_{d}(\mathbf{x}) p_{\eta}(\eta) d \eta d \mathbf{x} q(zx)=ηq(zx,η)pη(η)dηq(z)=xηq(zx,η)pd(x)pη(η)dηdxIn this case, the stochasticity in q ( z ) q(\mathbf z) q(z) comes from both the data-distribution and the random noise η \eta η at the input of the encoder. Note that in this case the posterior q ( z ∣ x ) q(\mathbf z|\mathbf x) q(zx) is no longer constrained to be Gaussian and the encoder can learn any arbitrary posterior distribution for a given input x \mathbf x x. Since there is an efficient method of sampling from the aggregated posterior q ( z ) q(\mathbf z) q(z), the adversarial training procedure can match q ( z ) q(\mathbf z) q(z) to p ( z ) p(\mathbf z) p(z) by direct back-propagation through the encoder network f ( x , η ) f(\mathbf{x}, \eta) f(x,η).
不同类型的后验,会导致不同的效果,比如对于第一种类型的方式,当 q ( z ) q(\mathbf z) q(z)靠近 p ( z ) p(\mathbf z) p(z)时,主要依靠的是数据的随机性,然而数据的随机性是有限的,因此最终得到的分布也是不连续的。而后两种方式引入了更多的随机性,进而使得所得的分布更加连续。虽然如此,作者通过大量的调参实验,发现这三种方式的测试likelihood都是可以达到差不多水平。因此文章只研究了第一种方式!
下面研究下VAE与AAE的区别,VAE的目标函数为 E x ∼ p d ( x ) [ − log ⁡ p ( x ) ] &lt; E x [ E q ( z ∣ x ) [ − log ⁡ ( p ( x ∣ z ) ] ] + E x [ KL ⁡ ( q ( z ∣ x ) ∥ p ( z ) ) ] = E x [ E q ( z ∣ x ) [ − log ⁡ p ( x ∣ z ) ] ] − E x [ H ( q ( z ∣ x ) ) ] + E q ( z ) [ − log ⁡ p ( z ) ] = E x [ E q ( z ∣ x ) [ − log ⁡ p ( x ∣ z ) ] − E x [ ∑ i log ⁡ σ i ( x ) ) ] + E q ( z ) [ − log ⁡ p ( z ) ] + c o n s t . = R e c o n s t r u c t i o n − E n t r o p y + C r o s s E n t r o p y ( q ( z ) , p ( z ) ) \begin{aligned} E_{\mathbf{x} \sim p_{d}(\mathbf{x})}[-\log p(\mathbf{x})] &amp;&lt;E_{\mathbf{x}}\left[\mathrm{E}_{q(\mathbf{z} | \mathbf{x})}[-\log (p(\mathbf{x} | \mathbf{z})]]+E_{\mathbf{x}}[\operatorname{KL}(q(\mathbf{z} | \mathbf{x}) \| p(\mathbf{z}))]\right.\\ &amp;=E_{\mathbf{x}}\left[\mathbf{E}_{q(\mathbf{z} | \mathbf{x})}[-\log p(\mathbf{x} | \mathbf{z})]\right]-E_{\mathbf{x}}[H(q(\mathbf{z} | \mathbf{x}))]+E_{q(\mathbf{z})}[-\log p(\mathbf{z})] \\ &amp;=E_{\mathbf{x}}\left[\mathbf{E}_{q(\mathbf{z} | \mathbf{x})}[-\log p(\mathbf{x} | \mathbf{z})]-E_{\mathbf{x}}\left[\sum_{i} \log \sigma_{i}(\mathbf{x})\right)\right]+E_{q(\mathbf{z})}[-\log p(\mathbf{z})]+\mathrm{const.} \\ &amp;=Reconstruction - Entropy + CrossEntropy(q(\mathbf z), p(\mathbf z)) \end{aligned} Expd(x)[logp(x)]<Ex[Eq(zx)[log(p(xz)]]+Ex[KL(q(zx)p(z))]=Ex[Eq(zx)[logp(xz)]]Ex[H(q(zx))]+Eq(z)[logp(z)]=Ex[Eq(zx)[logp(xz)]Ex[ilogσi(x))]+Eq(z)[logp(z)]+const.=ReconstructionEntropy+CrossEntropy(q(z),p(z))VAE将先验p(z)加在后验分布上,通过KL散度进行优化,这就要求p(z)必须有个显式的概率分布。而AAE则不需要,只要能采样出zp(z)即可。从下图可以看出,AAE更能抓住先验,而VAE则不能。
在这里插入图片描述
从上图可以看出,AAE能够很好地抓住预先设定的先验,但是标签信息是混乱的,因此可以考虑引入标签信息,让GMM的每个Gaussian分布都代表一个类别,那么可以提出如下图所示的模型。
在这里插入图片描述
这个one-hot向量为原数据中的标签或者p(z)某个高斯的标签。这样一来就让数据的标签和高斯的标签对应起来了。需要注意的是,如果有10个类别,one-hot为一个11维度的向量。前十个按照以上所述那样取标签,但是第11维标签为无标签数据,即从GMM里面取得,而不是从GMM某个类中取。整个训练过程为:During the positive phase of adversarial training, we provide the label of the mixture component(that the positive sample is drawn from) to the discriminator through the one-hot vector. The positive samples fed for unlabeled examples come from the full mixture of Gaussian, rather than from a particular class. During the negative phase, we provide the label of the training point image to the discriminator through the one-hot vector。在半监督下,实验结果在10K标签训练数据和40K无标签训练数据如下图所示。
在这里插入图片描述
以上为引入标签信息,现在考虑如何让AE能够划分两种特性:类别数和风格。网络结构如下图所示。这其实就是一个监督学习,利用标签信息生成图片。
在这里插入图片描述
这样就能让encoder学习到一个独立于标签的style特征,且这个style特征与标准正态分布很像,固定 z \mathbf z z改变标签 y \mathbf y y得到的mnist效果如下
在这里插入图片描述
接下来考虑的是半监督情况,所谓半监督就是利用没有标签的数据提升分类精度。那么就需要以生成的方式对没有标签的数据生成一个标签,则
p ( y ) = Cat ⁡ ( y ) p ( z ) = N ( z ∣ 0 , I ) p(\mathbf{y})=\operatorname{Cat}(\mathbf{y}) \quad p(\mathbf{z})=\mathcal{N}(\mathbf{z} | 0, \mathbf{I}) p(y)=Cat(y)p(z)=N(z0,I)
在这里插入图片描述
训练过程也是分为:重建过程,对抗过程,监督过程。监督过程主要是针对于 q ( y ∣ x ) q(\mathbf{y} | \mathbf{x}) q(yx)有标签的数据训练。无监督情况与上面模型一样,由于没有标签,所以就没有监督过程。
最后介绍模型的降维能力。其核心是映射到隐变量 y \mathbf y y,然后 y C \mathbf y_C yC得到一个Cluster Head,然后与 z \mathbf z z相加得到最终降维的变量。其中 W C W_C WC为一个可以训练的参数,主要是通过惩罚Cluster Head 之前的欧式距离优化。
在这里插入图片描述
如果我们把 W C = I W_C=I WC=I,那么映射后的就是正好一个混合高斯模型。总结来说AAE能够利用对抗训练,不像VAE那样通过KL算与 p ( z ) p(\mathbf z) p(z)的距离,这样就不需要知道 p ( z ) p(\mathbf z) p(z)的显示表达式,可以作用到很多很有意思的流形上!

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值