Finished HMM with a Langrangian term