Hidden Markov Model Implementation