HMM implementation the forward-backward algorithm