hidden markov model and forward algorithm