[ML-13-4] Hidden Markov Model HMM--Viterbi (Viterbi) Algorithm for Prediction Problems

[ML-13-1 ] Hidden Markov Model HMM

[ML-13-2 ] Hidden Markov Model HMM- forward and backward algorithm

[ML-13-3 ] Hidden Markov Model HMM--Baum-Welch (Baum- Welch)

[ML-13-4 ] Hidden Markov Model HMM-- Viterbi (Viterbi) Algorithm for Prediction Problems 

table of Contents

  1. Basics-Calculation of HMM Common Probability
  2. HMM most likely hidden state sequence approximation algorithm
  3. Viterbi algorithm
  4. Examples of Viterbi algorithm

Solution to the last problem of the HMM model: find the corresponding hidden state sequence that is most likely to occur under the given observation sequence. That is, given the model λ = (A, B, π) and the observation sequence Q = {q1, q2, ..., qT}, find the hidden state with the largest conditional probability P (I | Q, λ) of the given observation sequence sequence the I . Before reading this article, it is recommended to read the first article in this series to get familiar with the HMM model.

The most commonly used algorithm for the decoding problem of the HMM model is the Viterbi algorithm. Of course, there are other algorithms that can solve this problem. At the same time, the Viterbi algorithm is a general dynamic programming algorithm for finding the shortest path in the sequence. It can also be used for many other problems, such as the word segmentation principle of text mining.

  This paper focuses on the most likely hidden state sequence of HMM decoding with Viterbi algorithm.

1. Basic- Calculation of HMM Common Probability

 Using the forward and backward probabilities, we can calculate the probability formula for a single state and two states in the HMM.

1.1 Probability of a single state

Given the model λ and the observation sequence Q, the probability of being in state si at time t is written as:

The significance of a single state probability is mainly used to judge the most likely state at each moment, so that a state sequence can be obtained as the final prediction result.

Using the definition of forward probability and backward probability, we can know:

From the above two expressions:

1.2 Joint probability of two states

Given the model λ and the observation sequence Q, the probability of being in state si at time t and being in state sj at time t + 1 is written as:

1.3 The above two summations can be obtained:

2. HMM most likely hidden state sequence approximation algorithm  

In the decoding problem of the HMM model, given the model λ = (A, B, Π) and the observation sequence, find the most likely corresponding state sequence I = {i1, i2, .. .iT}, that is, P (I | Q) should be maximized. The best possible state directly at each time t is used as the final predicted state, and the probability value is calculated using the following formula:

It only needs to satisfy the value that maximizes the probability of the above formula, which can be obtained by forward and backward.

The approximation algorithm is very simple, but it cannot guarantee that the predicted state sequence is the most likely state sequence as a whole, because some adjacent hidden states in the predicted state sequence may have a transition probability of 0.

  The Viterbi algorithm can consider the HMM state sequence as a whole to avoid the problem of approximation algorithms. Let us take a look at the Viterbi algorithm for HMM decoding.

Three, Viterbi (Viterbi) algorithm

The Viterbi algorithm actually solves the HMM prediction problem with the idea of ​​dynamic programming, and finds the "path" with the highest probability. Each "path" corresponds to a state sequence:

At time t, the hidden state is the maximum probability of all possible state transition paths i1, i2, ... it. Recorded as δt (i):

The recursive expression of δ can be obtained from the definition of δt (i):

Calculate the maximum δT (i) at time T, which is the probability of the most likely hidden state sequence.

After making the above formula maximum, the most likely hidden state sequence I = {i 1, i 2, ... i T}

Four, Viterbi (Viterbi) algorithm examples

4.1 Examples

Suppose there are three boxes, numbered 1,2,3; each box is equipped with small balls of black and white colors, the proportion of balls is as follows:

According to the following rules, the ball with the replacement is extracted to obtain the observation sequence of the ball color:

  1. Select a box according to the probability of π, randomly extract a small ball from the box, record the color, and put it back into the box;
  2. Select a new box according to a certain conditional probability and repeat the operation;
  3. Obtained the observation sequence finally: "White black and white white black
  • State set: S = {Box 1, Box 2, Box 3}
  • Observation set: O = {white, black}
  • State sequence and observation sequence length T = 5
  • Initial probability distribution π
  • State transition probability matrix A
  • Observation probability matrix B

When the parameters π, A, and B are given, the observation sequence is "white, black, white, white and black", and the optimal hidden state sequence is obtained.

4.2 Calculation process

The final box sequence is: (2, 3, 2, 2, 3)

Appendix 1: Handwriting exercises

Guess you like

Origin www.cnblogs.com/yifanrensheng/p/12684738.html