File Exchange

Forward Viterbi Algorithm

version 1.1 (1.83 KB) by

Forward Viterbi algorithm based on: http://en.wikipedia.org/wiki/Viterbi_algorithm

3.66667
4 Ratings

Updated

Forward Viterbi algorithm based on the Python code found at: http://en.wikipedia.org/wiki/Viterbi_algorithm

Also included is an example based on the one from the Wikipedia page for a simple 2-state model with 4 observations. To paraphrase:

Bob tells Alice his daily activities (observations) and Alice wants to determine the most likely weather each day (states). Since Alice lives far away, the weather is unknown to her (hidden). Assuming that the states behave as a Markov process, and the observations have a statistical dependency on the states, the Viterbi algorithm can find the most likely weather pattern (path).

http://en.wikipedia.org/wiki/Viterbi_algorithm

weike yin

GC

GC (view profile)

Dear sir
I run forward-viterbi with an observation sequence of 2 elements.
The output is sequence of 3 states and compute the probability of this sequence.
In fact the sequence of the best states is right but there is one element more and the probabilty correspond with the sequence with this extra state.
Sincerely yours

Sam Ham

Sam Ham (view profile)

The code works fine now, the previous bug was fixed, I just tested it.

Sam Ham

Justin

Justin (view profile)

foward_viterbi.m contains a bug not in the original python version. If the output is longer than 3 states then this line throws an error. The 2nd index to emit_p should be the position of the output token in the vector of possible output states, not the index into the observation vector.
p = emit_p(source_state,output) * trans_p(source_state,next_state);