HMM foward algorithm and viterbi algorithm