EM the algorithm has many applications:
The most extensive is the GMM mixed Gaussian model, clustering, hmm and so On.
The EM algorithm
Gaussian mixture model (mixtures of GAUSSIANS) and EM algorithm
EM algorithm
General steps to find the maximum likelihood function estimate:
(1) write out the likelihood function;
(2) the likelihood function takes the logarithm, and organizes;
(3) the derivative number is 0, and the likelihood equation is Obtained.
(4) solving the likelihood equation, the obtained parameter is the Request.
Desired maximization Algorithm (em algorithm):
Advantages:
1, Simple and stable;
2, through the E-step and M-step to maximize the desired, is a self-convergent classification algorithm, neither need to set the category in advance or the data to see the 22 comparison merge and other Operations.
Disadvantages:
1, the iteration speed is slow, many times;
2, sensitive to the initialization;
3, when the function to be optimized is not a convex function, it is easy to get into the local optimal;
4, em may converge to the boundary of the parameter space.
#################### #R语言: Given a set of data set parameters ########################
# # # #EM算法在高斯混合模型GMM (Gaussian Mixture Model) has a very important purpose.
# # #简单来讲GMM就是一些高斯分布的组合. If we know the category of the observed data,
# # #则可以根据ML来估计出GMM的参数. conversely, for a bunch of data without category information, if
# # # #我们已知GMM的参数, It's easy to classify them into different classes with a Bayesian formula;
# # #的问题是我们即不知道GMM参数, and do not know the category of observational Data. The one-dimensional data generated below is # # #例,
# # #我们希望找到这两个高斯分布的参数, and classify the data at the same time.
# Set Simulation Parameters
If (FALSE) {
MIU1 <-3
MIU2 <--2
SIGMA1 <-1
Sigma2 <-2
Alpha1 <-0.4
ALPHA2 <-0.6
# Two samples of Gaussian distributions are generated
N <-5000
X <-rep (0,n)
N1 <-floor (n*alpha1)
N2 <-n-n1
x[1:n1] <-rnorm (n1) *sigma1 + miu1
x[(n1+1): n] <-rnorm (n2) *sigma2 + miu2
hist (x,freq=f)
Lines (density (x), col= ' Red ')
# # #下面用EM算法来估计GMM的参数.
}
X <-c ( -67,-48,6,8,14,16,23,24,28,29,41,49,56,60,75)
# Set the initial value
N <-15
M <-2
Miu <-runif (M)
Sigma <-runif (M)
Alpha <-c (0.5,0.5)
Prob <-matrix (rep (0,n*m), Ncol=m)
For (step 1:10) {
# e Step
For (j in 1:m) {
Prob[,j]<-sapply (x,dnorm,miu[j],sigma[j])
}
Sumprob <-rowsums (prob)
Prob<-prob/sumprob
# # #做NAN处理
For (i in 1:n)
For (j in 1:m) {
{
If (is.nan (prob[i,j])) {prob[i,j] <-0}
}
}
Oldmiu <-miu
Oldsigma <-sigma
Oldalpha <-alpha
# m Step
For (j in 1:m) {
P1 <-sum (prob[, J])
P2 <-sum (prob[, j]*x)
miu[j] <-P2/P1
alpha[j] <-p1/n
P3 <-sum (prob[, j]* (x-miu[j]) ^2)
sigma[j] <-sqrt (p3/p1)
}
# change
Epsilo <-1e-3
If (sum (abs (miu-oldmiu)) <epsilo && sum (abs (sigma-oldsigma)) <epsilo && sum (abs (alpha-oldalpha) ) <epsilo) Break
Cat (' Step ', step, ' Miu ', miu, ' sigma ', sigma, ' alpha ', alpha, ' \ n ')
}
# # #得出结果
Step 1 Miu 6.822826 17.40323 Sigma 0.9985392 5.880087 Alpha 0.08455481 0.3154452
Step 2 Miu 6.972619 22.93183 Sigma 0.9996251 38.57418 Alpha 0.1252252 0.8747748
#####
# # # #GMM models are often used for model-based clustering, and each Gaussian distribution in GMM can represent a class of data
# # #整个数据就是多个高斯分布的混合. The Mclust function in the Mclust package in R can be used for the base
# # #于GMM的聚类分析. The following is a graph of the cluster results generated with the most commonly used iris dataset as an example:
Library (mclust)
MC <-mclust (iris[,1:4], 3)
Plot (mc, data=iris[,1:4], what= "classification", dimens=c (3,4))
Table (iris$species, Mc$classification)
The principle of EM algorithm and the practice of Gaussian mixture model