Just a little bit, some feeling, not in depth, make a record.
Reference: Hidden Markov (HMM), front/back algorithm, Viterbi algorithm re-summary
Who can explain the Viterbi algorithm in layman's?
The 26th chapter of the second edition of the Beauty of mathematics
The structure of this article:
1.HMM three elements
2. Viterbi algorithm
3. Concise examples
Hmm three elements:
1. Initial probability distribution π
Z1 may be State 1, State 2 ... State n, so Z1 has an n-point distribution:
|
Z1 |
Status 1 |
Status 2 |
... |
Status n |
|
Probability |
P1 |
P2 |
... |
Pn |
That is:the Z1 corresponds to a vector of n-dimensions.
the above-mentioned vector of n-dimensional is the initial probability distribution, remember to do π.
2. State transition Matrix A
But Z2 can not simply "ibid" finished, because Z2 and Z1 is not independent, so Z2 is the probability of State 1 has: Z1 is the State 1 o'clock Z2 is the state of 1,Z1 is the state 2 o'clock Z2 is the state 1,..., Z1 is the state n when Z2 is state 1, so is The following table
|
Z2
Z1 |
Status 1 |
Status 2 |
... |
Status n |
|
Status 1 |
P11 |
P12 |
... |
/11 |
|
Status 2 |
P21 |
P22 |
... |
/21 |
|
... |
... |
... |
... |
... |
|
Status n |
Pn1 |
Pn2 |
... |
Pnn |
that is:z1->z2 corresponds to a n*n matrix.
similarly:Zi-zi+1 corresponds to a matrix of n*n.
The above n*n matrices are called state transition matrices, denoted by an*n.
Of course, if you really want to say it, the state transfer matrix of Zi-zi+1 must be different, but in practice, these state transition matrices are generally set as the same, that is, there is only one state transition matrix .
3. Observation Matrix B
If for Zi there is: State 1, State 2, ..., state n, then each state of the Zi will be produced from the following m observations: Observation 1, observation 2, ..., observing m, so there is the following matrix:
|
X
Z |
Observation 1 |
Observation 2 |
... |
Observation m |
|
Status 1 |
P11 |
P12 |
... |
P1m |
|
Status 2 |
P21 |
P22 |
... |
P2m |
|
... |
... |
... |
... |
... |
|
Status n |
Pn1 |
Pn2 |
... |
Pnm |
This can be represented by a n*m matrix, which is the observation matrix, which is recorded as Bn*m.
Since hmm can be described with the above π,a,b, we can say that the hmm is determined by the initial probability distribution π, the state transition probability distribution A and the observation probability distribution B, in order to facilitate the expression, the A, b,π with λ, namely:
Λ= (A, b,π)
Viterbi Algorithm
The Viterbi algorithm is a special but most widely used dynamic programming algorithm, which is proposed for the shortest path problem of the directed graph (Lattice) of the fence network. All the problems described using the implied Markov model can be decoded using the Viterbi algorithm, including today's digital communication, speech recognition, machine translation, pinyin to Chinese characters, word segmentation and so on.
1. Basic overview
(1) If the probability of the largest path P (or shortest path) through a point, such as the X22, then this path from the starting point S to X22 this path Q, must be the shortest path between S to X22. Otherwise, using S to X22 shortest path R instead of Q constitutes a shorter path than P, which is obviously contradictory.
(2) The path from S to E must go through a state at the time of the first moment, assuming that there is a K state at the moment, then if the shortest path of all k nodes from S to I state is recorded, the final shortest path must pass one of them. This way, at any moment, only a very limited shortest path is considered.
(3) in conjunction with the above two points, it is assumed that when we enter the state i+1 from state I, the shortest paths from S to state I have been found and recorded on these nodes, then the shortest path of K nodes from the starting point S to the previous state I is computed, and from this K node to the Xi+1,j The distance can be.
2. Summary
(1) Starting from the point S, for the first state X1 each node, it may be assumed that there are N1, calculate S to their distance d (s,x1i), where x1i represents a node of any State 1. Because there is only one step, these distances are s to their respective shortest distances.
(2) For all nodes of the second state X2, the shortest distance from S to them is calculated. For the characteristic node x2i, the path from S to it can be x1i by any node in the N1 of State 1, and the corresponding path length is d (s,x2i) = d (s,x1i) + D (x1i,x2i). Since J has the possibility of N1, we have to calculate each one to find the minimum value. That
D (s,x2i) = Mini=1,n1 D (s,x1i) + D (x1i,x2i)
This requires a N1 multiplication calculation for each node in the second state. Assuming that this state has a N2 section
Point, the distance of these nodes of S is counted once, there is O (N1 n2) times calculation.
(3) Next, similar to the above method from the second state to go to the third State, go to the last state, the entire grid to get the shortest path from beginning to end. The complexity of each step is proportional to the product of the respective number of nodes of the neighboring two state Si and si+1 ni,ni+1, i.e. O (NI ni+1)
(4) Assuming that the most nodes in the implied Markov chain have a D node, that is, the width of the entire grid is D, then any step of the complexity is not more than O (D2), because the grid length is N, so the complexity of the entire Viterbi algorithm is O (N· D2).
Concise Example
1. Topic Background:
Once there was a village where people in the village had only two possible physical conditions: health or fever.
Assuming that the village's people do not have a thermometer or Baidu this magical thing, his only way to judge his physical condition is to my idol Kingzhong's small clinic to inquire.
The moon by asking the villagers feel, judge her condition, and then assume that the villagers will only answer normal, dizzy or cold.
One day the village Obama donkey went to the moon to inquire.
The first day she told her she felt normal.
The next day she told the Moon she was feeling a little cold.
The third day she told the moon she felt a little dizzy.
So the question is, how can the moon infer a physical state of the donkey in the three days according to the description of the donkey?
For this month's son Baidu search Google, a wild search, found the Viterbi algorithm just can solve the problem. The moon is happy.
2. Known conditions:
Implied physical state = {health, fever}
Observable feeling state = {Normal, cold, dizzy}
The probability distribution of the body state of a donkey pre-sentenced by the Moon = {health: 0.6, Fever: 0.4}
This is the initial state sequence.
The moon thinks of a donkey. Transformation probability distribution of healthy state
Health, Health: 0.7,
Health, Fever: 0.3,
Fever--Health: 0.4,
Fever with fever: 0.6
}
This allows you to list the corresponding state transition matrices.
The probability distribution of the sensation of a donkey in the condition of the corresponding health condition is considered by the Moon = {
Healthy, Normal: 0.5, Cold: 0.4, dizziness: 0.1;
Fever, Normal: 0.1, Cold: 0.3, dizziness: 0.6
}
This makes it possible to list the corresponding observation matrices.
From the above we can find that the three elements of the HMM are ready, the following is the problem solved.
A donkey for three days of body feeling in sequence is: normal, cold, dizziness.
3. Title:
Known as above, Beg: Donkey This three days of physical health change process is how? in the case of known observation sequence and HMM model, the state sequence is obtained.
4. Process:
- Initialization On the first day, for each state (health or fever), find out the probability of the first day that the body feels normal:
P (first day health) = P (Normal | health) *p (health | initial condition) = 0.5 * 0.6 = 0.3
P (first day fever) = P (Normal | fever) *p (Fever | initial condition) = 0.1 * 0.4 = 0.04
- The next day, for each state, the maximum probability of the cold being observed on the first day of the condition for health or fever. In the Viterbi algorithm, we first ask for the maximum probability of the path of a single path, and then multiply the observed probability.
P (second day health) = max{0.3*0.7, 0.04*0.4}*0.4=0.3*0.7*0.4=0.084 At this point we need to record the previous state of the path with the largest probability, that is, the previous state of the 0.084 path, We wrote down on the Little laptop, the first day of health.
P (next day Fever) =max{0.3*0.3, 0.04*0.6}*0.3=0.027, the same on the 0.027 path, the first day is also healthy.
- The third day was the same as the next day.
P (third day health) =max{0.084*0.7, 0.027*0.4}*0.1=0.00588, on this path, the next day is healthy.
P (third day Fever) =max{0.084*0.3, 0.027*0.6}*0.6=0.01512, on this path, the next day is healthy.
- The last day of the state probability distribution is the probability of the optimal path, that is, P (optimal) = 0.01512, so that we can get the end of the optimal path, is a healthy
- Start backtracking from the optimal path. Please look at our little books, in the third day of the Fever probability, our little book is written on the second day of health, well, the next day should be a healthy state, and then in the second day of health, we recorded the first day is healthy. In this way, our state sequence inverse is introduced. That is: Health, health, fever .
- Let's draw a brief picture:
Here the arrow pointing is a backtracking query the process of small books, when we write algorithms, in fact, we have to note that each of the most probability of a single path to the previous state recorded.
Hmm and Veterbi algorithm (i.)