viterbi function

Viterbi algorithm for decoding the most likely state sequence