A Brief Introduction to HMM
"TLDR: This article introduces the fundamental principles, underlying assumptions, and solutions to the three core problems of the Hidden Markov Model (HMM): the evaluation problem, the prediction problem, and the learning problem. It elaborates on the joint probability function modeling of HMM, including the initial state probability distribution π, the state transition probability matrix A, and the emission probability matrix B. For the evaluation problem, the forward algorithm is mentioned; for the prediction problem, both the greedy algorithm and the Viterbi algorithm are discussed; and for the learning problem, it distinguishes between supervised and unsupervised learning scenarios, noting that the EM algorithm is commonly used to estimate model parameters in unsupervised learning."
Prerequisites/Assumptions of HMM
+------+ +------+ +------+ +------+
Start-> | S₁ | --> | S₂ | --> | S₃ | --> | Sₙ |
+------+ +------+ +------+ +------+
| | | |
v v v v
+------+ +------+ +------+ +------+
| O₁ | | O₂ | | O₃ | | Oₙ |
+------+ +------+ +------+ +------+
- Markov property: The state at time t depends only on the state at time t-1, and is independent of earlier states.
- Observation independence: The observation at time t depends only on the state at that time, and is independent of observations and states at any other time.
In HMM, once we have the dataset, we model their joint probability function:
Therefore, the joint probability depends only on:
- : Initial state probability distribution, denoted as
- : State transition probability matrix, denoted as
- : The probability distribution of observations given a state, also called emission probability, denoted as
All computations and predictions in HMM revolve around how to derive from the dataset.
- Evaluation problem: Given and an observation sequence , we need to compute the probability of this observation sequence occurring. The standard solution is the forward algorithm or the backward algorithm.
- Prediction problem: Given and an observation sequence , predict the most likely state sequence. The standard solutions are the greedy algorithm or the Viterbi algorithm.
- Learning problem: The model parameters are unknown and need to be learned or inferred. This falls into two scenarios:
- Supervised learning with known observation sequences and state sequences: directly compute the matrix and matrix by statistical counting from the dataset.
- Unsupervised learning where only observation sequences are known and the underlying states are unknown: this typically employs the EM algorithm.
On the Evaluation Problem:
Since the number of possible state sequences grows exponentially — if there are possible states, then there are possible state sequences — it is impossible to enumerate them all. Therefore, the forward algorithm based on dynamic programming is used instead. I haven't looked into the specific algorithm details.
On the Prediction Problem
We want to find a state sequence that maximizes the probability. The greedy solution is to maximize the probability of each individual state, i.e., choose the state with the highest probability at each step.
I haven't looked into the Viterbi algorithm.
On the Learning Problem
Supervised Scenario
Since we already know the state behind each observation, the state transition matrix and emission matrix can be directly computed by counting:
- Divide the state sequence into pairs, and directly obtain the frequency of transitioning from one state to another, then normalize to probabilities.
- Directly count the number of times a state produces a certain observation to obtain the emission frequency, then normalize to emission probabilities.
Unsupervised Scenario
We can only see the observation sequences and do not know the underlying states. The goal is to learn the model parameters such that is maximized.
This is done using the EM algorithm. However, the E-step of the EM algorithm used in HMM is a bit unusual, and I haven't been able to resolve it for now.