EM(Expectation-Maximum)算法

EM算法

简介

EM算法的核心分为两步

  1. E步(Expection-Step)
  2. M步(Maximization-Step)

因为在最大化过程中存在两个参量 r , θ r,\theta r,θ,其中若知道 r r r,则知道 θ \theta θ;若知道 θ \theta θ,则知道 r r r。且两个量未存在明显的关系,但又互相依存可以采用EM算法

其中主要思想为:

  1. 首先随机初始化参数 r r r
  2. 然后求的在参数 r r r下按照极大似然估计求得参数 θ \theta θ
  3. 然后根据参数 θ \theta θ按照极大似然估计求得参数 r r r
  4. 循环至收敛

算法示例

如下图所示存在A,B两种硬币,其中抛出正反面的概率未知,其中H表示正面,F表示反面

EM(Expectation-Maximum)算法_第1张图片

根据统计可得

EM(Expectation-Maximum)算法_第2张图片

可得
P ( H ∣ X = A ) = 24 24 + 6 = 0.8 P ( H ∣ X = B ) = 9 9 + 11 = 0.45 P(H|X=A)=\frac{24}{24+6}=0.8\\ P(H|X=B)=\frac{9}{9+11}=0.45 P(HX=A)=24+624=0.8P(HX=B)=9+119=0.45
若更改条件,不知道此时抛出是哪一枚硬币,只知道抛出的结果,即

EM(Expectation-Maximum)算法_第3张图片

首先初始化,设
P ( H ∣ X = A ) = 0.6 P ( H ∣ X = B ) = 0.5 P(H|X=A)=0.6\\ P(H|X=B)=0.5 P(HX=A)=0.6P(HX=B)=0.5
若当抛出的第一枚硬币为A时

此时的出现该情况的概率为 P 1 ( A ) = 0. 6 5 ∗ ( 1 − 0.6 ) 5 = 0.0007962624 P_1(A)=0.6^5*(1-0.6)^5=0.0007962624 P1(A)=0.65(10.6)5=0.0007962624

若当抛出的第一枚硬币为B时

此时的出现该情况的概率为 P 1 ( B ) = 0. 5 5 ∗ ( 1 − 0.5 ) 5 = 0.0009765625 P_1(B)=0.5^5*(1-0.5)^5=0.0009765625 P1(B)=0.55(10.5)5=0.0009765625

其中
P 1 ( A ) = P 1 ( A ) P 1 ( A ) + P 1 ( B ) ≈ 0.45 P 1 ( B ) = P 1 ( B ) P 1 ( A ) + P 1 ( B ) ≈ 0.55 P^1(A)=\frac{P_1(A)}{P_1(A)+P_1(B)}\approx0.45\\ P^1(B)=\frac{P_1(B)}{P_1(A)+P_1(B)}\approx0.55 P1(A)=P1(A)+P1(B)P1(A)0.45P1(B)=P1(A)+P1(B)P1(B)0.55
同理可得
P 2 ( A ) ≈ 0.80 , P 2 ( B ) ≈ 0.20 P 3 ( A ) ≈ 0.73 , P 3 ( B ) ≈ 0.27 P 4 ( A ) ≈ 0.35 , P 4 ( B ) ≈ 0.65 P 5 ( A ) ≈ 0.65 , P 5 ( B ) ≈ 0.35 P^2(A)\approx0.80,P^2(B)\approx0.20\\ P^3(A)\approx0.73,P^3(B)\approx0.27\\ P^4(A)\approx0.35,P^4(B)\approx0.65\\ P^5(A)\approx0.65,P^5(B)\approx0.35 P2(A)0.80,P2(B)0.20P3(A)0.73,P3(B)0.27P4(A)0.35,P4(B)0.65P5(A)0.65,P5(B)0.35
计算其数学期望
E 1 ( H ∣ X = A ) = 0.45 ∗ 5 = 2.2 E 1 ( T ∣ X = A ) = 0.45 ∗ 5 = 2.2 E 1 ( H ∣ X = B ) = 0.55 ∗ 5 = 2.75 E 1 ( T ∣ X = B ) = 0.55 ∗ 5 = 2.75 E 2 ( H ∣ X = A ) = 0.80 ∗ 9 = 7.2 E 2 ( T ∣ X = A ) = 0.45 ∗ 5 = 2.2 E 2 ( H ∣ X = B ) = 0.20 ∗ 9 = 1.8 E 2 ( T ∣ X = B ) = 0.20 ∗ 1 = 0.2 E 3 ( H ∣ X = A ) = 0.73 ∗ 8 = 5.8 E 3 ( T ∣ X = A ) = 0.73 ∗ 2 = 1.46 E 3 ( H ∣ X = B ) = 0.27 ∗ 8 = 2.16 E 3 ( T ∣ X = B ) = 0.27 ∗ 2 = 0.54 E 4 ( H ∣ X = A ) = 0.35 ∗ 4 = 1.4 E 4 ( T ∣ X = A ) = 0.35 ∗ 6 = 2.1 E 4 ( H ∣ X = B ) = 0.65 ∗ 4 = 2.6 E 4 ( T ∣ X = B ) = 0.65 ∗ 6 = 3.9 E 5 ( H ∣ X = A ) = 0.65 ∗ 7 = 4.55 E 5 ( T ∣ X = A ) = 0.65 ∗ 3 = 1.95 E 5 ( H ∣ X = B ) = 0.35 ∗ 7 = 2.45 E 5 ( T ∣ X = B ) = 0.35 ∗ 3 = 1.05 \begin{aligned} &E_1(H|X=A)=0.45*5=2.2\\ &E_1(T|X=A)=0.45*5=2.2\\ &E_1(H|X=B)=0.55*5=2.75\\ &E_1(T|X=B)=0.55*5=2.75\\ &E_2(H|X=A)=0.80*9=7.2\\ &E_2(T|X=A)=0.45*5=2.2\\ &E_2(H|X=B)=0.20*9=1.8\\ &E_2(T|X=B)=0.20*1=0.2\\ &E_3(H|X=A)=0.73*8=5.8\\ &E_3(T|X=A)=0.73*2=1.46\\ &E_3(H|X=B)=0.27*8=2.16\\ &E_3(T|X=B)=0.27*2=0.54\\ &E_4(H|X=A)=0.35*4=1.4\\ &E_4(T|X=A)=0.35*6=2.1\\ &E_4(H|X=B)=0.65*4=2.6\\ &E_4(T|X=B)=0.65*6=3.9\\ &E_5(H|X=A)=0.65*7=4.55\\ &E_5(T|X=A)=0.65*3=1.95\\ &E_5(H|X=B)=0.35*7=2.45\\ &E_5(T|X=B)=0.35*3=1.05\\ \end{aligned} E1(HX=A)=0.455=2.2E1(TX=A)=0.455=2.2E1(HX=B)=0.555=2.75E1(TX=B)=0.555=2.75E2(HX=A)=0.809=7.2E2(TX=A)=0.455=2.2E2(HX=B)=0.209=1.8E2(TX=B)=0.201=0.2E3(HX=A)=0.738=5.8E3(TX=A)=0.732=1.46E3(HX=B)=0.278=2.16E3(TX=B)=0.272=0.54E4(HX=A)=0.354=1.4E4(TX=A)=0.356=2.1E4(HX=B)=0.654=2.6E4(TX=B)=0.656=3.9E5(HX=A)=0.657=4.55E5(TX=A)=0.653=1.95E5(HX=B)=0.357=2.45E5(TX=B)=0.353=1.05
并计算其总共的期望
E ( H ∣ X = A ) = ∑ i = 1 5 E i ( H ∣ X = A ) ≈ 21.3 E ( H ∣ X = A ) = ∑ i = 1 5 E i ( T ∣ X = A ) ≈ 8.6 E ( H ∣ X = B ) = ∑ i = 1 5 E i ( H ∣ X = B ) ≈ 11.7 E ( H ∣ X = B ) = ∑ i = 1 5 E i ( T ∣ X = B ) ≈ 8.4 E(H|X=A)=\sum_{i=1}^5E_i(H|X=A)\approx21.3\\ E(H|X=A)=\sum_{i=1}^5E_i(T|X=A)\approx8.6\\ E(H|X=B)=\sum_{i=1}^5E_i(H|X=B)\approx11.7\\ E(H|X=B)=\sum_{i=1}^5E_i(T|X=B)\approx8.4\\ E(HX=A)=i=15Ei(HX=A)21.3E(HX=A)=i=15Ei(TX=A)8.6E(HX=B)=i=15Ei(HX=B)11.7E(HX=B)=i=15Ei(TX=B)8.4

可得
P ( H ∣ X = A ) = 21.3 21.3 + 8.6 = 0.71 P ( H ∣ X = B ) = 11.7 11.7 + 8.4 = 0.58 P(H|X=A)=\frac{21.3}{21.3+8.6}=0.71\\ P(H|X=B)=\frac{11.7}{11.7+8.4}=0.58 P(HX=A)=21.3+8.621.3=0.71P(HX=B)=11.7+8.411.7=0.58
由此循环直至收敛

EM(Expectation-Maximum)算法_第4张图片

得到最终
P ( H ∣ X = A ) = 0.80 P ( H ∣ X = B ) = 0.58 P(H|X=A)=0.80\\ P(H|X=B)=0.58 P(HX=A)=0.80P(HX=B)=0.58

你可能感兴趣的:(机器学习,算法,机器学习,概率论)