Probabilistic Finite State Machine in Python