Categories &

Functions List

Function Reference: hmmdecode

statistics: pstates = hmmdecode (sequence, transprob, outprob)
statistics: [pstates, logpseq] = hmmdecode (…)
statistics: [pstates, logpseq, fs, bs, s] = hmmdecode (…)
statistics: […] = hmmdecode (…, "symbols", symbols)

Posterior state probabilities of a hidden Markov model.

Calculate the posterior state probabilities of the sequence sequence from a hidden Markov model. The posterior state probabilities are the conditional probabilities of being in each state given the whole observed sequence. The model assumes that the generation starts in state 1 at step 0 but does not include step 0 in the sequence.

Arguments

  • sequence is a 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

  • pstates is the matrix of posterior state probabilities. It has one row for each state and one column for each element of sequence. pstates(i, j) is the conditional probability that the model is in state i when it generates the j-th output of sequence, given that sequence is emitted.
  • logpseq is the logarithm of the probability of the sequence sequence.
  • fs and bs are the scaled forward and backward probabilities, respectively, and s is the vector of scale factors used to keep the computation numerically stable.

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.

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);
 pstates = hmmdecode (sequence, transprob, outprob);

 symbols = {"A", "B", "C"};
 [sequence, states] = hmmgenerate (25, transprob, outprob, ...
                                   "symbols", symbols);
 pstates = hmmdecode (sequence, transprob, outprob, "symbols", symbols);

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: hmmdecode

Posterior probability of each state at every step of an observed sequence.

 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 = hmmgenerate (10, transprob, outprob);
 [pstates, logpseq] = hmmdecode (sequence, transprob, outprob)
pstates =

 Columns 1 through 8:

   9.9008e-01   9.8161e-01   9.7158e-01   9.5646e-01   9.3091e-01   8.8591e-01   8.0557e-01   6.6150e-01
   9.9188e-03   1.8395e-02   2.8422e-02   4.3540e-02   6.9089e-02   1.1409e-01   1.9443e-01   3.3850e-01

 Columns 9 and 10:

   6.3524e-01   5.6165e-01
   3.6476e-01   4.3835e-01

logpseq = -17.750