(EM算法)The EM Algorithm

EM是我一直想深入学习的算法之一,第一次听说是在NLP课中的HMM那一节,为了解决HMM的参数估计问题,使用了EM算法。在之后的MT中的词对齐中也用到了。在Mitchell的书中也提到EM可以用于贝叶斯网络中。

下面主要介绍EM的整个推导过程。

1. Jensen不等式

      回顾优化理论中的一些概念。设f是定义域为实数的函数,如果对于所有的实数x,clip_image002,那么f是凸函数。当x是向量时,如果其hessian矩阵H是半正定的(clip_image004),那么f是凸函数。如果clip_image006或者clip_image008,那么称f是严格凸函数。

      Jensen不等式表述如下:

      如果f是凸函数,X是随机变量,那么

      clip_image010

      特别地,如果f是严格凸函数,那么clip_image012当且仅当clip_image014,也就是说X是常量。

      这里我们将clip_image016简写为clip_image018

      如果用图表示会很清晰:

      clip_image019

      图中,实线f是凸函数,X是随机变量,有0.5的概率是a,有0.5的概率是b。(就像掷硬币一样)。X的期望值就是a和b的中值了,图中可以看到clip_image010[1]成立。

      当f是(严格)凹函数当且仅当-f是(严格)凸函数。

      Jensen不等式应用于凹函数时,不等号方向反向,也就是clip_image021

2. EM算法

      给定的训练样本是clip_image023,样例间独立,我们想找到每个样例隐含的类别z,能使得p(x,z)最大。p(x,z)的最大似然估计如下:

      clip_image024

      第一步是对极大似然取对数,第二步是对每个样例的每个可能类别z求联合分布概率和。但是直接求clip_image026一般比较困难,因为有隐藏变量z存在,但是一般确定了z后,求解就容易了。

      EM是一种解决存在隐含变量优化问题的有效方法。竟然不能直接最大化clip_image028,我们可以不断地建立clip_image030的下界(E步),然后优化下界(M步)。这句话比较抽象,看下面的。

      对于每一个样例i,让clip_image032表示该样例隐含变量z的某种分布,clip_image032[1]满足的条件是clip_image034。(如果z是连续性的,那么clip_image032[2]是概率密度函数,需要将求和符号换做积分符号)。比如要将班上学生聚类,假设隐藏变量z是身高,那么就是连续的高斯分布。如果按照隐藏变量是男女,那么就是伯努利分布了。

可以由前面阐述的内容得到下面的公式:

      clip_image035

      (1)到(2)比较直接,就是分子分母同乘以一个相等的函数。(2)到(3)利用了Jensen不等式,考虑到clip_image037是凹函数(二阶导数小于0),而且

      clip_image038

      就是clip_image039的期望(回想期望公式中的Lazy Statistician规则)

      设Y是随机变量X的函数clip_image041(g是连续函数),那么

      (1) X是离散型随机变量,它的分布律为clip_image043,k=1,2,…。若clip_image045绝对收敛,则有

      clip_image047

      (2) X是连续型随机变量,它的概率密度为clip_image049,若clip_image051绝对收敛,则有

      clip_image053

      对应于上述问题,Y是clip_image039[1],X是clip_image055clip_image057clip_image059,g是clip_image055[1]clip_image039[2]的映射。这样解释了式子(2)中的期望,再根据凹函数时的Jensen不等式:

      clip_image060

可以得到(3)。

      这个过程可以看作是对clip_image028[1]求了下界。对于clip_image032[3]的选择,有多种可能,那种更好的?假设clip_image026[1]已经给定,那么clip_image028[2]的值就决定于clip_image057[1]clip_image062了。我们可以通过调整这两个概率使下界不断上升,以逼近clip_image028[3]的真实值,那么什么时候算是调整好了呢?当不等式变成等式时,说明我们调整后的概率能够等价于clip_image028[4]了。按照这个思路,我们要找到等式成立的条件。根据Jensen不等式,要想让等式成立,需要让随机变量变成常数值,这里得到:

      clip_image063

      c为常数,不依赖于clip_image065。对此式子做进一步推导,我们知道clip_image067,那么也就有clip_image069,(多个等式分子分母相加不变,这个认为每个样例的两个概率比值都是c),那么有下式:

      clip_image070

      至此,我们推出了在固定其他参数clip_image026[2]后,clip_image072的计算公式就是后验概率,解决了clip_image072[1]如何选择的问题。这一步就是E步,建立clip_image028[5]的下界。接下来的M步,就是在给定clip_image072[2]后,调整clip_image026[3],去极大化clip_image028[6]的下界(在固定clip_image072[3]后,下界还可以调整的更大)。那么一般的EM算法的步骤如下:

循环重复直到收敛 {

      (E步)对于每一个i,计算

                  clip_image074

      (M步)计算

                  clip_image075

      那么究竟怎么确保EM收敛?假定clip_image077clip_image079是EM第t次和t+1次迭代后的结果。如果我们证明了clip_image081,也就是说极大似然估计单调增加,那么最终我们会到达最大似然估计的最大值。下面来证明,选定clip_image077[1]后,我们得到E步

      clip_image083

      这一步保证了在给定clip_image077[2]时,Jensen不等式中的等式成立,也就是

      clip_image084

      然后进行M步,固定clip_image086,并将clip_image088视作变量,对上面的clip_image090求导后,得到clip_image092,这样经过一些推导会有以下式子成立:

      clip_image093

      解释第(4)步,得到clip_image092[1]时,只是最大化clip_image090[1],也就是clip_image095的下界,而没有使等式成立,等式成立只有是在固定clip_image026[4],并按E步得到clip_image097时才能成立。

      况且根据我们前面得到的下式,对于所有的clip_image097[1]clip_image026[5]都成立

      clip_image098

      第(5)步利用了M步的定义,M步就是将clip_image088[1]调整到clip_image100,使得下界最大化。因此(5)成立,(6)是之前的等式结果。

      这样就证明了clip_image102会单调增加。一种收敛方法是clip_image102[1]不再变化,还有一种就是变化幅度很小。

      再次解释一下(4)、(5)、(6)。首先(4)对所有的参数都满足,而其等式成立条件只是在固定clip_image026[6],并调整好Q时成立,而第(4)步只是固定Q,调整clip_image026[7],不能保证等式一定成立。(4)到(5)就是M步的定义,(5)到(6)是前面E步所保证等式成立条件。也就是说E步会将下界拉到与clip_image102[2]一个特定值(这里clip_image088[2])一样的高度,而此时发现下界仍然可以上升,因此经过M步后,下界又被拉升,但达不到与clip_image102[3]另外一个特定值一样的高度,之后E步又将下界拉到与这个特定值一样的高度,重复下去,直到最大值。

      如果我们定义

      clip_image103

      从前面的推导中我们知道clip_image105,EM可以看作是J的坐标上升法,E步固定clip_image026[8],优化clip_image107,M步固定clip_image107[1]优化clip_image026[9]

3. 重新审视混合高斯模型

      我们已经知道了EM的精髓和推导过程,再次审视一下混合高斯模型。之前提到的混合高斯模型的参数clip_image109clip_image111计算公式都是根据很多假定得出的,有些没有说明来由。为了简单,这里在M步只给出clip_image113clip_image115的推导方法。

E步很简单,按照一般EM公式得到:

      clip_image116

      简单解释就是每个样例i的隐含类别clip_image055[2]为j的概率可以通过后验概率计算得到。

      在M步中,我们需要在固定clip_image072[4]后最大化最大似然估计,也就是

      clip_image118

      这是将clip_image120的k种情况展开后的样子,未知参数clip_image122clip_image124

      固定clip_image126clip_image128,对clip_image130求导得

      clip_image131

      等于0时,得到

      clip_image132

      这就是我们之前模型中的clip_image115[1]的更新公式。

      然后推导clip_image126[1]的更新公式。看之前得到的

      clip_image133

      在clip_image113[1]clip_image115[2]确定后,分子上面的一串都是常数了,实际上需要优化的公式是:

      clip_image134

      需要知道的是,clip_image126[2]还需要满足一定的约束条件就是clip_image136

      这个优化问题我们很熟悉了,直接构造拉格朗日乘子。

      clip_image137

      还有一点就是clip_image139,但这一点会在得到的公式里自动满足。

      求导得,

      clip_image141

      等于0,得到

      clip_image142

      也就是说clip_image143再次使用clip_image136[1],得到

      clip_image144

      这样就神奇地得到了clip_image146

      那么就顺势得到M步中clip_image126[3]的更新公式:

      clip_image147

      clip_image111[1]的推导也类似,不过稍微复杂一些,毕竟是矩阵。结果在之前的混合高斯模型中已经给出。

4. 总结

      如果将样本看作观察值,潜在类别看作是隐藏变量,那么聚类问题也就是参数估计问题,只不过聚类问题中参数分为隐含类别变量和其他参数,这犹如在x-y坐标系中找一个曲线的极值,然而曲线函数不能直接求导,因此什么梯度下降方法就不适用了。但固定一个变量后,另外一个可以通过求导得到,因此可以使用坐标上升法,一次固定一个变量,对另外的求极值,最后逐步逼近极值。对应到EM上,E步估计隐含变量,M步估计其他参数,交替将极值推向最大。EM中还有“硬”指定和“软”指定的概念,“软”指定看似更为合理,但计算量要大,“硬”指定在某些场合如K-means中更为实用(要是保持一个样本点到其他所有中心的概率,就会很麻烦)。

      另外,EM的收敛性证明方法确实很牛,能够利用log的凹函数性质,还能够想到利用创造下界,拉平函数下界,优化下界的方法来逐步逼近极大值。而且每一步迭代都能保证是单调的。最重要的是证明的数学公式非常精妙,硬是分子分母都乘以z的概率变成期望来套上Jensen不等式,前人都是怎么想到的。

      在Mitchell的Machine Learning书中也举了一个EM应用的例子,明白地说就是将班上学生的身高都放在一起,要求聚成两个类。这些身高可以看作是男生身高的高斯分布和女生身高的高斯分布组成。因此变成了如何估计每个样例是男生还是女生,然后在确定男女生情况下,如何估计均值和方差,里面也给出了公式,有兴趣可以参考。

https://zhuanlan.zhihu.com/p/26614750

https://zhuanlan.zhihu.com/p/78311644

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
刚找到的书,第二版的.. 【原书作者】: Geoffrey J. McLachlan, Thriyambakam Krishnan 【ISBN 】: ISBN-10: 0471201707 / ISBN-13: 978-0471201700 【页数 】:360 【开本 】 : 【出版社】 :Wiley-Interscience 【出版日期】:March 14, 2008 【文件格式】:DJVU(请去网上下载windjview阅读 【摘要或目录】: Review "...should be comprehensible to graduates with statistics as their major subject." (Quarterly of Applied Mathematics, Vol. LIX, No. 3, September 2001) --This text refers to the Hardcover edition. Book Description The EM Algorithm and Extensions remains the only single source to offer a complete and unified treatment of the theory, methodology, and applications of the EM algorithm. The highly applied area of statistics here outlined involves applications in regression, medical imaging, finite mixture analysis, robust statistical modeling, survival analysis, and repeated-measures designs, among other areas. The text includes newly added and updated results on convergence, and new discussion of categorical data, numerical differentiation, and variants of the EM algorithm. It also explores the relationship between the EM algorithm and the Gibbs sampler and Markov Chain Monte Carlo methods. About Authors Geoffrey J. McLachlan, PhD, DSc, is Professor of Statistics in the Department of Mathematics at The University of Queensland, Australia. A Fellow of the American Statistical Association and the Australian Mathematical Society, he has published extensively on his research interests, which include cluster and discriminant analyses, image analysis, machine learning, neural networks, and pattern recognition. Dr. McLachlan is the author or coauthor of Analyzing Microarray Gene Expression Data, Finite Mixture Models, and Discriminant Analysis and Statistical Pattern Recognition, all published by Wiley. Thriyambakam Krishnan, PhD, is Chief Statistical Architect, SYSTAT Software at Cranes Software International Limited in Bangalore, India. Dr. Krishnan has over forty-five years of research, teaching, consulting, and software development experience at the Indian Statistical Institute (ISI). His research interests include biostatistics, image analysis, pattern recognition, psychometry, and the EM algorithm. 目录 Preface to the Second Edition. Preface to the First Edition. List of Examples. 1. General Introduction. 1.1 Introduction. 1.2 Maximum Likelihood Estimation. 1.3 Newton-Type Methods. 1.4 Introductory Examples. 1.5 Formulation of the EM Algorithm. 1.6 EM Algorithm for MAP and MPL Estimation. 1.7 Brief Summary of the Properties of EM Algorithm. 1.8 History of the EM Algorithm. 1.9 Overview of the Book. 1.10 Notations. 2. Examples of the EM Algorithm. 2.1 Introduction. 2.2 Multivariate Data with Missing Values. 2.3 Least Square with the Missing Data. 2.4 Example 2.4: Multinomial with Complex Cell Structure. 2.5 Example 2.5: Analysis of PET and SPECT Data. 2.6 Example 2.6: Multivariate t-Distribution (Known D.F.). 2.7 Finite Normal Mixtures. 2.8 Example 2.9: Grouped and Truncated Data. 2.9 Example 2.10: A Hidden Markov AR(1) Model. 3. Basic Theory of the EM Algorithm. 3.1 Introduction. 3.2 Monotonicity of a Generalized EM Algorithm. 3.3 Monotonicity of a Generalized EM Algorithm. 3.4 Convergence of an EM Sequence to a Stationary Value. 3.5 Convergence of an EM Sequence of Iterates. 3.6 Examples of Nontypical Behavior of an EM (GEM) Sequence. 3.7 Score Statistic. 3.8 Missing Information. 3.9 Rate of Convergence of the EM Algorithm. 4. Standard Errors and Speeding up Convergence. 4.1 Introduction. 4.2 Observed Information Matrix. 4.3 Approximations to Observed Information Matrix: i.i.d. Case. 4.4 Observed Information Matrix for Grouped Data. 4.5 Supplemented EM Algorithm. 4.6 Bookstrap Approach to Standard Error Approximation. 4.7 Baker’s, Louis’, and Oakes’ Methods for Standard Error Computation. 4.8 Acceleration of the EM Algorithm via Aitken’s Method. 4.9 An Aitken Acceleration-Based Stopping Criterion. 4.10 conjugate Gradient Acceleration of EM Algorithm. 4.11 Hybrid Methods for Finding the MLE. 4.12 A GEM Algorithm Based on One Newton-Raphson Algorithm. 4.13 EM gradient Algorithm. 4.14 A Quasi-Newton Acceleration of the EM Algorithm. 4.15 Ikeda Acceleration. 5. Extension of the EM Algorithm. 5.1 Introduction. 5.2 ECM Algorithm. 5.3 Multicycle ECM Algorithm. 5.4 Example 5.2: Normal Mixtures with Equal Correlations. 5.5 Example 5.3: Mixture Models for Survival Data. 5.6 Example 5.4: Contingency Tables with Incomplete Data. 5.7 ECME Algorithm. 5.8 Example 5.5: MLE of t-Distribution with the Unknown D.F. 5.9 Example 5.6: Variance Components. 5.10 Linear Mixed Models. 5.11 Example 5.8: Factor Analysis. 5.12 Efficient Data Augmentation. 5.13 Alternating ECM Algorithm. 5.14 Example 5.9: Mixtures of Factor Analyzers. 5.15 Parameter-Expanded EM (PX-EM) Algorithm. 5.16 EMS Algorithm. 5.17 One-Step-Late Algorithm. 5.18 Variance Estimation for Penalized EM and OSL Algorithms. 5.19 Incremental EM. 5.20 Linear Inverse problems. 6. Monte Carlo Versions of the EM Algorithm. 6.1 Introduction. 6.2 Monte Carlo Techniques. 6.3 Monte Carlo EM. 6.4 Data Augmentation. 6.5 Bayesian EM. 6.6 I.I.D. Monte Carlo Algorithm. 6.7 Markov Chain Monte Carlo Algorithms. 6.8 Gibbs Sampling. 6.9 Examples of MCMC Algorithms. 6.10 Relationship of EM to Gibbs Sampling. 6.11 Data Augmentation and Gibbs Sampling. 6.12 Empirical Bayes and EM. 6.13 Multiple Imputation. 6.14 Missing-Data Mechanism, Ignorability, and EM Algorithm. 7. Some Generalization of the EM Algorithm. 7.1 Introduction. 7.2 Estimating Equations and Estimating Functions. 7.3 Quasi-Score and the Projection-Solution Algorithm. 7.4 Expectation-Solution (ES) Algorithm. 7.5 Other Generalization. 7.6 Variational Bayesian EM Algorithm. 7.7 MM Algorithm. 7.8 Lower Bound Maximization. 7.9 Interval EM Algorithm. 7.10 Competing Methods and Some Comparisons with EM. 7.11 The Delta Algorithm. 7.12 Image Space Reconstruction Algorithm. 8. Further Applications of the EM Algorithm. 8.1 Introduction. 8.2 Hidden Markov Models. 8.3 AIDS Epidemiology. 8.4 Neural Networks. 8.5 Data Mining. 8.6 Bioinformatics. References. Author Index. Subject Index
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值