实例 x \mathbf{x} x 由条件分布 x ∣ z \mathbf{x}|\mathbf{z} x∣z 生成, 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(z∣x)lnp(x)dz=∫zq(z∣x)ln(q(z∣x)p(x,z)p(z∣x)q(z∣x))dz=∫zq(z∣x)ln(q(z∣x)p(x,z))dz+∫zq(z∣x)ln(p(z∣x)q(z∣x))dz=LB+KL(q(z∣x)∣∣p(z∣x))
总之,要使
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(z∣x)ln(q(z∣x)p(z∣x)p(z))dz=∫zq(z∣x)ln(q(z∣x)p(z))dz+∫zq(z∣x)lnp(x∣z)dz=−KL(q(z∣x)∣∣p(z))+Eq(z∣x)lnp(x∣z)
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(z∣x)∣∣p(z))−Eq(z∣x)lnp(x∣z)
注意到,这里的
p
(
z
)
p\left(\mathbf{z}\right)
p(z) 是先验分布,可以为任意分布,而
q
(
z
∣
x
)
q\left(\mathbf{z}|\mathbf{x}\right)
q(z∣x) 和
p
(
x
∣
z
)
p\left(\mathbf{x}|\mathbf{z}\right)
p(x∣z) 也是由我们自行指定的,
q
(
z
∣
x
)
q\left(\mathbf{z}|\mathbf{x}\right)
q(z∣x) 实际上是
p
(
z
∣
x
)
p\left(\mathbf{z}|\mathbf{x}\right)
p(z∣x) 的近似,因为我们算不出来
p
(
z
∣
x
)
p\left(\mathbf{z}|\mathbf{x}\right)
p(z∣x),因此直接近似它。
从模型的角度来说 p ( x ∣ z ) p\left(\mathbf{x}|\mathbf{z}\right) p(x∣z) 是生成模型, q ( z ∣ x ) q\left(\mathbf{z}|\mathbf{x}\right) q(z∣x) 是鉴别模型,在 VAE 原文中, E L B O ELBO ELBO 中出现的三个分布都取多元高斯分布