变分自编码器的推导,VAE的推导,ELBO|证据下界|训练方法

前提描述: VAE在编码器输入x时隐藏变量h的分布为E(h|x),解码器在给定隐藏变量h对应的x的分布为D(x|h),模型的隐藏变量的分布满足Q(h),模型后验概率为D(x)= ∫ \int D(x|h)Q(h)dh,从证据下界推导VAE的损失函数

给定输入 x x x时,模型需要最大化对数似然概率,故而损失函数可以写成 L o s s : = − log ⁡ D ( x ) Loss := -\log D(x) Loss:=logD(x),模型最小化损失函数即是要最大化对数似然概率。

log ⁡ D ( x ) = ∫ E ( h ∣ x ) log ⁡ D ( x ) d h = ∫ E ( h ∣ x ) log ⁡ D ( x ) E ( h ∣ x ) D ( h ∣ x ) D ( h ∣ x ) E ( h ∣ x ) d h = ∫ E ( h ∣ x ) log ⁡ E ( h ∣ x ) D ( h ∣ x ) d h + ∫ E ( h ∣ x ) log ⁡ D ( x , h ) E ( h ∣ x ) d h = K L ( E ( h ∣ x ) ∥ D ( h ∣ x ) ) + ∫ E ( h ∣ x ) log ⁡ D ( x ∣ h ) Q ( h ) E ( h ∣ x ) d h = K L ( E ( h ∣ x ) ∥ D ( h ∣ x ) ) + ∫ E ( h ∣ x ) log ⁡ D ( x ∣ h ) d h − K L ( E ( h ∣ x ) ∥ Q ( h ) ) ≥ ∫ E ( h ∣ x ) log ⁡ D ( x ∣ h ) d h − K L ( E ( h ∣ x ) ∥ Q ( h ) ) = E h ∼ E ( h ∣ x ) log ⁡ D ( x ∣ h ) − K L ( E ( h ∣ x ) ∥ Q ( h ) ) \begin{aligned} \log D(x) &= \int E(h|x)\log D(x)dh\\ &=\int E(h|x) \log \frac{D(x) E(h|x)D(h|x)}{D(h|x)E(h|x)}dh\\ &= \int E(h|x) \log \frac{E(h|x)}{D(h|x)}dh + \int E(h|x)\log\frac{D(x,h)}{E(h|x)}dh\\ & = KL(E(h|x)\|D(h|x)) + \int E(h|x)\log \frac{D(x|h)Q(h)}{E(h|x)}dh\\ & = KL(E(h|x)\|D(h|x)) + \int E(h|x)\log D(x|h)dh - KL(E(h|x)\|Q(h))\\ & \ge \int E(h|x)\log D(x|h)dh - KL(E(h|x)\|Q(h))\\ & = E_{h\sim E(h|x)}\log D(x|h) - KL(E(h|x)\|Q(h)) \end{aligned} logD(x)=E(hx)logD(x)dh=E(hx)logD(hx)E(hx)D(x)E(hx)D(hx)dh=E(hx)logD(hx)E(hx)dh+E(hx)logE(hx)D(x,h)dh=KL(E(hx)D(hx))+E(hx)logE(hx)D(xh)Q(h)dh=KL(E(hx)D(hx))+E(hx)logD(xh)dhKL(E(hx)Q(h))E(hx)logD(xh)dhKL(E(hx)Q(h))=EhE(hx)logD(xh)KL(E(hx)Q(h))

因此,最大化 log ⁡ D ( x ) \log D(x) logD(x)可以通过最大化其证据下界(ELBO)实现,即最大化
E L B O : = E h ∼ E ( h ∣ x ) log ⁡ D ( x ∣ h ) − K L ( E ( h ∣ x ) ∥ Q ( h ) ) ELBO := \text E_{h\sim E(h|x)}\log D(x|h) - KL(E(h|x)\|Q(h)) ELBO:=EhE(hx)logD(xh)KL(E(hx)Q(h))
最大化ELBO

  1. 需要 E h ∼ E ( h ∣ x ) log ⁡ D ( x ∣ h ) E_{h\sim E(h|x)}\log D(x|h) EhE(hx)logD(xh)尽可能大,即需要从编码器得到的隐变量空间中采样隐变量,对采样得到的隐变量进行解码,使得解码得到的 x ^ \hat x x^分布中,对应真是输入 x x x的概率尽可能大。即最小化重构误差。
  2. 需要 K L ( E ( h ∣ x ) ∥ Q ( h ) ) KL(E(h|x)\|Q(h)) KL(E(hx)Q(h))尽可能小,即需要编码器得到的隐变量概率分布与隐变量的先验分布尽可能接近。

VAE的训练

当编码器和解码器输出的分布都是高斯分布,且要求隐变量先验分布为 N ( 0 , I ) \mathcal{N}(0,I) N(0,I)时,VAE的训练过程如下图左边所示。然而左图中的采样过程会导致训练过程中计算重构误差 ∥ X − f ( z ) ∥ 2 \|X-f(z)\|^2 Xf(z)2得到的梯度无法反向传播到编码器。因此将采样过程修改为下图右边的形式,从直接采样目标变量变成采样目标变量到分布均值的差,这样使得反向传播过程中梯度可以传递到编码器。
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值