0. Brief Description
This document mainly references "a tutorial on Hidden Markov models". This article can be found at http://vision.ai.uiuc.edu/dugad. We mainly read this technical report to learn about some hmm learning algorithms, namely, segmented K-means and forward-backward algorithms (also known as the baumwelch algorithm ).
The previous two articles have introduced the basis of HMM, so more formulas are available here. The two articles are: Hidden Markov Model-Hmm-Overview-1-principle-example, Hidden Markov Model-Hmm-Overview-2-evaluation-decoding-learning.
1. symbol description
Here, we will briefly describe that this article will refer to the hidden State as the State, and the observed state as the symbol.
N: The type of the state, M: the type of the symbol, T: the length of the symbolic sequence (Here we assume that the sample length is the same as the length ).
I _t: the status of T moment.
{V}: Symbol Set.
Initial: initial probability vector of the State.
A_ I _j: P (t + 1 moment in the state j | T moment in the state I), this is the transfer between States, is the adjacent time, t moment to t + 1 moment.
B _j (k): p (the symbol of the T moment is k | T moment is in the state J). This is the conditional probability of the state to the symbol. It is at the same time and is always at the T moment.
O_t: t time symbol.
Lambda = (a, B, callback): HMM model, or hmm parameter.
Symbol description in the original article:
2. Evaluation
Evaluation problem: when HMM parameters are known, calculate the probability of the symbol sequence, that is, P (O | λ ).
First, a direct calculation method is introduced to calculate the probability of the symbolic sequence corresponding to each state sequence, and then sum these probability values, that is, the probability of the symbolic sequence.
I = I _1, I _2,..., I _T represents any state sequence, O = O_1, O2,..., O_T represents any symbol sequence.
P (O, I | λ) = P (O | λ, I) * P (I | λ)
P (O | λ, I) = B _ I _1 (O_1) * B _ I _2 (O2) * · * B _ I _T (O_T)
P (I | λ) = 1__ I _1 * a_ I _1_ I _2 * · * a_ I _T-1_ I _T
P (O, I | λ) sums all I, that is, P (O | λ)
In this way, the computing complexity is high. For each State I, the computing time is 2 T, and the number of state I sequences is N ^ T, so the time complexity is 2 T * N ^ T, is the exponential function of T. Formula Derivation in the original article:
The forward algorithm is provided below to solve this problem. First define the forward factor, α _ t (I) = P (O_1, O2 ,..., o_t, I _t = I | λ), that is, the probability of P (O, I | λ) from moment 1 to moment t. This α _ t (I) can be dynamically planned and computed. α _ 1 (I) = 1_ I * B _ I (O_1), 1 <= I <= N α _ t + 1 (j) = Σ _ I (α _ t (I) * a_ I _j) * B _j (O_t + 1) P (O | λ) = Σ _ I α _ T (I) here, the formula differs from the lower mark in the previous formula. The previous formula traverses each state sequence. I _1 indicates the first State of state sequence I, the forward algorithm and the back algorithm, only for the status, so 1 indicates the first status. In this way, α _ 1 to α _ T is obtained for a total of T times. 2 * N ^ 2 multiplication is required for each calculation, and the complexity is 2 T * N ^ 2. Formula Derivation of the original article: The backward algorithm is given below to solve this problem. Defines the backward factor, β _ t (I) = P (O_t + 1, O_t + 2,... O_T | I _t = I, λ ). The recurrence formula is as follows: β _ T (I) = 1, 1 <= I <= N. β _ t (I) = Σ _ j (a_ I _j) * B _j (O_t + 1) * β _ t + 1 (j), transferred from status I to status j, then, the symbol O_t + 1 is determined from the status j, and then the recursion P (O | λ) = Σ _ I primary _ I * B _ I (O_1) * β _ 1 (I) the complexity of the backward algorithm is the same as that of the forward algorithm. It is also 2 T * N ^ 2. 3. decoding and decoding problem: If HMM parameters are known, find the state sequence with the highest probability of generating a symbolic sequence. That is, the P (O, I | λ) with the highest probability ). In fact, you can use the previous direct method to solve this problem by using the forward and backward algorithms respectively. The direct method is to calculate each P (O, I | λ) and then take the maximum value. The forward and backward algorithms convert the sum in the formula to the maximum value. Changes to the forward algorithm: α _ 1 (I) = 1_ I * B _ I (O_1), 1 <= I <= N α _ t + 1 (j) = max {(α _ t (I) * a_ I _j)} * B _j (O_t + 1), 1 <= I <= N max {P (O, I | λ )} = max {α _ T (I)}, 1 <= I <= N maximum state sequence = {I _1, I _2 ,..., I _T}, where α _ t (I _t) = max {a_t (j)}, 1 <= j <= N backward algorithms are similar, which are ignored here. The common decoding algorithm is Viterbi, namely Viterbi Alogrithm, which is actually a change of the Forward Algorithm and changes the probability to-ln (probability). In this way, the maximum value is obtained by multiplication, it is used to calculate the minimum value by addition, and the calculation amount is greatly reduced. Original article formula derivation:
4. Learning
Learning problem: Calculate HMM parameters with the highest probability of a symbolic Sequence Based on the symbolic sequence and its related State sets.
There are two methods: the segmented kmeans (the segmental K-means algorithm) and the forward and backward algorithms (also known as the Baum-Welch Algorithm ).
The segmental K-means algorithm: adjusts λ = (a, B, cosine) by maximizing P (O, I | λ ), among them, I obtains the optimal state sequence based on the decoding method.
The Baum-Welch re-estimation formulas: Adjust λ = (a, B, callback) by adding P (o | λ) to a maximum value ). P (o | λ) is calculated based on the sum of P (O, I | λ) for all State sequences I. Therefore, this algorithm focuses on all State sequences, while segmental K-means focuses on the optimal state sequences.
4.1 segmentation K-means algorithm (the segmental K-means algorithm)
Assume that λ is the current parameter, λ is the new calculated parameter, I is the optimal state sequence calculated for λ, and I is the optimal state sequence calculated for λ, if P (O, I | λ) <p (O, I '| λ'), continue iteration and set λ to λ '. To train this model, we need some symbolic sequences. Assume that there are W symbols, and each symbol sequence is O = O1, O2,..., ot, And the length is T. Each symbol is assumed to be a D (> = 1) vector. This algorithm consists of the following steps:
In the first step, we randomly select n symbols (D-dimensional vectors) and divide each of the wt symbols into the class with the smallest Euclidean distance. In this way, N classes are generated. Each class is called a State (from 1 to n ). The division of the initial class does not determine the final hmm parameter, but determines the number of iterations required for the final hmm parameter. In our example, we select n symbol sequences evenly, so that the numbers of symbol sequences between the N symbol sequences are the same, and a symbol is selected from each symbol sequence, that is to say, select 1st symbols from the 1st sequences and 2nd symbols from the 2 sequences ,..., select the nth symbol from the nth symbol sequence. You can select based on your wishes.
Step 2: Calculate the initial probability and transfer probability, and estimate the ratio _ I and a_ I _j. CATEGORY _ I = the number of O1 in category I/The number of O1. This is easy to understand. For example, if there are initially w symbol sequences, there will be w O1, w denominator, and w molecules will be assigned to category I. A_ I _j = the number of O_t in category I and the number of O_t + 1 in Category j/The number of O_t in Category I.
Step 3: calculate the mean and variance of each State (that is, each category.
Step 4: estimate the probability of the observed state to the symbol. It is estimated by calculating the distribution of symbols in each State (category. It is assumed that the distribution of symbols follows the Gaussian distribution.
Step 5: Calculate the optimal state sequence I 'of each observed sequence based on the estimated HMM parameters '. If I 'is different from I, different Oi will be reassigned. For example, I' and I are different from each other on the 3rd elements, then O3 will be reassigned to the category corresponding to the third element of I.
Step 6: if there is a reallocation in step 2, jump to step 2 and iterate.
The segmented K-means algorithm converges to the state optimal likelihood function in some observation density functions and the Gaussian density functions we assume ".
4.2 forward and backward algorithms (Baum-Welch Algorithm)
This method first assumes an initial HMM model, and then uses the methods described below to improve the HMM Model to maximize P (O | λ. An initial HMM model can be constructed using any method, but we can use the first five steps of the segmented K-means algorithm to obtain a reasonable HMM estimation. In any case, we assume that an initial HMM is known. This algorithm maximizes P (O | λ) by adjusting the λ parameter. This optimization standard is called the maximum likelihood standard. P (O | λ) is called a likelihood function.
The following describes some calculation variables:
γ _ t (I) indicates the probability that t moment is in state I, and the numerator is the product of forward and backward factors.
E _ t (I, j) indicates the probability that t moments are in State I, t + 1 moment in State j.
The formula for parameter estimation is:
The formula of phase _ I should feel like phase _ I = gamma _ 1 (I), that is, the first moment is the probability of state I. (I don't know if the author is wrong, but I feel wrong)
The numerator of a_ I _j is the joint probability of the transition from the I state to the j state. The denominator is the probability of the I state, and the phase division is the transfer probability from the I state to the j state.
The B _j (k) molecule is the joint probability in the j state and the symbol is k. The denominator is the probability in the j state, and the Division happens to be the known j state, conditional probability with the output symbol k.
The calculation is divided into two steps: 1. Calculate λ according to λ; 2. If P (O | λ ')> P (O | λ ), update λ to λ, or stop the calculation.
The Baum-welch algorithm requires a lot of multiplication, so the value may easily overflow, which requires some possible processing techniques. The segmental K-means algorithm uses the Viterbi algorithm to generate I, so the overflow problem is not serious. The advantage of segmental K-means is that we sometimes focus more on the observed sequence generated by the optimal state sequence, but not on the observed sequence generated by all State sequences. In addition, the calculation of segmental K-means is small.