Interactive demo · Probabilistic Machine Learning: Advanced Topics · Chapter 29

Baum–Welch (EM) for a hidden Markov model

A casino swaps between a fair die and a die loaded towards six, and you see only the rolls. EM never sees the hidden states. Each iteration runs forwards–backwards with the current parameters (E step, expected counts) and then re-estimates the transition matrix and the emission probabilities by normalising those counts (M step). The log-likelihood of the rolls can only go up. Choose a start, the number of rolls and the number of iterations, and compare the fit with the parameters that generated the data (outlined bars).

Start (initial parameters)

Data and iterations

Try these

The M step is just normalised expected counts: Ajk ∝ E[Njk] (29.30) and Bkv = E[Mkv]/E[Nk] (29.32), where E[Nk] sums γt(k) over all time steps. Note the two states may come out swapped relative to the truth (label switching), and a start in which the two states are identical is a fixed point that EM cannot leave.

In the lecture notes