/**************************************************************************/ /* File: exhaust_search.cc */ /**************************************************************************/ /* Project: Continuous Speech Recognition Search Algorithms */hypoth->get_next_hyp_cc /* Author: Neeraj Deshmukh, Aravind Ganapathiraju */ /* Class: EE 8993 Spring 1996 Date: April 2, 1996 */ /**************************************************************************/ /*======================================================================== This file gives the scores off all possible state sequences through a model given a start and end state. ========================================================================*/ /*------------------------------------------------------------------------ system and ISIP include files ------------------------------------------------------------------------*/ #include "test.h" main (int argc, char **argv) { if (argc != 4) exit (-1); FILE *fp_mean = fopen (argv[1],"r"); FILE *fp_model = fopen (argv[2],"r"); FILE *fp_in = fopen (argv[3],"r"); // define local variables // HMM_State *state_ptr; HMM_State *model_states_ptr; HMM_State *temp = new HMM_State; HMM_Trans_State *trans_ptr; String state_symbol; Score_Hyp *hypoth = new Score_Hyp (); Score_Hyp *ref_score_hyp; // Score_Hyp *back_hyp = new Score_Hyp (); int_2 frm_ind = 0; float_4 store = 0; float_4 score = 0; HMM_Model **model = new HMM_Model*[NUM_OF_MODELS]; for (int_2 i = 0; i < NUM_OF_MODELS; i++) { model[i] = new HMM_Model ("",NUM_OF_STATES); } // create the models // create_model_cc ( fp_model, fp_mean, model, NUM_OF_MODELS, NUM_OF_STATES ); state_symbol = (model[4]->get_start_state_cc ())->get_out_symbol_cc (); model_states_ptr = model[4]->get_states_cc (); // initialize the list of score_hyps to the one with state as start state // of the model state_ptr = model_states_ptr->find_state_cc(state_symbol); int_2 test_vec_len = (state_ptr->get_mean_cc ()-> get_num_columns_cc ()); HMM_Matrix *test_vector = new HMM_Matrix (1,test_vec_len,0.0); hypoth->add_score_hyp_cc (state_ptr,NULL,0.0,frm_ind); // create score_hyps for all input frame durations // while (fscanf (fp_in, "%f", &store) != EOF) { frm_ind++; test_vector->set_element_cc (0,0,store); // get the test_vector from the input file // for (int_2 i=1; iget_mean_cc ()-> get_num_columns_cc (); i++) { fscanf ( fp_in,"%f", &store ); test_vector->set_element_cc (0,i,store); } HMM_State *temp_state; // find all score hyps representing the same state in the HMM // for ( temp_state= model_states_ptr->get_next_state_cc (); temp_state != NULL; temp_state = temp_state->get_next_state_cc () ) { ref_score_hyp = hypoth->find_score_hyp_cc ( temp_state, frm_ind - 1); if (ref_score_hyp != NULL) { // go through the score_hyps generated during the previous frame // Score_Hyp *temp_hyp; for ( temp_hyp = ref_score_hyp->get_next_hyp_cc (); temp_hyp != NULL && temp_hyp->get_timestamp_cc () == frm_ind - 1; temp_hyp = temp_hyp->get_next_hyp_cc ()) { if ( ((HMM_State *)temp_hyp->get_element_cc ()) == temp_state) { if ( temp_hyp->get_path_score_cc () <= ref_score_hyp->get_path_score_cc () ) { ref_score_hyp->remove_score_hyp_cc (); ref_score_hyp = temp_hyp; } else { temp_hyp->remove_score_hyp_cc (); } } } } } Score_Hyp *temp_hyp; for ( temp_hyp = hypoth->get_next_hyp_cc (); temp_hyp != NULL; temp_hyp = temp_hyp->get_next_hyp_cc ()) { state_ptr = (HMM_State *)(temp_hyp->get_element_cc ()); // create score_hyps for all transitions from the state // represented by the present score_hyp // for ( trans_ptr = state_ptr->get_transition_cc (); trans_ptr != NULL && temp_hyp->get_timestamp_cc () == frm_ind -1; trans_ptr = trans_ptr->get_next_transition_cc ()) { state_symbol = trans_ptr->get_state_name_cc (); temp = model_states_ptr->find_state_cc (state_symbol); score = fabs ((log10(temp->state_score_cc (test_vector)))) + fabs (log10(state_ptr->get_trans_prob_cc (state_symbol))); hypoth->add_score_hyp_cc (temp,temp_hyp,score,frm_ind); } } // this part is supposed to find all hypotheses which end in stop state // and then back trace for ( temp_hyp = hypoth->get_next_hyp_cc (); temp_hyp != NULL; temp_hyp = temp_hyp->get_next_hyp_cc ()) { temp = (HMM_State *)temp_hyp->get_element_cc (); state_symbol = temp->get_out_symbol_cc (); if ( temp_hyp->get_timestamp_cc () == (frm_ind) && strcmp (state_symbol, (model[4]->get_stop_state_cc()) ->get_out_symbol_cc ()) == 0 ) { temp_hyp->hyp_backtrace_cc (); fprintf ( stdout, "path score is %f \n", temp_hyp->get_path_score_cc ()); } } } /* Score_Hyp *temp_hyp; for (temp_hyp = hypoth->get_next_hyp_cc (); temp_hyp != NULL; temp_hyp = temp_hyp->get_next_hyp_cc ()) { temp = (HMM_State *)temp_hyp->get_element_cc (); fprintf(stdout,"%s ---> ", temp->get_out_symbol_cc ()); fprintf(stdout," %i ", temp_hyp->get_timestamp_cc ()); fprintf(stdout," %f \n", temp_hyp->get_path_score_cc ()); back_hyp = temp_hyp->get_back_ptr_cc (); if (back_hyp != NULL) { state_ptr = (HMM_State *)back_hyp->get_element_cc (); fprintf(stdout,"back pointer is %s, %i \n\n", state_ptr->get_out_symbol_cc (), back_hyp->get_timestamp_cc ()); } } */ delete [] argv; delete [] model; fclose(fp_mean); fclose(fp_model); fclose(fp_in); }