/**************************************************************************/ /* 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 // int_2 count = 0; float_4 prob = 0; float_4 store = 0; Score_Hyp *ref_score_hyp = NULL; Score_Hyp *temp_hyp = NULL; // the very first state // if ( start_time == 0 ) { start_time ++; } int_2 frm_ind = start_time; HMM_State *temp_state = model->get_start_state_cc (); String state_symbol = (temp_state->get_prev_state_cc ())->get_out_symbol_cc (); // states of the model involved // HMM_State *model_states_ptr = model->get_states_cc (); // initialize the list of score_hyps to the one having state element // as the start state of the model // HMM_State *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); // determine size of input vector // int_2 test_vec_len = (state_ptr->get_mean_cc ())[0]->get_num_columns_cc (); // read the inputs // HMM_Matrix *test_vector = new HMM_Matrix (1, test_vec_len, 1.0); // go to the point in file specified by the start time // fseek (fp_in, test_vec_len * start_time * (sizeof (float_4)), SEEK_SET); // create score_hyps for all allowed input frame durations // while ((fscanf (fp_in, "%f", &store) != EOF) && ((count < MAX_DUR))) { test_vector->set_element_cc (0, 0, store); // get the test_vector from the input file // for (int_2 i = 1; i < test_vec_len; i++) { fscanf ( fp_in, "%f", &store ); test_vector->set_element_cc (0, i, store); } count++; // 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); if (ref_score_hyp != NULL) { // go through the score_hyps generated during this frame // for (temp_hyp = ref_score_hyp->get_next_hyp_cc (); temp_hyp->get_timestamp_cc () != 0 ; temp_hyp = temp_hyp->get_next_hyp_cc ()) { if (((HMM_State *)temp_hyp->get_element_cc () == temp_state) && (temp_hyp->get_timestamp_cc () == frm_ind) && (temp_hyp->get_word_index_cc () == word_index)) { 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 (); } } } } } // increment frame count // frm_ind ++; // dummy index variable // HMM_Trans_State *trans_ptr = NULL; // expand the trellis for all states in this model // for (temp_hyp = hypothesis->get_next_hyp_cc (); temp_hyp->get_timestamp_cc () != 0; temp_hyp = temp_hyp->get_next_hyp_cc ()) { // create score_hyps for all transitions from the state // represented by the present score_hyp // if ((temp_hyp->get_word_index_cc () == word_index) && (temp_hyp->get_timestamp_cc () == frm_ind - 1)) { state_ptr = (HMM_State *)(temp_hyp->get_element_cc ()); for (trans_ptr = state_ptr->get_transition_cc (); trans_ptr != NULL; trans_ptr = trans_ptr->get_next_transition_cc ()) { prob = 0.0; int_2 time = frm_ind; state_symbol = trans_ptr->get_state_name_cc (); temp_state = model_states_ptr->find_state_cc (state_symbol); if (temp_state != model->get_stop_state_cc ()) { prob -= log10 (score) + log10 (temp_state->state_score_cc (test_vector)) + log10 (state_ptr->get_trans_prob_cc (state_symbol)); } else { prob -= log10 (score) + log10 (state_ptr->get_trans_prob_cc (state_symbol)); time --; } fprintf (stdout,"%s\n", temp_state->get_out_symbol_cc ()); hypothesis->add_score_hyp_cc (temp_state, temp_hyp, prob, time, word_index); } } } } }