hmm forward/backward viterbi algs implementation