This is a rather simple, possibly naive, implementation of a discrete Hidden Markov Model with emissions given by a probability table.
There are libraries implementing this algorithm with many more features and most likely optimization as well. You should probaby use those.
- hmmlearn: hmmlearn is a set of algorithms for unsupervised learning and inference of Hidden Markov Models.
For supervised learning use:
- seqlearn: seqlearn is a sequence classification toolkit for Python. It is designed to extend scikit-learn and offer as similar as possible an API.
- Lawrence C. Rabiner: A tutorial on Hidden Markov Models and selected applications in speech recognition.
- Mark Stamp: A revealing introduction to Hidden Markov Models.
- Christopher Bishop: Pattern recognition and machine learning, chapter 13