Implemention HMM