## Basics section

The scope of this basics section is to provide a short introduction to a few topics and concepts which are essential for speech recognition.

# 1. Introduction

Statistical learning typically starts with observed data and a (parametric) model.  One possible way to estimate the model parameters is maximum likelihood, that is to pick the parameters that maximize the likelihood (probability) of the evidence.

Now while maximum likelihood leads to closed form solutions for many models (in particular for those belonging to the exponential family) and has (at least asymptotically) many desireable properties such as consistency and sufficiency there are models where a direct maximization of the (log) likelihood function is infeasible.

In practice we often encounter missing data - we don't have sufficient information to specify the complete likelihood.  Another scenario in which not all variables in the model are observed are the so-called hidden or latent variable models. In this case there are variables which are essential for the model description but never observed. For example, the underlying physics of a model may contain latent processes which are essential to describe the model, but cannot be directly measured.  Both cases can be tackled by introducing latent variable, that is by splitting observational variables into visible (those for which we actually know the state) and missing ones (those whose states would or should nominally be known). [2]

Expectation maximization is then an iterative approach to maximum likelihood parameter estimation in latent variable models.

In this article we will build up an understanding of the algorithm by considering the well known Gaussian Mixture Model before giving an generalized proof of convergence and closing with a critical discussion.

Our exposition is largely based on the books "Pattern Recognition and Machine Learning" by Christopher Bishop [1] and "Bayesian reasoning and machine learning" by David Barber [2].  Other useful references are indicated in the section Further Reading.

# 2. GMM Training

## 2.1 ML Estimate

Let's first derive the maximum likelihood estimate for the parameters $\inline&space;\theta&space;=&space;\left(\mu,&space;C&space;\right&space;)$ of a multivariate Gaussian distribution.

Assuming a set of independent identically distributed observations $\mathcal{X}$ we need to maximize the likelihood function

$L(\theta&space;)\to&space;\prod&space;_{i=n}^N&space;p\left(\left.x_n\right|\theta&space;\right)$

with respect to the parameter vector $\theta$.

As the (natural) logarithm is strictly monotone function on $\mathbb{R}^+$ we can equivalently maximize the log likelihood function

$l(\theta&space;)\to&space;\sum&space;_{n=1}^N&space;\log&space;\left(p\left(\left.x_n\right|\theta&space;\right)\right)$

which will simplify subsequent calculations for models belonging to the exponential familiy.

For our running example of a multivariate Gaussian that is

$l(\mu&space;,C)\to&space;-\frac{1}{2}&space;\sum&space;_{n=1}^N&space;\left(x_n-\mu&space;\right){}^T&space;C^{-1}&space;\left(x_n-\mu&space;\right)-\frac{N}{2}&space;(\log&space;\left|&space;2&space;{\pi&space;C}\right|&space;)$

Taking the partial derivative with respect to $\mu$ and equating it to $0$ we obtain

$\mu&space;_{\text{ML}}=\frac{\sum&space;_{n=1}^N&space;x_n}{N}$

To find $C_{}{\text{ML}}$  we rewrite the log likelihood as

$l(\mu&space;,\Sigma&space;)\to&space;-\frac{1}{2}&space;\text{Trace}\left[C^{-1}&space;\sum&space;_{n=1}^N&space;\left({x_n}-\mu&space;\right)&space;\left({x_n}-\mu&space;\right)^{\mathsf{T}}\right]-\frac{D&space;N}{2}&space;\log&space;(2&space;\pi&space;)+\frac{N}{2}&space;\log&space;\left(\left\left|&space;C^{-1}\right\right|&space;\right)$

and obtain

$C_{\text{ML}}=\frac{\sum&space;_{n=1}^N&space;\left(x_n-\mu&space;_{\text{ML}}\right)&space;\left(x_n-\mu&space;_{\text{ML}}\right){}^{\mathsf{T}}}{N}$

## 2.2 Known Allocations

Now let's assume that we have a Gaussian Mixture Model with known allocations as illustrated below for a three components two dimensional output example:

([1], Figure 9.5a)

Introducing a $K$-dimensional binary variable $z$ that has a $1$ of $K$ representation, the complete data log likelihood function is given by

$\log&space;(p(X,Z|\mu&space;,C&space;,\pi&space;))\to&space;\sum&space;_{n=1}^N&space;\sum&space;_{k=1}^K&space;z_{n,k}&space;\left(\log&space;\left(\mathcal{N}\left(x_n|\mu&space;_k,C_k\right)\right)+\log&space;\left(\pi&space;_k\right)\right)$

We see that this is a sum of $K$ independent components, therefore the maximization with respect to the means and covariances decouples and we have

$\mu&space;_{k_{\text{ML}}}=\frac{\sum&space;_{n=1}^N&space;z_{n,k}&space;\;x_n&space;}{\sum&space;_{n=1}^N&space;z_{n,k}}$

and

$C_{k_{\text{ML}}}=\frac{\sum&space;_{n=1}^N&space;z_{n,k}&space;\left(x_n-\mu&space;_{k_{\text{ML}}}\right)&space;\left(x_n-\mu&space;_{k_{\text{ML}}}\right){}^{\mathsf{T}}}{\sum&space;_{n=1}^N&space;z_{n,k}}$

Note that both relations depend directly on the number of observations assigned to the $k$-th component so that we have a sufficient statistic given as

$N_k&space;:=&space;\sum&space;_{n=1}^N&space;z_{n,k}$

## 2.3 Unknown Allocations

If the allocations are unknown we might have the following observations:

([1], Figure 9.5b)

Assuming mixing probabilies

$\pi_k&space;:=&space;p(z_k&space;==&space;1)$

the likelihood of a single observation is

$p(x)\to&space;\sum&space;_{k=1}^K&space;\pi&space;_k&space;\mathcal{N}\left(x\left|\mu&space;_k\right.,\Sigma&space;_k\right)$

For $\inline&space;N$ IID observations the corresponding log likelihood function is

$\log&space;(p(X|\pi&space;,\mu&space;,\Sigma&space;))\to&space;\sum&space;_{n=1}^N&space;\log&space;\left(\sum&space;_{k=1}^K&space;\pi&space;_k&space;\mathcal{N}\left(x\left|\mu&space;_k\right.,\Sigma&space;_k\right)\right)$

Thus the parameters to be found are $\inline&space;\left(\mu_{\{k\}},&space;C_{\{k\}},&space;\pi_{\{k\}}&space;\right)$

In a maximum likelihood approach we would again have to equate the derivatives $(\partial_{\mu_{\{k\}}},&space;\partial_{C_{\{k\}}},&space;\partial_{\pi_{\{k\}}})$ to $\inline&space;0$ and solve for the respective parameters.

However it is easy to see that the corresponding equations are coupled which prevents an easy (closed form) solution.

As we don't have the values of the mixing proportions $\pi_{\{k\}}$ we use their expected value with respect to the posterior distribution that using Bayes law is

$p(Z|X,\mu&space;,\Sigma&space;,\pi&space;)\propto&space;\prod&space;_{n=1}^N&space;\prod&space;_{k=1}^K&space;\left(\pi&space;_k&space;\mathcal{N}\left(x_n|\mu&space;_k,\Sigma&space;_k\right)\right){}^{z_{n,k}}$

Now the expected value for each individual component $\inline&space;z_{n,k}$ is

$\mathbb{E}\left(z_{n,k}\right)\to&space;\frac{\pi&space;_k&space;\mathcal{N}\left(x_n|\mu&space;_k,\Sigma&space;_k\right)}{\sum&space;_{k=1}^K&space;\pi&space;_k&space;\mathcal{N}\left(x_n|\mu&space;_k,\Sigma&space;_k\right)}\to&space;\gamma&space;\left(z_{n,k}\right)$

(The expectation of a binary $\inline&space;0,&space;1$ variable is just it's probability so the exponents drop out)

Note that $\inline&space;\gamma(z_{n,k})$ can be interpreted as the responsibility of the $k$-th component for the $n$-th data point.

Accordingly the expectation of the complete data log likelihood can be written as

$\mathbb{E}_Z(\log&space;(p(X,Z|\mu&space;,\Sigma&space;,\pi&space;)))\to&space;\sum&space;_{n=1}^N&space;\sum&space;_{k=1}^K&space;\gamma&space;\left(z_{n,k}\right)&space;\left(\log&space;\left(\mathcal{N}\left(x_n|\mu&space;_k,\Sigma&space;_k\right)\right)+\log&space;\left(\pi&space;_k\right)\right)$

which is finally the quantity to be maximized by the expectation maximization algorithm.

$\mathbb{E}_Z(\log&space;(p(X,Z|\mu&space;,\Sigma&space;,\pi&space;)))\to&space;\sum&space;_{n=1}^N&space;\sum&space;_{k=1}^K&space;\gamma&space;\left(z_{n,k}\right)&space;\left(\log&space;\left(\mathcal{N}\left(x_n|\mu&space;_k,\Sigma&space;_k\right)\right)+\log&space;\left(\pi&space;_k\right)\right)$

To this end we define

$N_k&space;:=&space;\sum&space;_{n=1}^N&space;\gamma&space;\left(z_{n,k}\right)$

and rewrite the maximum likelihood estimates as

$\mu&space;_{k_{\text{ML}}}=\frac{\sum&space;_{n=1}^N&space;x_n&space;\gamma&space;\left(z_{n,k}\right)}{\sum&space;_{n=1}^N&space;z_{n,k}}$

$C_{k_{\text{ML}}}=\frac{\sum&space;_{n=1}^N&space;\gamma&space;\left(z_{n,k}\right)&space;\left(x_n-\mu&space;_{k_{\text{ML}}}\right)&space;\left(x_n-\mu&space;_{k_{\text{ML}}}\right){}^{\mathsf{T}}}{\sum&space;_{n=1}^N&space;z_{n,k}}$

For the maximization with respect to the mixing components $\pi_{\{k\}}$ we have to enforce the summation constraint

$\sum&space;_{k=1}^K&space;\pi&space;_k=1$

and introduce a corresponding Lagrange multiplier $\lambda$ to obtain

$\pi&space;_{k_{\text{ML}}}\to&space;\frac{N_k}{N}$

## 2.4 Algorithm

Now the full alorithm reads as follows:

1. Initialize the parameters $\left(\overset{(i)}{\mu&space;_{\{k\}}},\overset{(i)}{\Sigma&space;_{\{k\}}},\overset{(i)}{\pi&space;_{\{k\}}}\right)$ for iteration index $i&space;=&space;0$.
2. Evaluate the responsibilities $\overset{(i)}{\gamma&space;}\left(z_{n,k}\right)$
3. Compute the maximum likelihood estimates $\inline&space;\left(\overset{(i)}{\mu&space;_{\{k\}_{\text{ML}}}},\overset{(i)}{\Sigma&space;_{\{k\}_{_{\text{ML}}}}},\overset{(i)}{\pi&space;_{\{k\}_{\text{ML}}}}\right)$
4. Continue with 2. until convergence.

Upon convergence the results can be visualized by color coding the responsibilities

([1], Figure 9.5c)

# 3. Generalization

As this derivation may appear rather heuristic we proceed to show that the algorithm indeed maximizes the log likelihood function in general.

For any hidden variable model the probability of the evidence can be obtained as the marginal

$p(X|\theta&space;)\to&space;\sum&space;_Z&space;p(X,Z|\theta&space;)$([1], eqn. 9.69)

If we introduce an arbitrary distribution on the hidden variables as $q(z)$, the corresponding log likelihood function can be decomposed as

$\log&space;(p(X|\theta&space;))\to&space;\mathcal{L}(q,\theta&space;)+\text{KL}(q&space;||&space;p)$

with

$\mathcal{L}(q,\theta&space;)\to&space;\sum&space;_Z&space;q(z)&space;\log&space;\left(\frac{p(X,Z|\theta&space;)}{q(z)}\right)$

$\text{KL}(q&space;||&space;p)\to&space;\sum&space;_Z&space;q(z)&space;\log&space;\left(\frac{p(Z|X,\theta&space;)}{q(z)}\right)$

where $\text{KL}(q&space;||&space;p)$ is the Kullback Leibler divergence between $\inline&space;q(z)$ and the posterior $p(Z&space;|&space;X,&space;\theta)$. As the Kullback Leibler is nonegative, with equality only for equal distributions $\mathcal{L}(q&space;,\theta)$ gives a lower bound to the complete log likelihood.

Now the E step does exactly set $q(z)$ equal to the posterior distribution $p(Z&space;|&space;X,&space;\overset{(i)}{\theta})$ .  Consequently the Kullback-Leibler divergence vanishes and the lower bound can be written as

$\mathcal{L}(q,\theta&space;)\to&space;\sum&space;_Z&space;p\left(Z|X,\overset{(i)}{\theta&space;}\right)&space;\log&space;(p(X,Z|\theta&space;))-p\left(Z|X,\overset{(i)}{\theta&space;}\right)&space;\log&space;\left(p\left(Z|X,\overset{(i)}{\theta&space;}\right)\right)$

Here the first term is exactly the expectation of the complete data log likelihood. The second term is the negative entropy of the $q$ distribution and can be neglected for the optimization with respect to $\inline&space;\theta$ in the M step. Note that the optimization parameters appear only in the argument of the $\log$ function which is particulary useful if the joint distribution $\inline&space;p(X,&space;Z&space;|&space;\theta)$ is a member of the exponential familiy.

Now the updated values $\overset{(i)}{\theta}$ imply a non zero KL divergence and lead to the next E step.

([1], Figures 9.12 and 9.13)

Thus iteration of both steps consistently increases the log likelihood function towards a (local) maximum.

# 4. Discussion

While the expectation maximization algorithm is a highly versatile procedure there are some caveats

• As the complete data log likelihood function is in general non-convex the algorithm can get stuck in optima that are either only local or pathological. For the example of a Gaussian Mixture that means that one of the components can collapse into a single point so that $\mu_k&space;=&space;x_n$ which introduces a term
$\mathcal{N}\left(x_n|x_n,i&space;\sigma&space;_k^2\right)\to&space;\frac{1}{\sqrt{2&space;\pi&space;}&space;\sigma&space;_k}$
so that the complete log likelihood goes to $\infty$ as $\sigma&space;\to&space;0$. To avoid such cases one can use heuristics to detect the collapsing component and subsequently reset its mean and covariance randomly before continuing with the optimization.  To find the best local maximum it may be advisable to evaluate several runs of the algorithm each initialized at random.
• A further issue in finding maximum likelihood solutions arises from the fact that for any given maximum likelihood solution, a $K$-component mixture will have a total of $K!$ equivalent solutions corresponding to the $K!$ ways of assigning $K$ sets of parameters to $K$ components. This problem is known as identifiability and becomes an issue when we whish to intrepret the parameter values discovered by the model. [5]
• Depending on the distributions involved a complete maximization in both the E and M step may become infeasible introducing the need for approximations such as generalized, partial and stochastic EM. [3]
• The maximum likelihood nature of  the procedure makes it prone to overfitting.  Also it may be desirable to include prior knowledge which can be done by adopting a Bayesian approach leading to the Variational Bayes Framework [4]

# 5. Further Reading

[1] Bishop, Christopher M. Pattern recognition and machine learning.  Springer,  2006.

[2] Barber, David. Bayesian reasoning and machine learning. Cambridge University Press, 2014.

[3] McLachlan, Geoffrey, and Thriyambakam Krishnan. The EM algorithm and extensions.  John Wiley & Sons, 2007.

[4] Beal, M.J. Variational Algorithms for Approximate Bayesian Inference PhD. Thesis, Gatsby Computational Neuroscience Unit, University College London, 2003.

[5] Casella, George, and Roger L. Berger. Statistical inference. Duxbury, 2002.

# 1. Stochastic processes

A stochastic process is defined as a sequence of random variables $x_1,&space;x_2,&space;...$. The random variable $x_n$ is called state of the process at time $n$. We assume a discrete time process here, i.e. the state is observed only at these time instances. The simplest example of such a process is a sequence of independent observations:

Sequence of independent observations [1]

Assuming all observations as independent would however mean loosing all time dependent information. To overcome this, we regard a process where the current state depends on the states observed before. To fully describe such a process, it is necessary to define the probability distribution for the initial state $p(x_1)$ as well as for all following states $n=2,3,...$ the conditional distribution $p(x_n|x_1,...,x_{n-1})$

Dependent observations [1] (altered)

As we can see from the figure, with a growing number of states we quickly get confusingly many dependencies. A model where a state depends on all the states visited before is therefore not feasible in a practical system.

# 2. Markov models

One special type of a stochastic process is the so called Markov chain. It has the convenient property that the conditional probability of the current state $n$ depends only on the previous state:

$p(x_n|x_1,...,x_{n-1})&space;=&space;p(x_n|x_{n-1})$

As we can see, the model stays simple even when the number of states is increased.

Markov model [1]

Let's assume we want to predict the weather with a Markov model. Our model should have two states: "rainy" and "sunny". It is known that after a rainy day the next day will be sunny with a probability of 30%. After a sunshine day, the next day will bring rain with a 40% chance. The state diagram for this example is shown below.

Based on the weather of the current day, we can now make a prediction of the weather on the following day.

# 3. Hidden markov models

In the previous example, the weather and the state respectively can be observed directly. For many applications however, this is not the case. We thus extend our model to a so called Hidden markov model (HMM). The model consists of an underlying Markov process with states $z_1,z_2,...$ which cannot be observed directly. What can be observed are the emissions $x_1,x_2,...$. The emission $x_n$ is a probabilistic function of the state $z_n$. One important assumption inherent with Hidden markov models is that the current state contains all information about previous observations.

Hidden markov model [1]

Let's go back to our weather example from before and extend it to an HMM. There is a prisoner locked into a dungeon without windows. He cannot see if it's a rainy or a sunny day. The only thing that he can observe is whether the shoes of the guards are clean or dirty. He knows that if it's raining, the guards' shoes are dirty in 90% of the cases, but when it's sunny they are dirty only with a 60% chance. The state space diagram now looks as follows:

The prisoner can exploit this knowledge and make predictions about the weather outside, just by looking at the guards' shoes. Leaving the prison again and entering the outside world, one can find many applications for HMMs. They are often used as a model for temporal pattern recognition applications. In this context they are frequently applied for speech recognition tasks.

# References

[1] Bishop, Christopher M. Pattern recognition and machine learning. Vol. 4. No. 4. New York: springer, 2006.

[2] DeGroot, Morris H., et al. Probability and statistics. Vol. 2. Reading, MA: Addison-Wesley, 1986.

[3] Rabiner, Lawrence. "A tutorial on hidden Markov models and selected applications in speech recognition." Proceedings of the IEEE 77.2 (1989): 257-286.

## Viterbi Algorithm

Given a Hidden Markov Model and a sequence of observations, the Viterbi Algorithm determines the most probable sequence of hidden states very efficiently. For instance in speech recognition, it is used in the language model to find the most probable word out of a phonemes sequence.

# 1 Motivation

In many applications of Hidden Markov Models, it is often of interest to find the most probable state sequence if an observation sequence is given. A naive approach would be to compute the probability of each combination of states and then to choose the most probable state combination. However, an increase of the number of states $N$ comes along with an increase of the number of combinations. This again results in an increase of the computational costs in an exponential manner. Consequently in real life, it is only possible to determine the most probable state sequence for small $N$. In contrast to the naive approach, the Viterbi-Algorithm is also suitable for greater $N$ since its computational costs grow only linearly. The basic idea of this algorithm is to find the most probable state sequence iteratively. For each state $s_j$ at time $t$, the most probable path is searched depending only on the most probable path to state $s_i$ at time $t-1$ and the transition probability $a_{ij}$ from state $s_i$ to state $s_j$.

# 2 Problem Definition

Before providing you more information about the concept of the Viterbi Algorithm, the general problem is outlined in this section. Let us assume that a Hidden Markov Model is given. Then let $N$ be the number of states in the model $\left\{s_1,&space;s_2,...,s_N\right\}$ and $M$ the number of discrete observations $\left\{\nu_1,&space;\nu_2,...,\nu_M\right\}$. At time $t$, the observation $o_t$ can be made and it is assumed that the Hidden Markov Model is in state $q_t$. Furthermore, $a_{ij}$ is defined as the transition probability from state $s_i$ to state $s_j$

$a_{ij}&space;&=&space;p\left(q_t&space;=&space;s_j|q_{t-1}&space;=&space;s_i\right),$

and $b_j(k)$ is defined as the observation probability distribution

$b_j(k)&space;&=&space;p\left(o_t&space;=&space;\nu_k|q_t&space;=&space;s_j\right)$

and $\pi_i$ is the initial state distribution

$\pi_i&space;&=&space;p\left(q_1&space;=&space;s_i\right).$

The goal of the Viterbi Algorithm is to find the optimal state sequence $\mathbf{q}^*&space;=&space;\left\{q_1^*,&space;q_2^*,...,q_T^*&space;\right\}$ such that its probability $p(\mathbf{q}^*)$ is maximal given an observation sequence $\left\{o_1,&space;o_2,...,o_T\right\}$. Recall that $q_t$ is defined as the state $s_i$ at time t.

# 3 Basic Idea

The main idea of the Viterbi Algorithm is that at every time $t$ and state $s_j$ the most probable state is determined in dependence of the most probable state sequence at time $t-1$ and the transition probability $a_{ij}$. For simplicity, let's define the variable $\delta_t(i)$, which gives the probability of the optimal state sequence from $t=1$ to state $s_i$ at time $t$. Mathematically, $\delta_t(i)$ is defined as:

$\delta_t(i)&space;&=&space;\max_{q_1,...,q_{t-1}}&space;p\left(q_1,...,q_{t-1},&space;q_t&space;=&space;s_i|&space;o_1,&space;o_2,...,o_t\right)$

where $1&space;\leq&space;i&space;\leq&space;N$and $q_t(i)$ stands for state $s_i$ at time $t$. The advantage of this definition is that $\delta_{t+1}$ can be iteratively calculated by

$\delta_1(i)&space;&=&space;\pi_i&space;\cdot&space;b_i(o_1)&space;\\&space;\delta_{t+1}(j)&space;&=&space;\max_i&space;\left[\delta_t(i)&space;a_{ij}\right]&space;\cdot&space;b_j(o_{t+1}).$

The probability of the desired optimal state sequence $\mathbf{q}^*$ is equal to $\delta_T(i)$. However, $\delta_T(i)$ cannot give you any information about the optimal state sequence. Hence, a new variable $\psi$ is introduced, which should deliver the most probable following state $s_j$ at time $t+1$ for a given state $s_i$ at time $t$:

$\psi_{t+1}(j)&space;=&space;\arg\,\max_{1\leq&space;i&space;\leq&space;N}&space;\left[&space;\delta_t(i)&space;a_{ij}\right].$

Finally, the optimal state sequence $\mathbf{q}^*$ can be determined by backtracking:

$q_t^*&space;&=&space;\psi_{t+1}\left(q_{t+1}^*\right)&space;&&space;\text{for&space;}&space;t&space;=&space;T-1\text{&space;...&space;}1$

# 4 The Algorithm

Summarizing the ideas of the last section, the Viterbi Algorithm for finding the optimal state sequence reads:

• Initialization:

$\delta_1(i)&space;=&space;\pi_i&space;\cdot&space;b_i(o_1)&space;\text{&space;for&space;}1&space;\leq&space;i&space;\leq&space;N$

$\psi_1(i)&space;=&space;0&space;\text{&space;(no&space;previous&space;states)}$

• Recursion:    $t=2...T$ for $j&space;=&space;1&space;...&space;N$

$\delta_{t+1}(j)&space;=&space;\max_i&space;\left[\delta_t(i)&space;a_{ij}\right]&space;\cdot&space;b_j(o_{t+1})$

$\psi_{t+1}(j)&space;=&space;\arg\,\max_{1\leq&space;i&space;\leq&space;N}&space;\left[&space;\delta_t(i)&space;a_{ij}\right]$

• Termination:

$q_T^*&space;=&space;\arg\,\max_{1\leq&space;i\leq&space;N}&space;\left[&space;\delta_t(i)\right]$

$q_t^*&space;=&space;\psi_{t+1}\left(q_{t+1}^*\right)&space;\text{&space;for&space;}&space;t&space;=&space;T-1\text{&space;...&space;}1$

The input of the algorithm is a given Hidden Markov Model with its parameters and an observation sequence. The output is the most probable state sequence $\mathbf{q}^*$.

# 5 A Small Example

The goal of the following example is to determine the most probable word given the phonemes sequence $\left\{p_1,&space;p_2,&space;p_2,&space;p_3\right\}$. For this, a Hidden Markov Model with three states ($A$, $n$, $e$) is used. It is given in the figure below. For initialization, it is assumed that the three states are initially equally probable, e.g. $\pi_1&space;=&space;\pi_2&space;=&space;\pi_3&space;=&space;1/3$.

## 5.1 Initialization

For initialization, $\delta_1(1)$$\delta_1(2)$ and $\delta_1(3)$ are determined first. Hereby, it is assumed that observation $p_1$ occurs.

$\delta_1(1)&space;&=&space;\pi_1&space;\cdot&space;b_1(p_1)&space;=&space;\frac{1}{3}&space;\cdot&space;\frac{8}{10}&space;=&space;\frac{8}{30}$
$\delta_1(2)&space;&=&space;\pi_2&space;\cdot&space;b_2(p_1)&space;=&space;\frac{1}{3}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{1}{30}$

$\delta_1(3)&space;&=&space;\pi_3&space;\cdot&space;b_3(p_1)&space;=&space;\frac{1}{3}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{1}{30}$

## 5.2 Recursion

Now $\delta_t(1)$$\delta_t(2)$ and $\delta_t(3)$ are determined iteratively for $t&space;=&space;2,3,4$.

time step t = 2:

$\delta_2(1)&space;&=&space;\max\left\{\delta_1(1)\cdot&space;a_{11},&space;\delta_1(2)\cdot&space;a_{21},&space;\delta_1(3)\cdot&space;a_{31}\right\}\cdot&space;b_1(p_2)\\&space;&=&space;\max\left\{\frac{8}{30}\cdot\frac{2}{10},&space;\frac{1}{30}\cdot&space;\frac{3}{10},&space;\frac{1}{30}\cdot&space;\frac{4}{10}\right\}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{16}{300}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{16}{3000}$

$\delta_2(2)&space;&=&space;\max\left\{\delta_1(1)\cdot&space;a_{12},&space;\delta_1(2)\cdot&space;a_{22},&space;\delta_1(3)\cdot&space;a_{32}\right\}\cdot&space;b_2(p_2)\\&space;&=&space;\max\left\{\frac{8}{30}\cdot\frac{4}{10},&space;\frac{1}{30}\cdot&space;\frac{4}{10},&space;\frac{1}{30}\cdot&space;\frac{4}{10}\right\}&space;\cdot&space;\frac{8}{10}&space;=&space;\frac{32}{300}&space;\cdot&space;\frac{8}{10}&space;=&space;\frac{256}{3000}\\$
$\delta_2(3)&space;&=&space;\max\left\{\delta_1(1)\cdot&space;a_{13},&space;\delta_1(2)\cdot&space;a_{23},&space;\delta_1(3)\cdot&space;a_{33}\right\}\cdot&space;b_3(p_2)\\&space;&=&space;\max\left\{\frac{8}{30}\cdot\frac{4}{10},&space;\frac{1}{30}\cdot&space;\frac{3}{10},&space;\frac{1}{30}\cdot&space;\frac{2}{10}\right\}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{32}{300}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{32}{3000}\\$

$\psi_2(1)&space;&=&space;\arg\,\max\left\{\frac{8}{30}\cdot\frac{2}{10},&space;\frac{1}{30}\cdot&space;\frac{3}{10},&space;\frac{1}{30}\cdot&space;\frac{4}{10}\right\}&space;=&space;1$

$\psi_2(2)&space;&=&space;\arg\,\max\left\{\frac{8}{30}\cdot\frac{4}{10},&space;\frac{1}{30}\cdot&space;\frac{4}{10},&space;\frac{1}{30}\cdot&space;\frac{4}{10}\right\}&space;=&space;1$

$\psi_2(3)&space;&=&space;\arg\,\max\left\{\frac{8}{30}\cdot\frac{4}{10},&space;\frac{1}{30}\cdot&space;\frac{3}{10},&space;\frac{1}{30}\cdot&space;\frac{2}{10}\right\}&space;=&space;1\\$

time step t=3:

$\delta_2(1)&space;&=&space;\max\left\{\frac{16}{3000}\cdot\frac{2}{10},&space;\frac{256}{30}\cdot&space;\frac{3}{10},&space;\frac{32}{3000}\cdot&space;\frac{4}{10}\right\}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{768}{3\cdot10^6}$

$\delta_2(2)&space;&=&space;\max\left\{\frac{16}{3000}\cdot\frac{4}{10},&space;\frac{256}{3000}\cdot&space;\frac{4}{10},&space;\frac{32}{3000}\cdot&space;\frac{4}{10}\right\}&space;\cdot&space;\frac{8}{10}&space;=&space;\frac{8192}{3\cdot10^6}$

$\delta_2(3)&space;&=&space;\max\left\{\frac{16}{3000}\cdot\frac{4}{10},&space;\frac{256}{3000}\cdot&space;\frac{3}{10},&space;\frac{32}{3000}\cdot&space;\frac{2}{10}\right\}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{768}{3\cdot10^6}$

$\psi_3(1)&space;&=&space;\arg\,\max\left\{\frac{16}{3000}\cdot\frac{2}{10},&space;\frac{256}{30}\cdot&space;\frac{3}{10},&space;\frac{32}{3000}\cdot&space;\frac{4}{10}\right\}&space;=&space;2$

$\psi_3(2)&space;&=&space;\arg\,\max\left\{\frac{16}{3000}\cdot\frac{4}{10},&space;\frac{256}{3000}\cdot&space;\frac{4}{10},&space;\frac{32}{3000}\cdot&space;\frac{4}{10}\right\}&space;=&space;2$

$\psi_3(3)&space;&=&space;\arg\,\max\left\{\frac{16}{3000}\cdot\frac{4}{10},&space;\frac{256}{3000}\cdot&space;\frac{3}{10},&space;\frac{32}{3000}\cdot&space;\frac{2}{10}\right\}&space;=&space;2$

time step t=4:

$\delta_4(1)&space;&=&space;\max\left\{\frac{768}{3\cdot10^6}\cdot\frac{2}{10},&space;\frac{8192}{3\cdot10^6}\cdot&space;\frac{3}{10},&space;\frac{768}{3\cdot10^6}\cdot&space;\frac{4}{10}\right\}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{24576}{3\cdot10^8}$

$\delta_4(2)&space;&=&space;\max\left\{\frac{768}{3\cdot10^6}\cdot\frac{4}{10},&space;\frac{8192}{3\cdot10^6}\cdot&space;\frac{4}{10},&space;\frac{768}{3\cdot10^6}\cdot&space;\frac{4}{10}\right\}&space;\cdot&space;\frac{1}{10}&space;=&space;\frac{32768}{3\cdot10^8}$

$\delta_4(3)&space;&=&space;\max\left\{\frac{768}{3\cdot10^6}\cdot\frac{4}{10},&space;\frac{8192}{3\cdot10^6}\cdot&space;\frac{3}{10},&space;\frac{768}{3\cdot10^6}\cdot&space;\frac{2}{10}\right\}&space;\cdot&space;\frac{8}{10}&space;=&space;\frac{262144}{3\cdot10^8}$

$\psi_4(1)&space;&=&space;\arg\,\max\left\{\frac{768}{3\cdot10^6}\cdot\frac{2}{10},&space;\frac{8192}{3\cdot10^6}\cdot&space;\frac{3}{10},&space;\frac{768}{3\cdot10^6}\cdot&space;\frac{4}{10}\right\}&space;=&space;2$

$\psi_4(2)&space;&=&space;\arg\,\max\left\{\frac{768}{3\cdot10^6}\cdot\frac{4}{10},&space;\frac{8192}{3\cdot10^6}\cdot&space;\frac{4}{10},&space;\frac{768}{3\cdot10^6}\cdot&space;\frac{4}{10}\right\}&space;=&space;2$

$\psi_4(3)&space;&=&space;\arg\,\max\left\{\frac{768}{3\cdot10^6}\cdot\frac{4}{10},&space;\frac{8192}{3\cdot10^6}\cdot&space;\frac{3}{10},&space;\frac{768}{3\cdot10^6}\cdot&space;\frac{2}{10}\right\}&space;=&space;2$

## 5.3 Termination

By backtracking, the most probable state sequence can be determined:

$q_4^*&space;&=&space;\arg\,\max\left\{\delta_4(1),&space;\delta_4(2),&space;\delta_4(3)\right\}&space;=&space;3$

$q_3^*&space;&=&space;\psi_4(3)&space;=&space;2$
$q_2^*&space;&=&space;\psi_3(2)&space;=&space;2$
$q_1^*&space;&=&space;\psi_2(2)&space;=&space;1$

Hence, the most probable state sequence $\mathbf{q}^*$ is $\left\{1,&space;2,&space;2,&space;3\right\}$ which corresponds to the word "Anne".

# 6 References

[1] Bishop, C. (2006). Pattern Recognition and Machine Learning.

[2] Duda, R.  & Hart, P. &  Strok, D., Pattern Classification.

[3] Lee, D. (2014). Lecture notes of the lecture Machine Learning in Robotics

# 1. Normal distribution

The basis for Gaussian Mixture Models is the Normal or Gaussian distribution with the probability density function (pdf)

${p}(x)\,&space;=&space;\,&space;{\frac{{{1}}}{{{{\sqrt&space;{2\pi&space;\sigma^2}&space;}}&space;}}\exp&space;\left(&space;-&space;\frac{(x&space;-&space;{\mu})^2}{2\sigma^2}&space;\right)}$

with mean $\mu$ and variance $\sigma$. Plotting this one dimensional function with $\mu&space;=&space;0$ and $\sigma&space;=&space;1$ leads to the famous Gauss curve

# 2. Multivariate normal distribution

This distribution can be extended to a multidimensional case. Let's assume a n-dimensional random variable $X&space;=&space;[X_1,&space;X_2,...,X_n]$ with Gaussian distribution $X&space;\sim&space;{\cal&space;N}({\mu&space;_m},{C_m})$.

The pdf is now given by
${p}(x)\,&space;=&space;\,&space;{\frac{{{1}}}{{{{\sqrt&space;{2\pi&space;}&space;}^n}\sqrt&space;{\det&space;{C}}&space;}}\exp&space;\left(&space;-&space;\frac{1}{2}{{(x&space;-&space;{\mu})}^T}C^{&space;-&space;1}(x&space;-&space;{\mu})\right)}$

where  $\mu&space;=&space;[E[X_1],&space;E[X_2],...,E[X_n]]$ is the mean vector and  $C&space;=&space;[\operatorname{Cov}[X_i,&space;X_j]];&space;i,j=&space;1,2,...,n$ the covariance matrix.

We now regard a two dimensional Gaussian distribution with

$\mu&space;=&space;[0,&space;0]$

$C&space;=&space;\begin{bmatrix}&space;0.25&space;&&space;0\\&space;0&space;&&space;2.5&space;\end{bmatrix}$.

The diagonal elements describe the variance of one Gaussian random variable, the off-diagonal elements the covariance between the random variables. These are zero here, hence the two random variables are independent. The distribution or more precisely the pdf of the distribution, can be visualized in different ways. The first plot shows how the 2-d distribution is formed by two 1-d marginal distributions. The same distribution is again shown in the second plot, where the floor is given the two dimensions of the distribution and the third dimension depicts the probability. Instead of plotting the 3-d shape of the Gauss bell, one can also "cut" several times through the bell and plot the contour lines. The resulting ellipses represent lines of equal probability.

# 3. Gaussian mixture models

However the multivariate Gaussian distribution still has clear limitations when it comes to modelling real data, which does not necessarily follow the Gauss curve. A much more flexible approach is to use a superposition of several Gaussian distributions, each weighted by a coefficient $c_m$. This is called a mixture model and the Gaussian densities ${\cal&space;N}({\mu&space;_m},{C_m})$ are called components. Each component has its own mean $\mu_m$ and covariance $C_m$. The pdf for $M$ components is given by

${p}(x)\,&space;=&space;\sum\limits_{m&space;=&space;1}^M&space;{{c_m}&space;{\cal&space;N}({\mu&space;_m},{C_m})}&space;=&space;\,\sum\limits_{m&space;=&space;1}^M&space;{\frac{{{c_m}}}{{{{\sqrt&space;{2\pi&space;}&space;}^n}\sqrt&space;{\det&space;{C_m}}&space;}}\exp&space;\left(&space;-&space;\frac{1}{2}{{(x&space;-&space;{\mu&space;_m})}^T}C_m^{&space;-&space;1}(x&space;-&space;{\mu&space;_m})\right)}$.

We also note that the sum of the mixing coefficients adds up to one.

$\sum\limits_{m&space;=&space;1}^M&space;{c_m}&space;=&space;1$

By increasing the number of components and adjusting the parameters of each component, almost any set of data can be represented by a Gaussian mixture model (GMM) with high accuracy.

# 4. Fitting with sample data

To illustrate the advantage of GMMs over multivariate Gaussians, peakly distributed data with two dimensions has been generated (first plot). Now we want to find a model for this bimodal data set. The second figure shows a multivariate Gaussian distribution fitted to the data. It is obvious that the distribution does not well represent the original data.

Now we try the same with a Gaussian mixture model. Therefore the data has to be split into clusters first. Each cluster represents one component of the mixture model. Clustering can be done with the k-means Algorithm. After the data has been separated into clusters, each cluster is represented by a multivariate Gaussian distribution. The distribution is fitted to the data using a technique called Expectation-Maximization (EM).

Our sample data splits into two clusters. The last figure shows a GMM fitted to the data. As we can see, in contrast to simple multivariate Gaussians, the Gaussian mixture model represents the data very well. In speech recognition tasks, GMMs are frequently used to model the acoustic feature vectors. The article "Gaussian mixture models for speech recognition" deals with this application.

# References

[1] Bishop, Christopher M. Pattern recognition and machine learning. Vol. 4. No. 4. New York: springer, 2006.

[2] DeGroot, Morris H., et al. Probability and statistics. Vol. 2. Reading, MA: Addison-Wesley, 1986.