Viterbi Algorithm - Pseudocode

Pseudocode

Here is some necessary set up for the problem. Given the observation space, the state space, a sequence of observations, transition matrix of size such that stores the transition probability of transiting from state to state, emission matrix of size such that stores the probability of observing from state, an array of initial probabilities of size such that stores the probability that .We say a path is a sequence of states that generate the observations .

In this dynamic programming problem, we construct two 2-dimensional tables of size . Each element of, stores the probability of the most likely path so far with that generates . Each element of, stores of the most likely path so far for

We fill entries of two tables by increasing order of .

, and
INPUT: The observation space, the state space, a sequence of observations such that if the observation at time is, transition matrix of size such that stores the transition probability of transiting from state to state, emission matrix of size such that stores the probability of observing from state, an array of initial probabilities of size such that stores the probability that OUTPUT: The most likely hidden state sequence A01 function VITERBI( O, S,π,Y,A,B ) : X A02 for each state si do A03 T1πiBi A04 T2←0 A05 end for A06 for i2,3,...,T do A07 for each state sj do A08 T1← A09 T2← A10 end for A11 end for A12 zT← A13 xT←szT A14 for iT,T-1,...,2 do A15 zi-1←T2 A16 xi-1szi-1 A17 end for A18 return X A19 end function

Read more about this topic:  Viterbi Algorithm