The Viterbi algorithm is a special, but most widely used, dynamic programming algorithm. With dynamic programming, you can solve the shortest path problem in any diagram. The Viterbi algorithm is proposed for a special graph-fence Network (Lattice) with the problem of directed graph shortest path. It is important because it can be used to decode any problem that is described using the implied Markov model.
If the user input pinyin is y1,y2,..., yn, the corresponding Chinese character is x1,x2,..., xn, according to the probability formula:
The input sequence is Y1,y2,..., YN, and their implied sequence is x1,x2,..., XN, which can be described by the process:
Figure 1 An implied Markov model for the Viterbi algorithm
Now the output of each state of this Markov chain is fixed, but the value of each state can vary. For example, the output of the word "Zhong" can Be "medium", "species" and many other words. A symbol Xij represents the J possible value of State XI. If you expand each state according to a different value, you get the following fence network:
Figure 2 Fence Network
In, each state has 3 or 4 values, and of course they can have any value in practice.
The summary algorithm is as follows:
The first step, starting from point s, for each node of the first state X1, it may be assumed that there are N1 to calculate s to their distance d (s,x1i), where x1i represents the node of any State 1.
In the second step, for all nodes in the second state X2, the shortest distance from s to them is calculated. For a particular node x2i, the path from S to it can go through any node in the N1 of State 1 x1i, of course, the corresponding path length is d (s,x2i) = d (s,x1j) + D (x1j,x2i). Since J has the possibility of N1, we have to calculate each one and then find the minimum value. That
D (s,x2i) = Min D (s,x1j) + D (x1j,x2i)
This requires a N1 calculation for each node in the second state. Assuming that the state has N2 nodes, the distance of these nodes of S is counted once and there is an O (N1 n2) calculation.
Next, similar to the appeal method from the second state to the third State, go to the last state, the entire network to get the shortest path from beginning to end. Complexity of O (N· d^2).
Reference books
Http://www.cnblogs.com/ryuham/p/4686594.html
Viterbi Algorithm Basics