EM algorithm and GMM model explained

In statistics, EM (expectation maximization) algorithm handles latent variables, while GMM is the Gaussian mixture model.

Background

In the picture below, are shown the red blood cell hemoglobin concentration and the red blood cell volume data of two groups of people, the Anemia group and the Control Group (i.e. the group of people without Anemia). As expected, people with Anemia have lower red blood cell volume and lower red blood cell hemoglobin concentration than those without Anemia.

x

is a random vector such as

x:=(redbloodcellvolume,redbloodcellhemoglobinconcentration)

, and from medical studies it is known that

x

are normally distributed in each group, i.e.

x\simlN(\mu,\Sigma)

.

z

is denoted as the group where

x

belongs, with

zi=0

when

xi

belongs to Anemia Group and

zi=1

when

xi

belongs to Control Group. Also

z\sim\operatorname{Categorical}(k,\phi)

where

k=2

,

\phij\geq0,

and
k\phi
\sum
j=1
. See Categorical distribution.

The following procedure can be used to estimate

\phi,\mu,\Sigma

.

A maximum likelihood estimation can be applied:

m
\ell(\phi,\mu,\Sigma)=\sum
i=1

log(p(x(i)

m
;\phi,\mu,\Sigma)) =\sum
i=1

log

k
\sum
z(i)=1

p\left(x(i)\midz(i);\mu,\Sigma\right)p(z(i);\phi)

As the

zi

for each

xi

are known, the log likelihood function can be simplified as below:

\ell(\phi,\mu,

m
\Sigma)=\sum
i=1

logp\left(x(i)\midz(i);\mu,\Sigma\right)+logp\left(z(i);\phi\right)

Now the likelihood function can be maximized by making partial derivative over

\mu,\Sigma,\phi

, obtaining:

\phij=

1
m
m
\sum
i=1

1\{z(i)=j\}

\muj=

m
\sum1\{z(i)=j\
i=1
x

(i)

}

\Sigmaj=

m
\sum1\{z(i)=j\
i=1
(x

(i)

(i)
-\mu
j)(x
m
-\mu
i=1

1\{z(i)=j\}}

[1]

If

zi

is known, the estimation of the parameters results to be quite simple with maximum likelihood estimation. But if

zi

is unknown it is much more complicated.[2]

Being

z

a latent variable (i.e. not observed), with unlabeled scenario, the Expectation Maximization Algorithm is needed to estimate

z

as well as other parameters. Generally, this problem is set as a GMM since the data in each group is normally distributed.[3]

In machine learning, the latent variable

z

is considered as a latent pattern lying under the data, which the observer is not able to see very directly.

xi

is the known data, while

\phi,\mu,\Sigma

are the parameter of the model. With the EM algorithm, some underlying pattern

z

in the data

xi

can be found, along with the estimation of the parameters. The wide application of this circumstance in machine learning is what makes EM algorithm so important.

EM algorithm in GMM

The EM algorithm consists of two steps: the E-step and the M-step. Firstly, the model parameters and the

z(i)

can be randomly initialized. In the E-step, the algorithm tries to guess the value of

z(i)

based on the parameters, while in the M-step, the algorithm updates the value of the model parameters based on the guess of

z(i)

of the E-step. These two steps are repeated until convergence is reached.

The algorithm in GMM is:

Repeat until convergence:

1. (E-step) For each

i,j

, set
(i)
w
j

:=p\left(z(i)=j|x(i);\phi,\mu,\Sigma\right)

2. (M-step) Update the parameters

\phij:=

1
m
m
\sum
i=1
(i)
w
j

\muj:=

m
\sum
(i)
w
j
x(i)
i=1
m
\sum
(i)
w
j
i=1

\Sigmaj:=

m
\sum
(i)
w
j
\left(x(i)-\muj\right)\left(x(i)-\muj\right)T
i=1
m
\sum
(i)
w
j
i=1

[4]

With Bayes Rule, the following result is obtained by the E-step:

p\left(z(i)=j|x(i);\phi,\mu,\Sigma\right)=

p\left(x(i)|z(i)=j;\mu,\Sigma\right)p\left(z(i)=j;\phi\right)
k
\sump\left(x(i)|z(i)=l;\mu,\Sigma\right)p\left(z(i)=l;\phi\right)
l=1

According to GMM setting, these following formulas are obtained:

p\left(x(i)|z(i)=j;\mu,\Sigma\right)=

1
(2\pi)n\left|\Sigmaj\right|1

\exp\left(-

1
2

\left(x(i)-\muj\right)T

-1
\Sigma
j

\left(x(i)-\muj\right)\right)

p\left(z(i)=j;\phi\right)=\phij

In this way, a switch between the E-step and the M-step is possible, according to the randomly initialized parameters.

Notes and References

  1. Web site: Ng . Andrew . CS229 Lecture notes .
  2. Web site: Hui . Jonathan . Machine Learning —Expectation-Maximization Algorithm (EM) . Medium . en . 13 October 2019.
  3. Web site: Tong . Y. L. . Multivariate normal distribution . Wikipedia . en . 2 July 2020.
  4. Web site: Ng . Andrew . CS229 Lecture notes .