贝叶斯推断中的边际似然-变分推断
边际似然的背景
在贝叶斯框架下,我们有:
p(θ∣D)=p(D∣θ)p(θ)p(D)(1)p(\theta|\mathcal{D})=\frac{p(\mathcal{D}|\theta)p(\theta)}{p(\mathcal{D})}\qquad{(1)}p(θ∣D)=p(D)p(D∣θ)p(θ)(1)
其中分母:
p(D)=∫p(D∣θ)p(θ)dθp(\mathcal{D})=\int p(\mathcal{D}|\theta)p(\theta)d\thetap(D)=∫p(D∣θ)p(θ)dθ
是边际似然,反应模型对数据的解释能力。但是这个积分通常是高维的、没有解析形式,因此我们需要:
- 采样近似(如MCMC)
- 优化近似(如Variational Inference)
变分推断基本思想
我们可以使用一个可计算的分布q(θ)q(\theta)q(θ)来近似后验分布p(θ∣D)p(\theta|\mathcal{D})p(θ∣D)。
我们希望q(θ)q(\theta)q(θ)尽量接近真实后验,也就是最小化KL散度:
KL(q(θ)∣∣p(θ∣D))=∫q(θ)logq(θ)p(θ∣D)dθ\mathrm{KL}(q(\theta)||p(\theta|\mathcal{D}))=\int q(\theta)\log\frac{q(\theta)}{p(\theta|\mathcal{D})}d\thetaKL(q(θ)∣∣p(θ∣D))=∫q(θ)logp(θ∣D)q(θ)dθ
由于p(D)p(\mathcal{D})p(D)是常数(与θ\thetaθ无关),我们无法直接最小化它,但是可以通过下式进行变形:
logp(D)=L(q)+KL(q(θ)∣∣p(θ∣D))(2)\log p(\mathcal{D})=\mathcal{L}(q)+\mathrm{KL}(q(\theta)||p(\theta|\mathcal{D}))\quad\quad{(2)}logp(D)=L(q)+KL(q(θ)∣∣p(θ∣D))(2)
因此:
L(q)=∫q(θ)logp(D,θ)q(θ)dθ\mathcal{L}(q)=\int q(\theta)\log\frac{p(\mathcal{D},\theta)}{q(\theta)}d\thetaL(q)=∫q(θ)logq(θ)p(D,θ)dθ是证据下限(Evidence Lower Bound, ELBO)。因此最大化ELBO⇔\Leftrightarrow⇔最小化KL散度。
推导过程
我们对贝叶斯公式(1)两边取对数并取期望(期望分布为q(θ)q(\theta)q(θ)):
Eq[logp(θ∣D)]=Eq[logp(D,θ)]−logp(D)E_q[\log p(\theta|\mathcal{D})]=E_q[\log p(\mathcal{D},\theta)]-\log p(\mathcal{D})Eq[logp(θ∣D)]=Eq[logp(D,θ)]−logp(D)
logp(D)=log∫p(D,θ)dθ\log p(\mathcal{D})=\log\int p(\mathcal{D},\theta)d\thetalogp(D)=log∫p(D,θ)dθ
引入q(θ)q(\theta)q(θ)
logp(D)=log∫q(θ)p(D,θ)q(θ)dθ\log p(\mathcal{D})=\log\int q(\theta)\frac{p(\mathcal{D},\theta)}{q(\theta)}d\thetalogp(D)=log∫q(θ)q(θ)p(D,θ)dθ
利用Jensen不等式:
logp(D)≥∫q(θ)logp(D,θ)q(θ)dθ=L(q)\log p(\mathcal{D})\geq\int q(\theta)\log\frac{p(\mathcal{D},\theta)}{q(\theta)}d\theta=\mathcal{L}(q)logp(D)≥∫q(θ)logq(θ)p(D,θ)dθ=L(q)
KL散度的定义为:
KL(q(θ)∥p(θ∣D))=∫q(θ)logq(θ)p(θ∣D)dθ(3)\mathrm{KL}(q(\theta)\|p(\theta|\mathcal{D}))=\int q(\theta)\log\frac{q(\theta)}{p(\theta|\mathcal{D})}d\theta\qquad{(3)}KL(q(θ)∥p(θ∣D))=∫q(θ)logp(θ∣D)q(θ)dθ(3)
KL(q(θ)∥p(θ∣D))=∫q(θ)(logq(θ)−logp(θ∣D))dθ=∫q(θ)logq(θ)dθ⏟Eq[logq(θ)]−∫q(θ)logp(θ∣D)dθ⏟Eq[logp(θ∣D)](4)\mathrm{KL}(q(\theta)\|p(\theta|\mathcal{D}))=\int q(\theta)\left(\log q(\theta)-\log p(\theta\mid\mathcal{D})\right)d\theta=\underbrace{\int q(\theta)\log q(\theta)d\theta}_{E_q[\log q(\theta)]}-\underbrace{\int q(\theta)\log p(\theta\mid\mathcal{D})d\theta}_{E_q[\log p(\theta|\mathcal{D})]}\qquad{(4)}KL(q(θ)∥p(θ∣D))=∫q(θ)(logq(θ)−logp(θ∣D))dθ=Eq[logq(θ)]∫q(θ)logq(θ)dθ−Eq[logp(θ∣D)]∫q(θ)logp(θ∣D)dθ(4)
由公式(1)可以得到logp(θ∣D)=logp(D,θ)−logp(D)\log p(\theta\mid\mathcal{D})=\log p(\mathcal{D},\theta)-\log p(\mathcal{D})logp(θ∣D)=logp(D,θ)−logp(D)。将其带入公式(4)的第二项:
Eq[logp(θ∣D)]=∫q(θ)(logp(D,θ)−logp(D))dθ.E_q[\log p(\theta\mid\mathcal{D})]=\int q(\theta)\left(\log p(\mathcal{D},\theta)-\log p(\mathcal{D})\right)d\theta.Eq[logp(θ∣D)]=∫q(θ)(logp(D,θ)−logp(D))dθ.
因为logp(D)\log p(\mathcal{D})logp(D)与θ\thetaθ无关,且∫q(θ)dθ=1\int q(\theta)d\theta=1∫q(θ)dθ=1,得到:
Eq[logp(θ∣D)]=Eq[logp(D,θ)]−logp(D)(5)E_q[\log p(\theta\mid\mathcal{D})]=E_q[\log p(\mathcal{D},\theta)]-\log p(\mathcal{D})\qquad{(5)}Eq[logp(θ∣D)]=Eq[logp(D,θ)]−logp(D)(5)
将公式(5)代入KL散度(公式(4))的展开式,整理得到:
KL(q∥p)=logp(D)−(Eq[logp(D,θ)]−Eq[logq(θ)])(6)\mathrm{KL}(q\|p)=\log p(\mathcal{D})-\left(E_q[\log p(\mathcal{D},\theta)]-E_q[\log q(\theta)]\right)\qquad{(6)}KL(q∥p)=logp(D)−(Eq[logp(D,θ)]−Eq[logq(θ)])(6)
定义ELBO并最终写出恒等式
定义证据下界(ELBO)为:
L(q):=Eq[logp(D,θ)]−Eq[logq(θ)].\mathcal{L}(q):=E_q[\log p(\mathcal{D},\theta)]-E_q[\log q(\theta)].L(q):=Eq[logp(D,θ)]−Eq[logq(θ)].
于是公式(6)可以写成:
KL(q(θ)∥p(θ∣D))=logp(D)−L(q)\mathrm{KL}(q(\theta)\|p(\theta|\mathcal{D}))=\log p(\mathcal{D})-\mathcal{L}(q)KL(q(θ)∥p(θ∣D))=logp(D)−L(q)
也就是:
logp(D)=L(q)+KL(q(θ)∥p(θ∣D))\log p(\mathcal{D})=\mathcal{L}(q)+\mathrm{KL}(q(\theta)\|p(\theta|\mathcal{D}))logp(D)=L(q)+KL(q(θ)∥p(θ∣D))
这个公式意味着:
- logp(D)\log p(\mathcal{D})logp(D):我们想要最大化的模型证据(边际似然)。
- L(q)\mathcal{L}(q)L(q):我们能优化的下界(ELBO)。
- KL(q∣∣p)KL(q||p)KL(q∣∣p):永远非负。
1394

被折叠的 条评论
为什么被折叠?



