Function to generate initial HMM automatically