Model with Latent Variable
潜变量(Latent Variables)
对于数据 X \mathbf{X} X 的系统,有时候当我们引入从 X \mathbf{X} X 中派生出的额外变量 Z \mathbf{Z} Z ,可以使得模型具有更强的表达能力 (表示复杂结构) 以及有时候优化会更加简单.;但这些变量可能是未观测的.
latent variable 的定义是建模的一部分.
例如,在高斯混合模型中:对于一个样本 x n \mathbf{x}_n x n ,潜变量 z n \mathbf{z}_n z n 表示这个样本属于哪一个高斯分布;
后验概率 p ( z ∣ x ) p(\mathbf{z} \mid \mathbf{x}) p ( z ∣ x ) 被称为 responsibility ,即 latent variable 在给定原数据下的 distribution.
通常, 我们想要做一个 model with paramters θ \theta θ , maximizing the log-likelihood of the observed data:
$θ m l : = arg max θ log p ( X ∣ θ )
\theta_{ml} : = \arg \max_{\theta} \log p(X \mid\theta )
θ m l := arg max θ log p ( X ∣ θ ) $
这就是普通的 MLE.
而当我们 model with latent variable Z Z Z 的时候, 我们 by Bayesian formula, 可以等同于 maximize:
$log p ( X ∣ θ ) = log p ( X , Z ∣ θ ) log ( Z ∣ θ )
\log p(X \mid\theta ) = \log p(X, Z |\theta ) \, \log (Z | \theta)
log p ( X ∣ θ ) = log p ( X , Z ∣ θ ) log ( Z ∣ θ ) $
如果我们拥有完整数据{ X , Z } \{\mathbf{X}, \mathbf{Z}\} { X , Z } , 那么这个 joint prob log p ( X , Z ∣ θ ) \log p(X, Z |\theta ) log p ( X , Z ∣ θ ) 很容易求得.
但是, 如果我们并不知道 latent variable 呢 ? 比如说, Z Z Z 是一个 missing label. 那么
$log p ( X ∣ θ ) = log ∫ p ( X , Z ∣ θ ) d Z
\log p(X \mid\theta ) = \log \int p(X, Z |\theta ) \, dZ
log p ( X ∣ θ ) = log ∫ p ( X , Z ∣ θ ) d Z S p e i c i a l l y ,
Speicially, Sp e i c ia ll y , Z是 d i s c r e t e v a r i a b l e 的情况下 : 是 discrete variable 的情况下:
是 d i scre t e v a r iab l e 的情况下 : log p ( X ∣ θ ) = log ∑ Z p ( X , Z ∣ θ )
\log p(X \mid\theta ) = \log \sum_Z p(X, Z |\theta )
log p ( X ∣ θ ) = log ∑ Z p ( X , Z ∣ θ ) $
这个做法称为 Z Z Z 的 marginalization . 不得不进行 marginalization 使得想要优化这个式子变得困难 (因为 log 里套了积分/求和)
decomposition of log p ( X ∣ θ ) = log ∑ Z p ( X , Z ∣ θ ) \log p(X \mid\theta ) = \log \sum_Z p(X, Z |\theta ) log p ( X ∣ θ ) = log ∑ Z p ( X , Z ∣ θ ) into Evidence Lower Bound 和 KL divergence
目标是最大化对数似然 log p ( X ∣ θ ) \log p(\mathbf{X} \mid \theta) log p ( X ∣ θ ) :
log p ( X ∣ θ ) = ∑ Z q ( Z ) log p ( X ∣ θ ) (因为 ∑ Z q ( Z ) = 1 ) = ∑ Z q ( Z ) log p ( X , Z ∣ θ ) p ( Z ∣ X , θ ) = ∑ Z q ( Z ) log p ( X , Z ∣ θ ) q ( Z ) ⋅ q ( Z ) p ( Z ∣ X , θ ) = ∑ Z q ( Z ) log p ( X , Z ∣ θ ) q ( Z ) + ∑ Z q ( Z ) log q ( Z ) p ( Z ∣ X , θ ) \begin{align*}
\log p(\mathbf{X} \mid \theta)
&= \sum_{\mathbf{Z}} q(\mathbf{Z}) \log p(\mathbf{X} \mid \theta) \quad \text{(因为} \sum_{\mathbf{Z}} q(\mathbf{Z}) = 1)\\
&= \sum_{\mathbf{Z}} q(\mathbf{Z}) \log \frac{p(\mathbf{X}, \mathbf{Z} \mid \theta)}{p(\mathbf{Z} \mid \mathbf{X}, \theta)} \\
&= \sum_{\mathbf{Z}} q(\mathbf{Z}) \log \frac{p(\mathbf{X}, \mathbf{Z} \mid \theta)}{q(\mathbf{Z})} \cdot \frac{q(\mathbf{Z})}{p(\mathbf{Z} \mid \mathbf{X}, \theta)} \\
&= \sum_{\mathbf{Z}} q(\mathbf{Z}) \log \frac{p(\mathbf{X}, \mathbf{Z} \mid \theta)}{q(\mathbf{Z})} + \sum_{\mathbf{Z}} q(\mathbf{Z}) \log \frac{q(\mathbf{Z})}{p(\mathbf{Z} \mid \mathbf{X}, \theta)}
\end{align*} log p ( X ∣ θ ) = Z ∑ q ( Z ) log p ( X ∣ θ ) ( 因为 Z ∑ q ( Z ) = 1 ) = Z ∑ q ( Z ) log p ( Z ∣ X , θ ) p ( X , Z ∣ θ ) = Z ∑ q ( Z ) log q ( Z ) p ( X , Z ∣ θ ) ⋅ p ( Z ∣ X , θ ) q ( Z ) = Z ∑ q ( Z ) log q ( Z ) p ( X , Z ∣ θ ) + Z ∑ q ( Z ) log p ( Z ∣ X , θ ) q ( Z ) 我们把这两个成分,分别定义为
variational lower bound of q q q (或称为 Evidence Lower Bound, ELBO)
$
\begin{align}
\mathcal{L}(q, \theta) &: =\sum_{\mathbf{Z}} q(\mathbf{Z}) \log \frac{p(\mathbf{X}, \mathbf{Z} \mid \theta)}{q(\mathbf{Z})} \\
&= \mathbb{E}_{Z\sim q(Z)}[\log p(\mathbf{X}, \mathbf{Z} \mid \theta)] - \mathbb{E}_{Z\sim q(Z)}[\log q(\mathbf{Z})]
\end{align}
$
KL divergence of q q q w.r.t. p p p
K L ( q ( Z ) ∥ p ( Z ∣ X , θ ) ) : = ∑ Z q ( Z ) log q ( Z ) p ( Z ∣ X , θ ) = E Z ∼ q ( Z ) [ log q ( Z ) ] − E Z ∼ q ( Z ) [ log p ( Z ∣ X , θ ) ] \begin{align}
\mathrm{KL}(q(\mathbf{Z}) \parallel p(\mathbf{Z} \mid \mathbf{X}, \theta)) &:=\sum_{\mathbf{Z}} q(\mathbf{Z}) \log \frac{q(\mathbf{Z})}{p(\mathbf{Z} \mid \mathbf{X}, \theta)}\\
& = \mathbb{E}_{Z\sim q(Z)}[\log q(\mathbf{Z})] - \mathbb{E}_{Z\sim q(Z)}[\log p(\mathbf{Z}\mid \mathbf{X} ,\theta)]
\end{align} KL ( q ( Z ) ∥ p ( Z ∣ X , θ )) := Z ∑ q ( Z ) log p ( Z ∣ X , θ ) q ( Z ) = E Z ∼ q ( Z ) [ log q ( Z )] − E Z ∼ q ( Z ) [ log p ( Z ∣ X , θ )] 从而:
$log p ( X ∣ θ ) = L ( q , θ ) + K L ( q ( Z ) ∥ p ( Z ∣ X , θ ) )
\begin{aligned} \log p(\mathbf{X} \mid \theta) & =\mathcal{L}(q, \theta)+K L(q(\mathbf{Z}) \| p(\mathbf{Z} \mid \mathbf{X}, \theta))\end{aligned}
log p ( X ∣ θ ) = L ( q , θ ) + K L ( q ( Z ) ∥ p ( Z ∣ X , θ )) $
KL 散度
我们这里简写.
可以发现, KL-divergence 有很多种展开形式:
$K L ( q ∥ p ) = E z ∼ q ( z ) [ log q ( z ) p ( z ) ] = ∑ z q ( z ) log q ( z ) p ( z ) = − ∑ z q ( z ) log p ( z ) + ∑ z q ( z ) log q ( z ) = H ( q , p ) − H ( q )
\begin{aligned} K L(q \| p) &=\mathbb{E}_{z\sim q(z)}\left[\log \frac{q(z)}{p(z)}\right]\\
& =\sum_z q(z) \log \frac{q(z)}{p(z)} \\
& =-\sum_z q(z) \log p(z)+\sum_z q(z) \log q(z) \\
& = \mathbb{H}(q, p)-\mathbb{H}(q)
\end{aligned}
K L ( q ∥ p ) = E z ∼ q ( z ) [ log p ( z ) q ( z ) ] = z ∑ q ( z ) log p ( z ) q ( z ) = − z ∑ q ( z ) log p ( z ) + z ∑ q ( z ) log q ( z ) = H ( q , p ) − H ( q ) 因而两个分布的 K L 散度就是
因而两个分布的 KL 散度就是 因而两个分布的 K L 散度就是 p,q的 c r o s s e n t r o p y 减去 的 cross entropy 减去 的 crosse n t ro p y 减去 p$ 自己的 entropy.
这个结果是 0 当且仅当 p = q p=q p = q (下面会证明). 并且显然 p , q p,q p , q 这两个分布越是相近, 这个 KL 散度越低.
但是 notice:
$K L ( q ∥ p ) ≠ K L ( p ∥ q )
K L(q \| p) \not = K L(p \| q)
K L ( q ∥ p ) = K L ( p ∥ q ) $
这个行为不是 commutative 的.
K L ( p ‖ q ) KL(p‖q) K L ( p ‖ q ) 表示:真实分布是 p p p ,用 q q q 来近似它
K L ( q ‖ p ) KL(q‖p) K L ( q ‖ p ) 表示:真实分布是 q q q ,用 p p p 来近似它
Jensen 不等式: showing that KL 散度是非负的
Recall 凸分析中我们有 Jensen 不等式:
If f f f is convex , then for any 0 ≤ θ i ≤ 1 ( ∀ i ) 0 \leq \theta_i \leq 1(\forall i) 0 ≤ θ i ≤ 1 ( ∀ i ) s.t. \theta_1+\theta_2+\cdots+\theta_k=1 \\$ 都有:
f ( θ 1 x 1 + θ 2 x 2 + ⋯ + θ k x k ) ≤ θ 1 f ( x 1 ) + ⋯ + θ k f ( x k )
\begin{array}{r}
f\left(\theta_1 x_1+\theta_2 x_2+\cdots+\theta_k x_k\right) \leq \theta_1 f\left(x_1\right)+\cdots+\theta_k f\left(x_k\right)
\end{array}
f ( θ 1 x 1 + θ 2 x 2 + ⋯ + θ k x k ) ≤ θ 1 f ( x 1 ) + ⋯ + θ k f ( x k ) 这是 c o n v e x i n e q 的一个更广泛的 i n t e r p o l a t i o n 推广 . 它还可以从而推广到积分形式 : 对于任意一个 m e a s u r e s p a c e
这是 convex ineq 的一个更广泛的 interpolation 推广. 它还可以从而推广到积分形式: 对于任意一个 measure space 这是 co n v e x in e q 的一个更广泛的 in t er p o l a t i o n 推广 . 它还可以从而推广到积分形式 : 对于任意一个 m e a s u res p a ce (\Omega, A, \mu), 如果 m e a s u r a b l e , 如果 measurable , 如果 m e a s u r ab l e f是 c o n v e x 的,那取任意 m e a s u r a b l e f u n c t i o n 是 convex 的,那 取任意 measurable function 是 co n v e x 的,那取任意 m e a s u r ab l e f u n c t i o n g都有 : 都有:
都有 : φ ( ∫ Ω f d μ ) ≤ ∫ Ω φ ∘ f d μ
\varphi\left(\int_{\Omega} f \mathrm{~d} \mu\right) \leq \int_{\Omega} \varphi \circ f \mathrm{~d} \mu
φ ( ∫ Ω f d μ ) ≤ ∫ Ω φ ∘ f d μ 从而 c o r o l l a r y :
从而 corollary:
从而 coro ll a ry : f ( E [ x ] ) ≤ E [ f ( x ) ]
f(\mathbb{E}[x]) \leq \mathbb{E}[f(x)]
f ( E [ x ]) ≤ E [ f ( x )] $
因而,由于 − l o g -log − l o g 函数是 convex 的 (l o g log l o g 是 convex 的),我们可以由 Jensen 证明出:散度总是非负,且当且仅当 q = p ( Z ∣ X , θ ) q = p(\mathbf{Z} \mid \mathbf{X}, \theta) q = p ( Z ∣ X , θ ) 时取等号
$K L ( q ∥ p ) = E z ∼ q ( z ) [ log q ( z ) p ( z ) ] = E z ∼ q ( z ) [ − log p ( z ) q ( z ) ] ≥ − log ( E z ∼ q ( z ) [ p ( z ) q ( z ) ] ) = − log ( ∑ z q ( z ) p ( z ) q ( z ) ⏟ = ∑ z p ( z ) = 1 ) = 0
\begin{aligned} K L(q \| p) &=\mathbb{E}_{z\sim q(z)}\left[\log \frac{q(z)}{p(z)}\right]\\
& = \mathbb{E}_{z\sim q(z)}\left[-\log \frac{p(z)}{q(z)}\right] \\
&\geq -\log (\mathbb{E}_{z\sim q(z)}\left[ \frac{p(z)}{q(z)}\right]) \\
& = -\log (\underbrace{\sum_z q(z) \frac{p(z)}{q(z)}}_{=\sum_z p(z)=1}) \\ & =0\end{aligned}
K L ( q ∥ p ) = E z ∼ q ( z ) [ log p ( z ) q ( z ) ] = E z ∼ q ( z ) [ − log q ( z ) p ( z ) ] ≥ − log ( E z ∼ q ( z ) [ q ( z ) p ( z ) ] ) = − log ( = ∑ z p ( z ) = 1 z ∑ q ( z ) q ( z ) p ( z ) ) = 0 $
recall:
$
\begin{align*} \log p(\mathbf{X} \mid \theta) & =\mathcal{L}(q, \theta)+K L(q(\mathbf{Z}) \| p(\mathbf{Z} \mid \mathbf{X}, \theta))\end{align*}
由于 K L 非负 , 我们可以得到 : 对于任意的 d i s t r i b u t i o n
由于 KL 非负, 我们可以得到: 对于任意的 distribution 由于 K L 非负 , 我们可以得到 : 对于任意的 d i s t r ib u t i o n qo f of o f \mathbf{Z}, , , \mathcal{L}(q, \theta)是 是 是 \log p(\mathbf{X})$ 的一个 lower bound. 因此我们才把它叫做 variational lower bound .
EM Algorithm
EM Algorithm 是一个在设定了 latent variable Z Z Z 时,间接地 maximizing (log) p ( X ∣ θ ) p(X \mid\theta ) p ( X ∣ θ ) 的方法. 它并不直接优化 p ( X ∣ θ ) p(X \mid\theta ) p ( X ∣ θ ) , 而是通过不断 maximize 它的 variational lower bound L ( q , θ ) \mathcal{L}(q, \theta) L ( q , θ ) 的行为,来间接优化 p ( X ∣ θ ) p(X \mid\theta ) p ( X ∣ θ )
重复以下步骤直到收敛:
E-step (expectation): 固定参数 θ \theta θ ,compute posterior p ( Z ∣ X , θ ) p(\mathbf{Z} \mid \mathbf{X}, \theta) p ( Z ∣ X , θ ) , 然后把它赋给 q ( Z ) q(\mathbf{Z}) q ( Z ) ,使 variational lower bound L \mathcal{L} L 最大化 (此时 for 固定的 θ \theta θ , 有 L ( q , θ ) = log p ( X ∣ θ ) \mathcal{L}(q,\theta) = \log p(\mathbf{X} \mid \theta) L ( q , θ ) = log p ( X ∣ θ ) )
具体要做的即:
$q ( t ) ( Z ) : = p ( Z ∣ X , θ ( t ) )
q^{(t)}(\mathbf{Z}) := p(\mathbf{Z} \mid \mathbf{X}, \theta^{(t)})
q ( t ) ( Z ) := p ( Z ∣ X , θ ( t ) ) $
M-step (maximization):固定 q ( Z ) q(\mathbf{Z}) q ( Z ) ,最大化 E q [ log p ( X , Z ∣ θ ) ] \mathbb{E}_q[\log p(\mathbf{X}, \mathbf{Z} \mid \theta)] E q [ log p ( X , Z ∣ θ )] 得到新的 θ \theta θ
具体要做的即:
$θ ( t + 1 ) : = argmax θ L ( q ( t ) , θ ) = argmax θ ∑ Z q ( t ) ( Z ) log p ( X , Z ∣ θ )
\theta^{(t+1)} : = \operatorname{argmax}_\theta \mathcal{L}(q^{(t)}, \theta)=\operatorname{argmax}_\theta \sum_{\mathbf{Z}} q^{(t)}(\mathbf{Z}) \log p(\mathbf{X}, \mathbf{Z} \mid \theta)
θ ( t + 1 ) := argmax θ L ( q ( t ) , θ ) = argmax θ ∑ Z q ( t ) ( Z ) log p ( X , Z ∣ θ ) $
EM 即交替优化 q q q 和 θ \theta θ ,提升 ELBO 下界,直至收敛. E step 就是固定目前的参数 θ \theta θ , 把 q q q 重新设定为 p p p ,使得 variational lower bound 提升至等于我们需要的 liklihood;M step 就是固定住分布 q q q ,看看什么参数能够优化 variational lower bound.
EM 的 idea 是: use q(Z) as (factional) pseudo-counts and maximize the “data completion” log-likelihood".
E step 计算的 latent var 的后验概率,可以视为对未观测数据的“伪计数”(pseudo-counts);在 M step,利用这些伪计数来进行对数似然函数的最大化“data completion”.
图示
我们容易验证: EM Algorithm 一定是 converging 的. (一定单调递增, 又是有界, 因而 MCT)
EM for multiple data-points
The EM Algorithm: Multiple data-points
Variational lower bound for a single example x \mathbf{x} x :
log p ( x ∣ θ ) = ∑ z q ( z ) log p ( z , x ∣ θ ) q ( z ) + K L ( q ( z ) ∥ p ( z ∣ x , θ ) ) ≥ ∑ z q ( z ) log p ( z , x ∣ θ ) q ( z ) \begin{aligned}
\log p(\mathbf{x} \mid \theta) & =\sum_{\mathbf{z}} q(\mathbf{z}) \log \frac{p(\mathbf{z}, \mathbf{x} \mid \theta)}{q(\mathbf{z})}+K L(q(\mathbf{z}) \| p(\mathbf{z} \mid \mathbf{x}, \theta)) \\
& \geq \sum_{\mathbf{z}} q(\mathbf{z}) \log \frac{p(\mathbf{z}, \mathbf{x} \mid \theta)}{q(\mathbf{z})}
\end{aligned} log p ( x ∣ θ ) = z ∑ q ( z ) log q ( z ) p ( z , x ∣ θ ) + K L ( q ( z ) ∥ p ( z ∣ x , θ )) ≥ z ∑ q ( z ) log q ( z ) p ( z , x ∣ θ )
Lower bound on the log-likelihood of the entire training data D = { x ( 1 ) , … , x ( N ) } \mathcal{D}=\left\{\mathbf{x}^{(1)}, \ldots, \mathbf{x}^{(N)}\right\} D = { x ( 1 ) , … , x ( N ) } :
log p ( D ∣ θ ) = ∑ n log p ( x ( n ) ∣ θ ) = ∑ n ∑ z q ( n ) ( z ) log p ( z , x ( n ) ∣ θ ) q ( n ) ( z ) + ∑ n K L ( q ( n ) ( z ) ∥ p ( z ∣ x ( n ) , θ ) ) ≥ ∑ n ∑ z q ( n ) ( z ) log p ( z , x ( n ) ∣ θ ) q ( n ) ( z ) \begin{aligned}
\log p(\mathcal{D} \mid \theta)=\sum_n \log p\left(\mathbf{x}^{(n)} \mid \theta\right) & =\sum_n \sum_{\mathbf{z}} q^{(n)}(\mathbf{z}) \log \frac{p\left(\mathbf{z}, \mathbf{x}^{(n)} \mid \theta\right)}{q^{(n)}(\mathbf{z})}+\sum_n K L\left(q^{(n)}(\mathbf{z}) \| p\left(\mathbf{z} \mid \mathbf{x}^{(n)}, \theta\right)\right) \\
& \geq \sum_n \sum_{\mathbf{z}} q^{(n)}(\mathbf{z}) \log \frac{p\left(\mathbf{z}, \mathbf{x}^{(n)} \mid \theta\right)}{q^{(n)}(\mathbf{z})}
\end{aligned} log p ( D ∣ θ ) = n ∑ log p ( x ( n ) ∣ θ ) = n ∑ z ∑ q ( n ) ( z ) log q ( n ) ( z ) p ( z , x ( n ) ∣ θ ) + n ∑ K L ( q ( n ) ( z ) ∥ p ( z ∣ x ( n ) , θ ) ) ≥ n ∑ z ∑ q ( n ) ( z ) log q ( n ) ( z ) p ( z , x ( n ) ∣ θ ) 注意: 每个 n n n 用的 q q q 是不一样的!
因而 EM for multiple data points:
Initialize random parameters θ \theta θ .
Repeat until convergence:
"E-step": Set q ( n ) ( z ) = p ( z ∣ x ( n ) , θ ) q^{(n)}(\mathbf{z})=p\left(\mathbf{z} \mid \mathbf{x}^{(n)}, \theta\right) q ( n ) ( z ) = p ( z ∣ x ( n ) , θ ) for each training sample n n n .
"M-step": Update θ \theta θ via the following maximization:
arg max θ ∑ n ∑ z q ( n ) ( z ) log p ( z , x ( n ) ∣ θ ) \arg \max _\theta \sum_n \sum_{\mathbf{z}} q^{(n)}(\mathbf{z}) \log p\left(\mathbf{z}, \mathbf{x}^{(n)} \mid \theta\right) arg θ max n ∑ z ∑ q ( n ) ( z ) log p ( z , x ( n ) ∣ θ )
注意:这个过程对于很多具体的情况,可以 vectorize.
eg:GMM
z ∈ { 1 , … , K } \mathbf{z} \in\{1, \ldots, K\} z ∈ { 1 , … , K } ,是 cluster assignment
q ( n ) ( z ) = γ k ( n ) q^{(n)}(z)=\gamma_k^{(n)} q ( n ) ( z ) = γ k ( n ) 是第 n n n 个样本属于第 k k k 类的"软分配"概率
可以将所有 γ \gamma γ 组织成一个 N × K N \times K N × K 的矩阵
每个 component 的参数 θ k \theta_k θ k 也可以向量化操作(均值向量,协方差矩阵等)这时整个 E step 和 M step 都可以用 矩阵操作,广播,batch 乘法等实现。
但是有的模型是:
隐变量是 连续的
或者是图模型中很复杂的结构(比如 HMM,LDA,VAE 中的 latent vector)
那你就需要 采样 或 近似推断,vectorization 就变得困难(但不是不可能,需要更复杂的技巧,比如 Monte Carlo+vectorized sampling)。
What if E-step 需算的 p ( Z ∣ X , θ ) p(Z \mid X, \theta) p ( Z ∣ X , θ ) intractable?
(Note: 在每一步,我们需要根据当前的参数 θ ( t ) \theta^{(t)} θ ( t ) 计算 latent var 的后验分布 p ( Z ∣ X , θ ) p(Z \mid X, \theta) p ( Z ∣ X , θ ) 。这要求我们能显式地写出并计算这个分布。
这被称为 tractable :可以显式地写出并计算(比如 GMM 中,posterior 是 softmax over components,就很 tractable)
Q: 如果 p ( Z ∣ X , θ ) p(Z \mid X, \theta) p ( Z ∣ X , θ ) 不可解(intractable),那怎么办?
当后验不可 tractable,我们就不能用 standard EM 了,需要改用更 general 的方法,比如:
Variational EM(变分 EMa
用一个可计算的变分分布 q ( Z ) ≈ p ( Z ∣ X , θ ) q(Z) \approx p(Z \mid X, \theta) q ( Z ) ≈ p ( Z ∣ X , θ )
不再要求 q ( Z ) = p ( Z ∣ X , θ ) q(Z) = p(Z \mid X, \theta) q ( Z ) = p ( Z ∣ X , θ ) ,而是优化下界:
L ( q , θ ) = E q ( Z ) [ log p ( X , Z ∣ θ ) ] − E q ( Z ) [ log q ( Z ) ] \mathcal{L}(q, \theta) = \mathbb{E}_{q(Z)}[\log p(X, Z \mid \theta)] - \mathbb{E}_{q(Z)}[\log q(Z)] L ( q , θ ) = E q ( Z ) [ log p ( X , Z ∣ θ )] − E q ( Z ) [ log q ( Z )]
然后交替优化 q q q 和 θ \theta θ ,这就是变分推断框架。
MCMC-EM(采样版 EM)
用采样方法近似计算 E 步中的期望,比如用 Gibbs Sampling 或 Metropolis-Hastings 从 p ( Z ∣ X , θ ) p(Z \mid X, \theta) p ( Z ∣ X , θ ) 中采样
这里不讲解)