/**************************************************************************/ /* File: hypothesize.cc */ /**************************************************************************/ /* Project: Continuous Speech Recognition Search Algorithms */ /* 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" void hypothesize_cc ( FILE *fp_in,HMM_Model *model,Score_Hyp *hypothesis, Score_Hyp *back_ptr, float_4 score ,int_2 start_time , int_2 word_index ) { // define local variables // HMM_State *state_ptr; HMM_State *model_states_ptr; HMM_State *temp = new HMM_State; HMM_Trans_State *trans_ptr = new HMM_Trans_State (); String state_symbol; Score_Hyp *ref_score_hyp; int_2 frm_ind = start_time; float_4 store = 0; int_2 count = 0; float_4 prob = 0; if ( frm_ind == 0 ) { state_symbol = (model->get_start_state_cc ())->get_out_symbol_cc (); } else { state_symbol = ((model->get_start_state_cc ())->get_prev_state_cc ())-> get_out_symbol_cc (); } model_states_ptr = model->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); hypothesis->add_score_hyp_cc (state_ptr,back_ptr,0.0,start_time,word_index ); HMM_Matrix **temp_mat = state_ptr->get_mean_cc (); int_2 test_vec_len = (temp_mat[0]->get_num_columns_cc ()); HMM_Matrix *test_vector = new HMM_Matrix (1,test_vec_len,0.0); // go to the point in file specified the start time // rewind (fp_in); fseek(fp_in, test_vec_len*start_time*(sizeof(float_4)), SEEK_SET); // create score_hyps for all input frame durations // while (fscanf (fp_in, "%f", &store) != EOF && (count <= 7)) { frm_ind++; test_vector->set_element_cc (0,0,store); // get the test vector from the input file // for (int_2 i=1; iget_num_columns_cc (); i++) { fscanf ( fp_in,"%f", &store ); test_vector->set_element_cc (0,i,store); } count++; 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 = hypothesis->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 = temp_hyp->get_next_hyp_cc ()) { if ( temp_hyp->get_timestamp_cc () == frm_ind - 1 && temp_hyp->get_word_index_cc () == word_index ) { 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 = hypothesis->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; trans_ptr = trans_ptr->get_next_transition_cc ()) { if (temp_hyp->get_timestamp_cc () == frm_ind -1) { state_symbol = trans_ptr->get_state_name_cc (); temp = model_states_ptr->find_state_cc (state_symbol); prob = fabs(log10(score)) + fabs(log10(temp->state_score_cc (test_vector))) + fabs(log10(state_ptr->get_trans_prob_cc (state_symbol))); hypothesis->add_score_hyp_cc (temp,temp_hyp,prob,frm_ind, word_index); } } } // this part is supposed to find all hypotheses which end in stop state // and then back trace for ( temp_hyp = hypothesis->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->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 ()); } } } }