VAE 损失函数

实例 x \mathbf{x} x 由条件分布 x ∣ z \mathbf{x}|\mathbf{z} xz 生成, z \mathbf{z} z 是一个服从任意分布的随机变量

VAE 的优化目标是令 p ( x ) p\left(\mathbf{x}\right) p(x) 的对数似然最大化,因此有
ln ⁡ p ( x ) = ∫ z q ( z ∣ x ) ln ⁡ p ( x ) d z = ∫ z q ( z ∣ x ) ln ⁡ ( p ( x , z ) q ( z ∣ x ) q ( z ∣ x ) p ( z ∣ x ) ) d z = ∫ z q ( z ∣ x ) ln ⁡ ( p ( x , z ) q ( z ∣ x ) ) d z + ∫ z q ( z ∣ x ) ln ⁡ ( q ( z ∣ x ) p ( z ∣ x ) ) d z = L B + K L ( q ( z ∣ x ) ∣ ∣ p ( z ∣ x ) ) \begin{aligned} \ln p\left(\mathbf{x}\right) &=\int_\mathbf{z}q\left(\mathbf{z}|\mathbf{x}\right)\ln p\left(\mathbf{x}\right)d\mathbf{z}\\ &=\int_\mathbf{z}q\left(\mathbf{z}|\mathbf{x}\right)\ln \left(\frac{p\left(\mathbf{x},\mathbf{z}\right)}{q\left(\mathbf{z}|\mathbf{x}\right)}\frac{q\left(\mathbf{z}|\mathbf{x}\right)}{p\left(\mathbf{z}|\mathbf{x}\right)}\right)d\mathbf{z}\\ &=\int_\mathbf{z}q\left(\mathbf{z}|\mathbf{x}\right)\ln\left(\frac{p\left(\mathbf{x},\mathbf{z}\right)}{q\left(\mathbf{z}|\mathbf{x}\right)}\right)d\mathbf{z}+\int_\mathbf{z}q\left(\mathbf{z}|\mathbf{x}\right)\ln\left(\frac{q\left(\mathbf{z}|\mathbf{x}\right)}{p\left(\mathbf{z}|\mathbf{x}\right)}\right)d\mathbf{z}\\ &=LB + KL\left(q\left(\mathbf{z}|\mathbf{x}\right)||p\left(\mathbf{z}|\mathbf{x}\right)\right) \end{aligned} lnp(x)=zq(zx)lnp(x)dz=zq(zx)ln(q(zx)p(x,z)p(zx)q(zx))dz=zq(zx)ln(q(zx)p(x,z))dz+zq(zx)ln(p(zx)q(zx))dz=LB+KL(q(zx)∣∣p(zx))
总之,要使 ln ⁡ p ( x ) \ln p\left(\mathbf{x}\right) lnp(x) 最大化,就等价于使 L B LB LB 最大化,而 L B LB LB 又有
L B = ∫ z q ( z ∣ x ) ln ⁡ ( p ( z ∣ x ) p ( z ) q ( z ∣ x ) ) d z = ∫ z q ( z ∣ x ) ln ⁡ ( p ( z ) q ( z ∣ x ) ) d z + ∫ z q ( z ∣ x ) ln ⁡ p ( x ∣ z ) d z = − K L ( q ( z ∣ x ) ∣ ∣ p ( z ) ) + E q ( z ∣ x ) ln ⁡ p ( x ∣ z ) \begin{aligned} LB &=\int_\mathbf{z}q\left(\mathbf{z}|\mathbf{x}\right)\ln\left(\frac{p\left(\mathbf{z}|\mathbf{x}\right)p\left(\mathbf{z}\right)}{q\left(\mathbf{z}|\mathbf{x}\right)}\right)d\mathbf{z}\\ &=\int_\mathbf{z}q\left(\mathbf{z}|\mathbf{x}\right)\ln\left(\frac{p\left(\mathbf{z}\right)}{q\left(\mathbf{z}|\mathbf{x}\right)}\right)d\mathbf{z}+\int_\mathbf{z}q\left(\mathbf{z}|\mathbf{x}\right)\ln p\left(\mathbf{x}|\mathbf{z}\right)d\mathbf{z}\\ &=-KL\left(q\left(\mathbf{z}|\mathbf{x}\right)||p\left(\mathbf{z}\right)\right)+\mathbb{E}_{q\left(\mathbf{z}|\mathbf{x}\right)}\ln p\left(\mathbf{x}|\mathbf{z}\right) \end{aligned} LB=zq(zx)ln(q(zx)p(zx)p(z))dz=zq(zx)ln(q(zx)p(z))dz+zq(zx)lnp(xz)dz=KL(q(zx)∣∣p(z))+Eq(zx)lnp(xz)
L B LB LB 最大化就是我们的目标,但是一般最优化问题写作求最小值的形式,因此对 L B LB LB 取负得到最小化的目标,也就是损失函数,记做 E L B O ELBO ELBO
E L B O = K L ( q ( z ∣ x ) ∣ ∣ p ( z ) ) − E q ( z ∣ x ) ln ⁡ p ( x ∣ z ) ELBO=KL\left(q\left(\mathbf{z}|\mathbf{x}\right)||p\left(\mathbf{z}\right)\right)-\mathbb{E}_{q\left(\mathbf{z}|\mathbf{x}\right)}\ln p\left(\mathbf{x}|\mathbf{z}\right) ELBO=KL(q(zx)∣∣p(z))Eq(zx)lnp(xz)
注意到,这里的 p ( z ) p\left(\mathbf{z}\right) p(z) 是先验分布,可以为任意分布,而 q ( z ∣ x ) q\left(\mathbf{z}|\mathbf{x}\right) q(zx) p ( x ∣ z ) p\left(\mathbf{x}|\mathbf{z}\right) p(xz) 也是由我们自行指定的, q ( z ∣ x ) q\left(\mathbf{z}|\mathbf{x}\right) q(zx) 实际上是 p ( z ∣ x ) p\left(\mathbf{z}|\mathbf{x}\right) p(zx) 的近似,因为我们算不出来 p ( z ∣ x ) p\left(\mathbf{z}|\mathbf{x}\right) p(zx),因此直接近似它。

从模型的角度来说 p ( x ∣ z ) p\left(\mathbf{x}|\mathbf{z}\right) p(xz) 是生成模型, q ( z ∣ x ) q\left(\mathbf{z}|\mathbf{x}\right) q(zx) 是鉴别模型,在 VAE 原文中, E L B O ELBO ELBO 中出现的三个分布都取多元高斯分布

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值