Python implementation of a generic HMM model