A simple implementation of HMM