I was working through HMM R package and used posterior as well as Viterbi algorithm:
R> hmm = initHMM(c("A","B"), c("L","R"), transProbs=matrix(c(.8,.2,.2,.8),2),
+ emissionProbs=matrix(c(.6,.4,.4,.6),2))
R> observations = c("L","L","R","R")
# Calculate posterior probablities of the states
R> posterior = posterior(hmm,observations)
R> print(posterior)
index
states 1 2 3 4
A 0.6037344 0.56639 0.43361 0.3962656
B 0.3962656 0.43361 0.56639 0.6037344
R> viterbi = viterbi(hmm,observations)
R> print(viterbi)
[1] "A" "A" "A" "A"
So in the above example if I would consider posterior results and take sequence of hidden states according to highest probability at each position, then I would get
"A" "A" "B" "B"
but the Viterbi algorithm tells me that the sequence is
"A" "A" "A" "A"
My question is which sequence should I trust and why?