# Find Hidden States Underlying Given Emissions of HMM Process

Given the sequence of observations from a system with a known model, it is generically impossible to uniquely recover the corresponding sequence of unobservable states of the system. Mathematica 10 supports two commonly used criteria to find the "optimal" state sequence associated with the given observationsViterbi decoding and posterior decoding. The Viterbi decoded sequence maximizes the joint likelihood of the sequence of hidden states and emissions. The posterior decoded sequence individually maximizes the likelihood of being in the hidden state for each emission.

Construct an HMM with left-to-right topology and overlapping emission distributions.

 In:= Xp0 = 1; tm = {{5/6, 1/6, 0}, {0, 4/5, 1/5}, {0, 0, 1}}; hmm = HiddenMarkovProcess[p0, tm, {NormalDistribution[-1, 2/3], NormalDistribution[2, 1], NormalDistribution[5, 1/2]}];
 In:= XPlot[PDF[hmm, x] // Evaluate, {x, -4, 8}]
 Out= In:= Xobs = {-1.797, -0.859, 0.328, 3.853, 4.707, 4.872};

Find the most likely hidden-state sequence using Viterbi decoding.

 In:= Xvd = FindHiddenMarkovStates[obs, hmm]
 Out=  Find the sequence of individually most likely hidden states using posterior decoding.

 In:= Xpd = FindHiddenMarkovStates[obs, hmm, "PosteriorDecoding"]
 Out=  Decoding also works with multivariate emissions.

 In:= Xp0 = {3/5, 2/5}; tm = {{2/3, 1/3}, {1/4, 3/4}}; hmm = HiddenMarkovProcess[p0, tm, {MultivariateTDistribution[{{1, 1/2}, {1/2, 1}}, 8], MultivariateTDistribution[{{1, -2/3}, {-2/3, 1}}, 3]}];
 In:= XPlot3D[PDF[hmm, {x, y}], {x, -4, 4}, {y, -4, 4}]
 Out= In:= Xobs = {{-0.15, 0.63}, {0.03, -0.71}, {-0.93, -0.14}, {-1.36, 2.32}, {0.68, 0.88}};

Find the most likely state sequence using Viterbi decoding.

 In:= XFindHiddenMarkovStates[obs, hmm]
 Out= Find the sequence of individually most likely states using posterior decoding.

 In:= XFindHiddenMarkovStates[obs, hmm, "PosteriorDecoding"]
 Out= ## Mathematica

Questions? Comments? Contact a Wolfram expert »