Viterbi algorithm (Belief propagation for directed graphical model) for HMM MAP inference
demo.m
# This is the example from wiki page (http://en.wikipedia.org/wiki/Viterbi_algorithm)
# latent states are 1:Rainy, 2:Sunny
# observe states are 1:walk, 2:shop, 3:clean
s = [0.6, 0.4];
P = [0.7, 0.3;
0.4, 0.6];
E = [0.1, 0.4, 0.5;
0.6, 0.3, 0.1];
x = [1,2,3,1,1,1,3,3];
[z,v] = viterbi(x, s, P, E);