统计学习方法 第九章笔记: EM 算法

本文介绍了EM(Expectation-Maximization)算法在统计学习中的应用,通过三硬币模型详细阐述了算法原理。首先提出了问题背景,即如何在无法直接观察到所有数据的情况下,估计硬币正面向上的概率。接着,文章通过EM算法的推导,解释了E步(期望)和M步(最大化)的含义和作用,以及如何利用EM算法逐步优化参数估计。最后,讨论了EM算法的收敛性,证明了算法在每次迭代后目标函数非减,确保了算法的收敛性。


如果概率模型都是观测变量,那么给定数据就可以用极大似然估计法或者贝叶斯估计发去获得模型。但是,有时候概率模型既有观测变量,又有隐变量或者潜在变量,这样就不能用这些估计方法了。本文要介绍的EM算法可以解决这类问题。

三硬币模型

为了更好的描述EM算法,先提出一个实际的问题。问题描述如下:

假设有3枚硬币,分别记作A,B和C。 这些硬币正面向上的概率分别是 π \pi π p p p q q q 。进行如下抛硬币试验:先抛硬币A, 根据其结果选出硬币B或者硬币C,正面选硬币B,反面选硬币C;然后掷选出的硬币,抛硬币的结果,出现正面记作1,出现反面记作0;独立重复10次试验。结果如下:

1,1,0,1,0,0,1,0,1,1

假设只能观测到掷硬币的结果,不能观测掷硬币的过程。问如何估计三硬币正面出现的概率。

我们用 θ = ( π , p , q ) \theta = (\pi,p,q) θ=(π,p,q)表示模型的参数,y表示某次得到的0或者1的观测结果,z表示隐变量,表示某次A的结果。一般地,用Y表示观测变量数据,用Z表示隐变量的数据。在上面的问题中, Y = ( y 1 , y 2 , … , y n ) T Y=(y_1, y_2,…,y_n)^T Y(y1y2,,yn)T表示观测到硬币B、C的0,1序列, Z = ( z 1 , z 2 , … , z n ) T Z=(z_1,z_2,…,z_n)^T Z(z1,z2,,zn)T表示未观测到的硬币A的0,1序列。

考虑用极大似然估计求模型参数 θ ^ = ( π , p , q ) \hat \theta=(\pi,p,q) θ^=(π,p,q)的, 即:
L ( θ ) = log ⁡ P ( Y ∣ θ ) = log ⁡ ∑ Z P ( Y , Z ∣ θ ) = ∑ j = 1 10 l o g ∑ i = 1 2 P ( y j , z i ∣ θ ) (1) \begin{aligned} L(\theta) &= \log P(Y|\theta) \\ &= \log \sum\limits_{Z}P(Y,Z|\theta) \\&= \sum_{j=1}^{10}log\sum_{i=1}^{2} P(y_j,z_i|\theta) \end{aligned} \tag 1 L(θ)=logP(Yθ)=logZP(Y,Zθ)=j=110logi=12P(yj,ziθ)(1)

θ ^ = arg ⁡ max ⁡ θ L ( θ ) (2) \hat \theta = \arg\max\limits_{\theta} L(\theta) \tag 2 θ^=argθmaxL(θ)(2)

直接求(2)的参数θ会比较困难,因为上式存在隐含随机变量Z。如果Z是个已知的数,那么使用极大似然估计来估算会很容易。在这种Z不确定的情形下,EM算法就派上用场了。

EM推导背景

对于式子1,我们做如下变形:
L ( θ ) = ∑ j = 1 10 l o g ∑ i = 1 2 P ( y j , z i ∣ θ ) = ∑ j = 1 10 l o g ∑ i = 1 2 D j ( z i ) P ( y j , z i ∣ θ ) D j ( z i ) ( 3 ) ≥ ∑ j = 1 10 ∑ i = 1 2 D j ( z i ) l o g P ( y j , z i ∣ θ ) D j ( z i ) ( 4 ) \begin{aligned}L(\theta) &= \sum_{j=1}^{10}log\sum_{i=1}^{2} P(y_j,z_i|\theta) \\&=\sum_{j=1}^{10}log\sum_{i=1}^{2}D_j(z_i)\frac{P(y_j,z_i|\theta) }{D_j(z_i)} \qquad (3) \\&\geq \sum_{j=1}^{10}\sum_{i=1}^{2}D_j(z_i)log\frac{P(y_j,z_i|\theta) }{D_j(z_i)} \qquad (4)\end{aligned} L(θ)=j=110logi=12P(yj,ziθ)=j=110logi=12Dj(zi)Dj(zi)P(yj,ziθ)(3)j=110i=12Dj(zi)logDj(zi)P(yj,ziθ)(4)
其中,对于每个实例i,用 D i D_i Di表示样本实例隐含变量z的某种分布,且 D i D_i Di满足条件 ∑ z D i ( z ) = 1 , D i ( z ) ≥ 0 \sum_zD_i(z)=1,D_i(z)\geq0 zDi(z)=1,Di(z)0。由于对数函数是凹函数,则根据詹森不等式可以从(3)缩放为(4)。

具体来说,问题简化为如何求解随机变量的期望。假如我们的期望表达式为:
E ( x ) = ∑ x ∗ p ( x ) E(x)=\sum x*p(x) E(x)=xp(x)
我们可以把(3)式当中的 D j ( z i ) D_j(z_{i}) Dj(zi)看上式中的概率 p ( x ) p(x) p(x),把 P ( y j , z i ∣ θ ) D j ( z i ) \frac{P(y_j,z_i|\theta) }{D_j(z_i)} Dj(zi)P(yj,ziθ)看作是 D j ( z i ) D_j(z_{i}) Dj(zi)的取值x,可以得到:
∑ Z D j ( z i ) P ( y j , z i ∣ θ ) D j ( z i ) \sum\limits_Z D_j(z_i)\frac{P(y_j,z_i|\theta) }{D_j(z_i)} ZDj(zi)Dj(zi)P(yj,ziθ)
就是 P ( y j , z i ∣ θ ) D j ( z i ) \frac{P(y_j,z_i|\theta) }{D_j(z_i)} Dj(zi)P(yj,ziθ)的期望。经过詹森不等式变形之后,就得到了式子(4),于是似然函数L(θ)可以简写成:
L ( θ ) ≥ J ( z , D ) (5) L(θ) \geq J(z,D) \tag 5 L(θ)J(z,D)(5)
的形式,那么:

我们可以不断优化L(θ)的下界 J ( z , D ) J(z,D) J(z,D)来达到优化L(θ)的目的

现在有了两个问题:

1,式子(5)什么时候取等?

在詹森不等式中说到,当自变量X=E(X)时,即为常数的时候,等式成立。也就是:
P ( y j , z i ∣ θ ) D j ( z i ) = c (6) \frac{P(y_j,z_i|\theta) }{D_j(z_i)} = c \tag 6 Dj(zi)P(yj,ziθ)=c(6)
2,D函数怎么来的?

前面提到 ∑ z D i ( z ) = 1 \sum_zD_i(z)=1 zDi(z)=1,则有以下的推导过程:
P ( y j , z i ∣ θ ) = D j ( z i ∣ θ ) c ∑ Z P ( y j , z i ∣ θ ) = ∑ Z D j ( z i ∣ θ ) c P(y_j,z_i|\theta) = D_j(z_i|\theta) c \\ \sum\limits_Z P(y_j,z_i|\theta) = \sum\limits_Z D_j(z_i|\theta) c P(yj,ziθ)=Dj(ziθ)cZP(yj,ziθ)=ZDj(ziθ)c

∑ Z P ( y j , z i ∣ θ ) = c (7) \sum\limits_Z P(y_j,z_i|\theta) = c \\ \tag 7 ZP(yj,ziθ)=c(7)

将(7)代入(6)得到:
D j ( z i ) = P ( y j , z i ∣ θ ) ∑ Z P ( y j , z i ∣ θ ) = P ( y j , z i ∣ θ ) P ( y j ∣ θ ) = P ( z i ∣ y j , θ ) \begin{aligned} D_j(z_i) &= \frac{P(y_j,z_i|\theta)}{\sum\limits_Z P(y_j,z_i|\theta)} \\ &= \frac{P(y_j,z_i|\theta)}{ P(y_j|\theta)} \\ &= P(z_i|y_j,\theta) \end{aligned} Dj(zi)=ZP(yj,ziθ)P(yj,ziθ)=P(yjθ)P(yj,ziθ)=P(ziyj,θ)
所以D函数本质上是隐变量z的后验概率:
D j ( z i ) = P ( z i ∣ y j , θ ) D_j(z_i) = P(z_i|y_j,\theta) Dj(zi)=P(ziyj,θ)
到此为止,我们对式子(1)、(5)有了更多的了解,也就是有:
L ( θ ) ≥ J ( z , D ) = ∑ j = 1 10 ∑ i = 1 2 D j ( z i ) l o g P ( y j , z i ∣ θ ) D j ( z i ) = ∑ j = 1 10 ∑ i = 1 2 P ( z i ∣ y j , θ ) l o g P ( y j , z i ∣ θ ) P ( z i ∣ y j , θ ) \begin{aligned} L(θ)& \geq J(z,D) \\ &=\sum_{j=1}^{10}\sum_{i=1}^{2}\color{green} D_j(z_i) \color{black}log\frac{P(y_j,z_i|\theta) }{\color{green}D_j(z_i)} \\ &=\sum_{j=1}^{10}\sum_{i=1}^{2} \color{green}P(z_i|y_j,\theta) \color{black}log\frac{P(y_j,z_i|\theta) }{ \color{green}P(z_i|y_j,\theta) } \end{aligned} L(θ)J(z,D)=j=110i=12Dj(zi)logDj(zi)P(yj,ziθ)=j=110i=12P(ziyj,θ)logP(ziyj,θ)P(yj,ziθ)
将上面的式子一般化可以得到:
L ( θ ) ≥ ∑ Z P ( Z ∣ Y , θ ( i ) ) log ⁡ P ( Y , Z ∣ θ ) P ( Z ∣ Y , θ ( i ) ) = ∑ Z P ( Z ∣ Y , θ ( i ) ) log ⁡ P ( Y ∣ Z , θ ) P ( Z ∣ θ ) P ( Z ∣ Y , θ ( i ) ) (8) \begin{aligned} L(\theta) &\geq \sum_Z \color{green}P(Z|Y,\theta^{(i)})\color{black}\log \frac{P(Y,Z|\theta)}{\color{green}P(Z|Y,\theta^{(i)})\color{black}}\\ &= \sum_Z \color{green}P(Z|Y,\theta^{(i)})\color{black}\log \frac{P(Y|Z,\theta)P(Z|\theta)}{\color{green}P(Z|Y,\theta^{(i)})\color{black}} \end{aligned} \tag 8 L(θ)ZP(ZY,θ(i))logP(ZY,θ(i))P(Y,Zθ)=ZP(ZY,θ(i))logP(ZY,θ(i))P(YZ,θ)P(Zθ)(8)
了解了上面的基础知识,下面就可以了解实际的EM算法了。

EM算法步骤

输入: 观测变量数据 Y Y Y,隐变量数据 Z Z Z,联合分布 P ( Y , Z ∣ θ ) P(Y,Z|\theta) P(Y,Zθ),条件分布 P ( Z ∣ Y , θ ) P(Z|Y,\theta) P(ZY,θ)

输出: 模型参数 θ \theta θ

1,选择参数的初值 θ ( 0 ) \theta^{(0)} θ(0),开始迭代

2,E步:记 θ ( i ) \theta^{(i)} θ(i)为第 i i i 次迭代参数 θ \theta θ的估计值,在第 i + 1 i+1 i+1次迭代的 E E E步,计算
Q ( θ , θ ( i ) ) = ∑ Z P ( Z ∣ Y , θ ( i ) ) log ⁡ P ( Y , Z ∣ θ ) \begin{aligned} Q(\theta, \theta^{(i)}) =& \sum_Z\color{green}P(Z|Y, \theta^{(i)})\color{red}\log P(Y,Z|\theta) \end{aligned} Q(θ,θ(i))=ZP(ZY,θ(i))logP(Y,Zθ)
3,M步:求使 Q ( θ , θ ( i ) ) Q(\theta, \theta^{(i)}) Q(θ,θ(i))最大化的 θ \theta θ,确定第 i + 1 i+1 i+1次迭代的参数估计值
θ ( i + 1 ) = arg ⁡ max ⁡ θ Q ( θ , θ ( i ) ) \theta^{(i+1)}=\arg\max_\theta Q(\theta, \theta^{(i)}) θ(i+1)=argθmaxQ(θ,θ(i))
4,重复2,3两步,直到收敛。

上面的步骤中提到了Q函数,它是指完全数据(Y,Z)的对数似然函数 log ⁡ P ( Y , Z ∣ θ ) \log P(Y, Z|\theta) logP(Y,Zθ)关于给定观测数据 Y Y Y的当前参数 θ ( i ) \theta^{(i)} θ(i)下,对观测数据 Z Z Z条件概率分布 P ( Z ∣ Y , θ ( i ) ) P(Z|Y,\theta^{(i)}) P(ZY,θ(i))的期望表达式

也就是说对于期望函数 E ( x ) = ∑ x ∗ p ( x ) E(x)=\sum x*p(x) E(x)=xp(x)而言, log ⁡ P ( Y , Z ∣ θ ) \log P(Y, Z|\theta) logP(Y,Zθ) 是x, P ( Z ∣ Y , θ ( i ) ) P(Z|Y,\theta^{(i)}) P(ZY,θ(i)) (也就是上一节提到的D函数)是p(x)。

要注意的是, Q ( θ , θ ( i ) ) Q(\theta, \theta^{(i)}) Q(θ,θ(i))中的θ表示是要极大化的参数。EM算法,或者说期望最大化算法的两个步骤实际在:

  1. 给定 θ ( i ) \theta^{(i)} θ(i)后,求期望的表达式,也就是Q函数的具体形式(先优化Z)
  2. 求得到的Q函数(期望表达式)取到极大值的新参数 θ ( i + 1 ) \theta^{(i+1)} θ(i+1) (再优化θ)

EM算法的导出

为什么EM算法能近似实现对观测数据的极大似然估计?Q函数又是怎么来的?

我们知道:
L ( θ ) = log ⁡ P ( Y ∣ θ ) = log ⁡ ∑ Z P ( Y , Z ∣ θ ) = log ⁡ ( ∑ Z P ( Y ∣ Z , θ ) P ( Z ∣ θ ) ) L(\theta)=\log P(Y|\theta)=\log \sum_Z P(Y,Z|\theta)=\log(\sum_Z P(Y|Z,\theta)P(Z|\theta)) L(θ)=logP(Yθ)=logZP(Y,Zθ)=log(ZP(YZ,θ)P(Zθ))
那么有:
L ( θ ) − L ( θ ( i ) ) = log ⁡ ( ∑ Z P ( Y ∣ Z , θ ( i ) ) P ( Y ∣ Z , θ ) P ( Z ∣ θ ) P ( Y ∣ Z , θ ( i ) ) ) − log ⁡ P ( Y ∣ θ ( i ) ) ≥ ∑ Z P ( Z ∣ Y , θ ( i ) ) log ⁡ P ( Y ∣ Z , θ ) P ( Z ∣ θ ) P ( Z ∣ Y , θ ( i ) ) − log ⁡ P ( Y ∣ θ ( i ) ) = ∑ Z P ( Z ∣ Y , θ ( i ) ) log ⁡ P ( Y ∣ Z , θ ) P ( Z ∣ θ ) P ( Z ∣ Y , θ ( i ) ) − ∑ Z P ( Z ∣ Y , θ ( i ) ) log ⁡ P ( Y ∣ θ ( i ) ) = ∑ Z P ( Z ∣ Y , θ ( i ) ) log ⁡ P ( Y ∣ Z , θ ) P ( Z ∣ θ ) P ( Z ∣ Y , θ ( i ) ) P ( Y ∣ θ ( i ) ) \begin{aligned} L(\theta)-L(\theta^{(i)})&=\log \left(\sum_Z\color{green}P(Y|Z,\theta^{(i)})\color{black}\frac{P(Y|Z,\theta)P(Z|\theta)}{\color{green}P(Y|Z,\theta^{(i)})}\color{black}\right)-\log P(Y|\theta^{(i)})\\ &\ge\sum_Z \color{green}P(Z|Y,\theta^{(i)})\color{black}\log \frac{P(Y|Z,\theta)P(Z|\theta)}{\color{green}P(Z|Y,\theta^{(i)})\color{black}}-\log P(Y|\theta^{(i)})\\ &=\sum_Z P(Z|Y,\theta^{(i)})\log \frac{P(Y|Z,\theta)P(Z|\theta)}{P(Z|Y,\theta^{(i)})}-\color{red}\sum_ZP(Z|Y,\theta^{(i)})\color{black}\log P(Y|\theta^{(i)})\\ &=\sum_ZP(Z|Y,\theta^{(i)})\log \frac{P(Y|Z,\theta)P(Z|\theta)}{P(Z|Y,\theta^{(i)})P(Y|\theta^{(i)})} \end{aligned} L(θ)L(θ(i))=log(ZP(YZ,θ(i))P(YZ,θ(i))P(YZ,θ)P(Zθ))logP(Yθ(i))ZP(ZY,θ(i))logP(ZY,θ(i))P(YZ,θ)P(Zθ)logP(Yθ(i))=ZP(ZY,θ(i))logP(ZY,θ(i))P(YZ,θ)P(Zθ)ZP(ZY,θ(i))logP(Yθ(i))=ZP(ZY,θ(i))logP(ZY,θ(i))P(Yθ(i))P(YZ,θ)P(Zθ)
上面式子中的 P ( Y ∣ Z , θ ( i ) ) \color{green}P(Y|Z,\theta^{(i)}) P(YZ,θ(i))就是我们之前讨论的D函数,是为了构造期望, 进而应用詹森不等式,具体是怎么来的也讨论过了,这里不再赘述。

令:
B ( θ , θ ( i ) ) = L ( θ ( i ) ) + ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g P ( Y ∣ Z , θ ) P ( Z , θ ) P ( Z ∣ Y , θ ( i ) ) P ( Y ∣ θ ( i ) ) B(\theta,\theta^{(i)}) = L(\theta^{(i)})+ \sum_{Z} P(Z|Y,\theta^{(i)})log\frac{P(Y|Z,\theta)P(Z,\theta)}{P(Z|Y,\theta^{(i)}) P(Y|\theta^{(i)})} B(θ,θ(i))=L(θ(i))+ZP(ZY,θ(i))logP(ZY,θ(i))P(Yθ(i))P(YZ,θ)P(Z,θ)
则有:
L ( θ ) ≥ B ( θ , θ ( i ) ) L(\theta)\ge B(\theta,\theta^{(i)}) L(θ)B(θ,θ(i))
也就是 B ( θ , θ i ) B(\theta,\theta^{i}) B(θ,θi) L ( θ ) L(\theta) L(θ) 的一个下界,又由于:
P ( Y , Z ∣ θ ) = P ( Y ∣ Z , θ ) P ( Z , θ ) = P ( Z ∣ Y , θ ) P ( Y ∣ θ ) P(Y,Z|\theta)=P(Y|Z,\theta)P(Z,\theta)=P(Z|Y,\theta) P(Y|\theta) P(Y,Zθ)=P(YZ,θ)P(Z,θ)=P(ZY,θ)P(Yθ)
θ = θ ( i ) \theta = \theta^{(i)} θ=θ(i) 时等号成立,因为:
B ( θ ( i ) , θ ( i ) ) = L ( θ ( i ) ) + ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g P ( Y ∣ Z , θ ( i ) ) P ( Z , θ ( i ) ) P ( Z ∣ Y , θ ( i ) ) P ( Y ∣ θ ( i ) ) = L ( θ ( i ) ) + ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g 1 = L ( θ ( i ) ) \begin{aligned} B(\theta^{(i)},\theta^{(i)}) &= L(\theta^{(i)})+ \sum_{Z} P(Z|Y,\theta^{(i)})log\frac{P(Y|Z,\theta^{(i)})P(Z,\theta^{(i)})}{P(Z|Y,\theta^{(i)}) P(Y|\theta^{(i)})} \\ &= L(\theta^{(i)}) + \sum_{Z} P(Z|Y,\theta^{(i)})log1 \\&=L(\theta^{(i)}) \end{aligned} B(θ(i),θ(i))=L(θ(i))+ZP(ZY,θ(i))logP(ZY,θ(i))P(Yθ(i))P(YZ,θ(i))P(Z,θ(i))=L(θ(i))+ZP(ZY,θ(i))log1=L(θ(i))
所以,任何可以使 B ( θ , θ ( i ) ) B(\theta,\theta^{(i)}) B(θ,θ(i)) 增大的 θ \theta θ 都可以使 L ( θ ) L(\theta) L(θ) 增大。所以为了使 L ( θ ) L(\theta) L(θ) 尽可能增大,我们选择 θ ( i + 1 ) \theta^{(i+1)} θ(i+1) 使得 B ( θ , θ i ) B(\theta,\theta^{i}) B(θ,θi) 尽可能大:
θ ( i + 1 ) = arg ⁡ max ⁡ θ B ( θ , θ ( i ) ) = L ( θ ( i ) ) + ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g P ( Y ∣ Z , θ ) P ( Z , θ ) P ( Y ∣ Z , θ ( i ) ) P ( Y ∣ θ ( i ) ) = arg ⁡ max ⁡ θ ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g ( P ( Y ∣ Z , θ ) P ( Z , θ ) P ( Z ∣ Y , θ ( i ) ) P ( Y ∣ θ ( i ) ) ) = arg ⁡ max ⁡ θ ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g ( P ( Y ∣ Z , θ ) P ( Z , θ ) ) − arg ⁡ max ⁡ θ ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g ( P ( Z ∣ Y , θ i ) P ( Y ∣ θ ( i ) ) ) = a r g max ⁡ θ ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g ( P ( Y ∣ Z , θ ) P ( Z , θ ) ) = a r g max ⁡ θ ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g ( P ( Y , Z ∣ θ ) ) = a r g max ⁡ θ Q ( θ , θ ( i ) ) \begin{aligned} \theta^{(i+1)} &= \arg \max_{\theta} B(\theta,\theta^{(i)})\\ &= L(\theta^{(i)})+ \sum_{Z} P(Z|Y,\theta^{(i)})log\frac{P(Y|Z,\theta)P(Z,\theta)}{P(Y|Z,\theta^{(i)}) P(Y|\theta^{(i)})} \\&=\arg \max_{\theta}\sum_{Z} P(Z|Y,\theta^{(i)})log(\frac{P(Y|Z,\theta)P(Z,\theta)}{P(Z|Y,\theta^{(i)})P(Y|\theta^{(i)})}) \\ &=\arg \max_{\theta}\sum_{Z} P(Z|Y,\theta^{(i)})log(P(Y|Z,\theta)P(Z,\theta))-\arg \max_{\theta}\sum_{Z} P(Z|Y,\theta^{(i)})log(P(Z|Y,\theta^i)P(Y|\theta^{(i)}))\\ &=arg \max_{\theta}\sum_{Z} P(Z|Y,\theta^{(i)})log(P(Y|Z,\theta)P(Z,\theta))\\ & =arg \max_{\theta}\sum_{Z} P(Z|Y,\theta^{(i)})log(P(Y,Z|\theta))\\ &=arg \max_{\theta}Q(\theta,\theta^{(i)}) \end{aligned} θ(i+1)=argθmaxB(θ,θ(i))=L(θ(i))+ZP(ZY,θ(i))logP(YZ,θ(i))P(Yθ(i))P(YZ,θ)P(Z,θ)=argθmaxZP(ZY,θ(i))log(P(ZY,θ(i))P(Yθ(i))P(YZ,θ)P(Z,θ))=argθmaxZP(ZY,θ(i))log(P(YZ,θ)P(Z,θ))argθmaxZP(ZY,θ(i))log(P(ZY,θi)P(Yθ(i)))=argθmaxZP(ZY,θ(i))log(P(YZ,θ)P(Z,θ))=argθmaxZP(ZY,θ(i))log(P(Y,Zθ))=argθmaxQ(θ,θ(i))
上面式子解释了Q函数的由来,并且完成了EM的一次迭代过程,得到了 θ ( i + 1 ) \theta^{(i+1)} θ(i+1)。上面的推导过程也说明了:EM算法是通过不断求解使得下界 B ( θ , θ i ) B(\theta,\theta^{i}) B(θ,θi) 极大化的参数θ,来近似求解对数似然函数L(θ)极大值的算法。

下图给出EM算法的直观解释。图中上方曲线为 L ( θ ) L(\theta) L(θ),下方曲线为 B ( θ , θ ( i ) ) B(\theta,\theta^{(i)}) B(θ,θ(i)) B ( θ , θ ( i ) ) B(\theta,\theta^{(i)}) B(θ,θ(i))为对数似然函数 L ( θ ) L(\theta) L(θ)的下界。

在这里插入图片描述

通过图片我们总结EM算法的迭代过程如下:

(1) 初始状态:在 θ = θ ( i ) \theta = \theta ^{(i)} θ=θ(i) 时, L ( θ ( i ) ) = B ( θ ( i ) , θ ( i ) ) L(\theta^{(i)})=B(\theta^{(i)},\theta^{(i)}) L(θ(i))=B(θ(i),θ(i))

(2) EM算法的更新过程:寻找 θ ( i + 1 ) ) \theta^{(i+1))} θ(i+1)) 使得 B ( θ , θ ( i ) ) B(\theta,\theta^{(i)}) B(θ,θ(i))极大化。因为 L ( θ ) ≥ B ( θ , θ ( i ) ) L(\theta)\ge B(\theta,\theta^{(i)}) L(θ)B(θ,θ(i)),所以得 B ( θ , θ ( i ) ) B(\theta,\theta^{(i)}) B(θ,θ(i))极大化也使得 L ( θ ) L(\theta) L(θ) 增加。

(3) 根据第二步找到的 θ ( i + 1 ) ) \theta^{(i+1))} θ(i+1)) 重新计算 B ( θ , θ ( i ) ) B(\theta,\theta^{(i)}) B(θ,θ(i))(或者说重新计算Q函数),进行下一次迭代。

上述过程暴露一个问题:对数似然函数不断增大,但EM算法不能保证找到全局最优解。

EM算法的收敛性

我们已经证明了EM算法的合理性,接下来我们来研究一下算法是否收敛。

要证EM算法的收敛性即证:
P ( Y ∣ θ ( i + 1 ) ) ≥ P ( Y ∣ θ ( i ) ) P(Y|\theta^{(i+1)}) \ge P(Y|\theta^{(i)}) P(Yθ(i+1))P(Yθ(i))
同样由:
P ( Y , Z ∣ θ ) = P ( Y ∣ Z , θ ) P ( Z , θ ) = P ( Z ∣ Y , θ ) P ( Y ∣ θ ) P(Y,Z|\theta)=P(Y|Z,\theta)P(Z,\theta)=P(Z|Y,\theta) P(Y|\theta) P(Y,Zθ)=P(YZ,θ)P(Z,θ)=P(ZY,θ)P(Yθ)
可以得到:
P ( Y ∣ θ ) = P ( Z , Y ∣ θ ) P ( Z ∣ Y , θ ) P(Y|\theta) = \frac{P(Z,Y|\theta)}{P(Z|Y,\theta)} P(Yθ)=P(ZY,θ)P(Z,Yθ)
两边同取对数:
l o g P ( Y ∣ θ ) = l o g P ( Z , Y ∣ θ ) − l o g P ( Z ∣ Y , θ ) logP(Y|\theta) = logP(Z,Y|\theta) - logP(Z|Y,\theta) logP(Yθ)=logP(Z,Yθ)logP(ZY,θ)
左右两边同时对 P ( Z ∣ Y , θ ( i ) ) P(Z|Y,\theta^{(i)}) P(ZY,θ(i))求期望,则有
l o g P ( Y ∣ θ ) = ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g P ( Y ∣ θ ) = ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g P ( Z , Y ∣ θ ) − ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g P ( Z ∣ Y , θ ) \begin{aligned} logP(Y|\theta) &= \sum_ZP(Z|Y,\theta^{(i)})logP(Y|\theta) \\ &= \sum_ZP(Z|Y,\theta^{(i)})logP(Z,Y|\theta) - \sum_ZP(Z|Y,\theta^{(i)})logP(Z|Y,\theta) \\ \end{aligned} logP(Yθ)=ZP(ZY,θ(i))logP(Yθ)=ZP(ZY,θ(i))logP(Z,Yθ)ZP(ZY,θ(i))logP(ZY,θ)
其中, ∑ Z P ( Z ∣ Y , θ ( i ) ) = 1 \sum_ZP(Z|Y,\theta^{(i)})=1 ZP(ZY,θ(i))=1, l o g P ( Y ∣ θ ) logP(Y|\theta) logP(Yθ) 是与Z无关的变量。

根据Q函数的定义:
Q ( θ , θ ( i ) ) = ∑ Z l o g P ( Y , Z ∣ θ ) P ( Z ∣ Y , θ ( i ) ) Q(\theta,\theta^{(i)}) = \sum_Z logP(Y,Z|\theta)P(Z|Y,\theta^{(i)}) Q(θ,θ(i))=ZlogP(Y,Zθ)P(ZY,θ(i))
以及这里我们令:
H ( θ , θ ( i ) ) = ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g P ( Z ∣ Y , θ ) H(\theta,\theta^{(i)}) = \sum_ZP(Z|Y,\theta^{(i)})logP(Z|Y,\theta) H(θ,θ(i))=ZP(ZY,θ(i))logP(ZY,θ)
所以:
l o g P ( Y ∣ θ ) = ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g P ( Z , Y ∣ θ ) − ∑ Z P ( Z ∣ Y , θ ( i ) ) l o g P ( Z ∣ Y , θ ) = Q ( θ , θ ( i ) ) − H ( θ , θ ( i ) ) \begin{aligned} logP(Y|\theta) &= \sum_ZP(Z|Y,\theta^{(i)})logP(Z,Y|\theta) - \sum_ZP(Z|Y,\theta^{(i)})logP(Z|Y,\theta) \\ &= Q(\theta,\theta^{(i)}) - H(\theta,\theta^{(i)}) \end{aligned} logP(Yθ)=ZP(ZY,θ(i))logP(Z,Yθ)ZP(ZY,θ(i))logP(ZY,θ)=Q(θ,θ(i))H(θ,θ(i))
进而有:
l o g P ( Y , θ ( i + 1 ) ) − l o g P ( Y , θ ( i ) ) = Q ( θ ( i + 1 ) , θ ( i ) − H ( θ ( i + 1 ) , θ ( i ) ) − ( Q ( θ ( i ) , θ ( i ) ) − H ( θ ( i ) , θ ( i ) ) ) = Q ( θ ( i + 1 ) , θ ( i ) ) − Q ( θ ( i ) , θ ( i ) ) − ( H ( θ ( i + 1 ) , θ ( i ) ) − H ( θ ( i ) , θ ( i ) ) ) \begin{aligned} & \quad logP(Y,\theta^{(i+1)})-logP(Y,\theta^{(i)}) \\ &= Q(\theta^{(i+1)},\theta^{(i)}-H(\theta^{(i+1)},\theta^{(i)}) - (Q(\theta^{(i)},\theta^{(i)})-H(\theta^{(i)},\theta^{(i)}))\\ &= Q(\theta^{(i+1)},\theta^{(i)})- Q(\theta^{(i)},\theta^{(i)}) -( H(\theta^{(i+1)},\theta^{(i)}) - H(\theta^{(i)},\theta^{(i)})) \end{aligned} logP(Y,θ(i+1))logP(Y,θ(i))=Q(θ(i+1),θ(i)H(θ(i+1),θ(i))(Q(θ(i),θ(i))H(θ(i),θ(i)))=Q(θ(i+1),θ(i))Q(θ(i),θ(i))(H(θ(i+1),θ(i))H(θ(i),θ(i)))
因为 θ i + 1 \theta^{i+1} θi+1 使得 Q ( θ , θ ( i ) ) Q(\theta,\theta^{(i)}) Q(θ,θ(i)) 增加,所以
Q ( θ ( i + 1 ) , θ ( i ) ) − Q ( θ ( i ) , θ ( i ) ) ≥ 0 Q(\theta^{(i+1)},\theta^{(i)})- Q(\theta^{(i)},\theta^{(i)}) \ge 0 Q(θ(i+1),θ(i))Q(θ(i),θ(i))0
所以,我们的目标是证明 H ( θ ( i + 1 ) , θ ( i ) ) − H ( θ ( i ) , θ ( i ) ) ≤ 0 H(\theta^{(i+1)},\theta^{(i)}) - H(\theta^{(i)},\theta^{(i)}) \le 0 H(θ(i+1),θ(i))H(θ(i),θ(i))0 ,证明如下:
H ( θ ( i + 1 ) , θ ( i ) ) − H ( θ ( i ) , θ ( i ) ) = ∑ Z ( l o g ( P ( Z ∣ Y , θ ( i + 1 ) ) P ( Z ∣ Y , θ ( i ) ) ) ) P ( Z ∣ Y , θ ( i ) ) ≤ l o g ( ∑ Z P ( Z ∣ Y , θ ( i + 1 ) ) P ( Z ∣ Y , θ ( i ) ) P ( Z ∣ Y , θ ( i ) ) ) = l o g P ( Z ∣ Y , θ ( i + 1 ) ) = l o g 1 = 0 \begin{aligned} & \quad H(\theta^{(i+1)},\theta^{(i)}) - H(\theta^{(i)},\theta^{(i)}) \\&=\sum_{Z}\bigg(log(\frac{P(Z|Y,\theta^{(i+1)})}{P(Z|Y,\theta^{(i)})}) \bigg)P(Z|Y,\theta^{(i)}) \\ & \le log\bigg(\sum_{Z}\frac{P(Z|Y,\theta^{(i+1)})}{P(Z|Y,\theta^{(i)})}P(Z|Y,\theta^{(i)}) \bigg)\\ &=logP(Z|Y,\theta^{(i+1)})=log1=0 \end{aligned} H(θ(i+1),θ(i))H(θ(i),θ(i))=Z(log(P(ZY,θ(i))P(ZY,θ(i+1))))P(ZY,θ(i))log(ZP(ZY,θ(i))P(ZY,θ(i+1))P(ZY,θ(i)))=logP(ZY,θ(i+1))=log1=0
不等号由詹森不等式得到。所以:
l o g P ( Y , θ ( i + 1 ) ) − l o g P ( Y , θ ( i ) ) ≥ 0 P ( Y , θ ( i + 1 ) ) − P ( Y , θ ( i ) ) ≥ 0 P ( Y , θ ( i + 1 ) ) ≥ P ( Y , θ ( i ) ) logP(Y,\theta^{(i+1)})-logP(Y,\theta^{(i)}) \ge 0 \\ P(Y,\theta^{(i+1)})-P(Y,\theta^{(i)}) \ge 0 \\ P(Y,\theta^{(i+1)})\ge P(Y,\theta^{(i)}) logP(Y,θ(i+1))logP(Y,θ(i))0P(Y,θ(i+1))P(Y,θ(i))0P(Y,θ(i+1))P(Y,θ(i))
证明了EM算法的收敛性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值