Implements a Hidden Markov Model