/**************************************************************************/ /* File: create_model.cc */ /**************************************************************************/ /* Project: Continuous Speech Recognition Search Algorithms */ /* Author: Neeraj Deshmukh, Aravind Ganapathiraju */ /* Class: EE 8993 Spring 1996 Date: April 1, 1996 */ /**************************************************************************/ /*======================================================================== This file creates the HMMs for the four test words in the grammer namely one, two, three and four. ========================================================================*/ /*------------------------------------------------------------------------ system and ISIP include files ------------------------------------------------------------------------*/ #include "test.h" /*------------------------------------------------------------------------ function definition to create models for given words ------------------------------------------------------------------------*/ void create_model_cc (FILE *model_file_ptr, FILE *mean_file_ptr, HMM_Model **model,int_2 num_of_models, int_2 num_of_states) { // local string variables // String data_string = new char[10]; String temp_string; // read the size of the mean vectors // int_2 size_of_mean; fscanf (mean_file_ptr, "%hd", &size_of_mean); //set mean values of output vectors of each state in each test model // HMM_Matrix **mean_vector = new HMM_Matrix*[9]; for (int_2 i = 0; i < 9; i++) mean_vector[i] = new HMM_Matrix(1,size_of_mean,0.0); int_2 vector_num = 0; float_4 data; while (fscanf (mean_file_ptr, "%s", data_string) != EOF) { data = atof(data_string); mean_vector[vector_num]->set_element_cc (0,0,data) ; for (int_2 i = 1; i < size_of_mean; i++) { fscanf (mean_file_ptr, "%f", &data); mean_vector[vector_num]->set_element_cc (0,i,data) ; } vector_num++; } // read the hmm models // int_2 num_model = 0; HMM_State *model_state_ptr = NULL; HMM_State *curr_state = NULL; HMM_State *tran_state = NULL; float_4 prob_trans ; float_4 *temp_weight = NULL; HMM_Matrix **temp_vector = NULL; int_2 num_mix = 0; while (fscanf (model_file_ptr, "%s", data_string) != EOF) { if (strcmp (data_string, "----") == 0) { // find the current model states // model_state_ptr = model[num_model]->get_states_cc(); } else if (data_string[0] == 'N') { model_state_ptr = model[num_model]->get_states_cc(); temp_string = data_string + 5; model[num_model]->set_model_symbol_cc (temp_string); num_model++; } else if (data_string[0] == '$') { temp_string = data_string + 1; curr_state = model_state_ptr->add_state_cc(temp_string); // if state already exists make it the current state // if (curr_state == NULL) curr_state = model_state_ptr->find_state_cc (temp_string); // read the mean vector for the state // fscanf(model_file_ptr, "%s", data_string); num_mix = atoi (data_string); curr_state->set_num_mix_cc (num_mix); // setting the mixture weights // if (num_mix > 1) { temp_weight = new float_4[num_mix]; for (int_2 i = 0; i < num_mix; i++) { fscanf (model_file_ptr, "%s", data_string); temp_weight[i] = atof (data_string); } curr_state->update_mix_weights_cc ( temp_weight ); delete [] temp_weight; temp_weight = NULL; } else fscanf (model_file_ptr, "%s", data_string); // read in the mean vectors // temp_vector = new HMM_Matrix*[num_mix]; for (int_2 i = 0; i < num_mix; i++) { fscanf(model_file_ptr,"%s",data_string); temp_vector[i] = mean_vector[atoi(data_string)]; } curr_state->update_mean_cc (temp_vector); } // now fill in all possible transitions // else if (strcmp (data_string, "->") == 0) { // read the transition-to state // fscanf (model_file_ptr, "%s", data_string); // increment pointer to remove the identifier // temp_string = data_string + 1; // create new state if it doesn't exist already // tran_state = model_state_ptr->add_state_cc (data_string); // if it already exists make it the trans_state // if (tran_state == NULL) tran_state = model_state_ptr->find_state_cc (data_string); // now read the score of this transition // fscanf (model_file_ptr, "%s", data_string); prob_trans = atof (data_string); // add this to the transition linked list from the current state // curr_state->add_trans_state_cc (tran_state, prob_trans); } } // free memory // delete [] data_string; delete [] mean_vector; }