Categories &

Functions List

Function Reference: hmmviterbi

statistics: vpath = hmmviterbi (sequence, transprob, outprob)
statistics: vpath = hmmviterbi (…, "symbols", symbols)
statistics: vpath = hmmviterbi (…, "statenames", statenames)

Viterbi path of a hidden Markov model.

Use the Viterbi algorithm to find the Viterbi path of a hidden Markov model given a sequence of outputs. The model assumes that the generation starts in state 1 at step 0 but does not include step 0 in the generated states and sequence.

Arguments

  • sequence is the vector of length len of given outputs. The outputs must be integers ranging from 1 to columns (outprob).
  • transprob is the matrix of transition probabilities of the states. transprob(i, j) is the probability of a transition to state j given state i.
  • outprob is the matrix of output probabilities. outprob(i, j) is the probability of generating output j given state i.

Return values

  • vpath is the vector of the same length as sequence of the estimated hidden states. The states are integers ranging from 1 to columns (transprob).

If "symbols" is specified, then sequence is expected to be a sequence of the elements of symbols instead of integers ranging from 1 to columns (outprob). symbols can be a cell array.

If "statenames" is specified, then the elements of statenames are used for the states in vpath instead of integers ranging from 1 to columns (transprob). statenames can be a cell array.

Examples

 
 transprob = [0.8, 0.2; 0.4, 0.6];
 outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1];
 [sequence, states] = hmmgenerate (25, transprob, outprob);
 vpath = hmmviterbi (sequence, transprob, outprob);

 symbols = {"A", "B", "C"};
 statenames = {"One", "Two"};
 [sequence, states] = hmmgenerate (25, transprob, outprob, ...
                      "symbols", symbols, "statenames", statenames);
 vpath = hmmviterbi (sequence, transprob, outprob, ...
         "symbols", symbols, "statenames", statenames);

References

  1. Wendy L. Martinez and Angel R. Martinez. Computational Statistics Handbook with MATLAB. Appendix E, pages 547-557, Chapman & Hall/CRC, 2001.
  2. Lawrence R. Rabiner. A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition. Proceedings of the IEEE, 77(2), pages 257-286, February 1989.

Source Code: hmmviterbi

Most likely (Viterbi) state path for a two-state, three-symbol model.

 transprob = [0.8, 0.2; 0.4, 0.6];
 outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1];
 sequence = [1, 2, 1, 1, 3, 2, 3, 1, 2, 3];
 vpath = hmmviterbi (sequence, transprob, outprob)
vpath =

   1   1   2   2   1   1   1   1   1   1

The state path can also be reported using custom state names.

 transprob = [0.95, 0.05; 0.10, 0.90];
 outprob = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6; 1/10, 1/10, 1/10, 1/10, 1/10, 1/2];
 [sequence, states] = hmmgenerate (12, transprob, outprob, ...
                                   "statenames", {"fair", "loaded"});
 vpath = hmmviterbi (sequence, transprob, outprob, ...
                     "statenames", {"fair", "loaded"})
vpath =
  1x12 cell array

Columns 1 through 10:

    {'fair'}    {'fair'}    {'fair'}    {'fair'}    {'fair'}    {'fair'}    {'fair'}    {'fair'}    {'fair'}    {'fair'}    

Columns 11 through 12:

    {'fair'}    {'fair'}