hidden markov model python from scratch