📄 hsrch_14.cc
字号:
if (tmp_context != (Context*)NULL) { delete tmp_context; } // get the subgraph start vertex // tmp_vert = (sl_lower.getSubGraph((long)*subgr_ind)).getStart(); // loop over all paths in the subgraph and create new // instances in the next level // for (boolean more_paths = tmp_vert->gotoFirst(); more_paths; more_paths = tmp_vert->gotoNext()) { // initialize central vertex of the context // tmp_arc = tmp_vert->getCurr(); // create a new instance, we store the extra instance so we // can later view the scores as they are added. this can // be changed later for efficiency // tmp_instance = new Instance(*new_instance); tmp_instance->setFrame((ulong)current_frame_d); // update the score with the arc score // tmp_score = tmp_instance->getScore() + tmp_arc->getWeight(); tmp_instance->setScore(tmp_score); // change the history // changeHistory(tmp_instance, ascend, level_num_a, tmp_vert); tmp_instance->setSymbol(context_pool_d.setLastAndAllocate(tmp_instance->getSymbol(), tmp_arc->getVertex())); // add the instance to current level's instance list // addInstance( level_num_a + 1 , new_instance, tmp_instance, pruning); } // clean the memory // if (new_instance->getRefCount() < 1 && new_instance != curr_instance_a) { delete new_instance; } // new instance generated // return true; } // central vertext is at a lower level , ready for propagate down // set the nxt level context as start-start+curr_central_context // the start will be treated in the propagte up stage // else if (curr_context->getCentralVertex()->getItem()-> getSearchLevel()->getLevelIndex() > level_num_a ) { // get the central vertex // tmp_vert = curr_context->getCentralVertex(); // new instance // new_instance = new Instance(*curr_instance_a); new_instance->setFrame((ulong)current_frame_d); // currently , different level has different left context node // we must set it to the correct level // tmp_vert = tmp_vert->getItem()->getSearchLevel()-> getSubGraph((long)0).getStart(); // change the history // changeHistory(new_instance, ascend, level_num_a, tmp_vert); new_instance->setSymbol(context_pool_d.setLastAndAllocate(new_instance->getSymbol(), curr_context->getCentralVertex())); // add the instance to current level's instance list // addInstance( level_num_a + 1 , curr_instance_a, new_instance, pruning); // new instance generated // return true; } // error, can not happen // else { return Error::handle(name(), L"ascendInstance: Wrong instance", Error::ARG, __FILE__, __LINE__); } // exit gracefully // return true; }// method: propagateLexInstancesUp//// arguments:// long level_num: (input) the level for which we will propagate instances//// return: logical error status//// propagate all instances up the hierarchy. only instances at the end of a// each subgraph are considered//boolean HierarchicalSearch::propagateLexInstancesUp(long level_num_a) { // algorithm for this method: propagateLexInstancesUp // define local variables // boolean status = false; boolean end_loop = false; Instance* curr_instance = (Instance*)NULL; Context useless; // make sure there is at least one instance to propagate // if (instance_lists_d(level_num_a).length() < 1) { return false; } // loop over all current instances and create the next level's instances. // all new instances will go at the end of the list so we set the mark to // tell us when to stop propagating // instance_lists_d(level_num_a).gotoLast(); instance_lists_d(level_num_a).setMark(); instance_lists_d(level_num_a).gotoFirst(); while (!end_loop) { // loop until we reached the marked element // end_loop = instance_lists_d(level_num_a).isMarkedElement(); // get the current first instance from the list // instance_lists_d(level_num_a).removeFirst(curr_instance); // if the instance is inactive then delete it and its backpath if necessary // if (!curr_instance->isActive()) { if (search_mode_d == DECODE) { Instance::deleteInstance(curr_instance, true); } } // else, extend paths and update scores // else { // if we propagate new instances, but not sure they are pruned or not // if ( ascendInstance(level_num_a, curr_instance) ) { // if all new instances are pruned // bump the current instance off of the instance list // if (curr_instance->getRefCount() < 1) { // delete the instance // if (search_mode_d == DECODE) { Instance::deleteInstance(curr_instance, true); } } else { // now, there is at least one new instance survived // status = true; } instance_lists_d(level_num_a).gotoFirst(); } // when the instance is NOT at the end of the current subgraph we keep // it at this level for now it gets propagated forwards during the // evaluateLexInstanceModels function // else { float curr_score = curr_instance->getScore(); // update the maximal instance score for the beam pruning // if(getSearchLevel(level_num_a).useBeam() && (curr_score > max_instance_scores_d(level_num_a)) ) { max_instance_scores_d(level_num_a) = curr_score; } // keep the instance on this level // instance_lists_d(level_num_a).insertLast(curr_instance); instance_lists_d(level_num_a).gotoFirst(); } } } // exit gracefully // return status; }// method: propagateLexInstancesDown//// arguments:// long level_num: (input) the level for which we will propagate LexInstances//// return: logical error status//// propagate all instances down the hierarchy. //boolean HierarchicalSearch::propagateLexInstancesDown(long level_num_a) { // algorithm for this method: // define local variables // Instance* curr_instance = (Instance*)NULL; boolean status = false; boolean end_loop = false; // make sure there is at least one instance to propagate // if (instance_lists_d(level_num_a).length() < 1) { return false; } // switch on whether we are at the lowest level or not // // if we are not at the lowest level, push instances down the hierarchy - // there should be no instances left at this level when we are done // instance_lists_d(level_num_a).gotoLast(); instance_lists_d(level_num_a).setMark(); instance_lists_d(level_num_a).gotoFirst(); if (level_num_a != getNumLevels() - 1) { // loop over all current instances and create the next level's instances // while (!end_loop) { // loop until we reached the marked element // end_loop = instance_lists_d(level_num_a).isMarkedElement(); // get the current vertex in the search graph // instance_lists_d(level_num_a).removeFirst(curr_instance); // delete this instance if it is now inactive // if (!curr_instance->isActive()) { // bump the current instance off of the instance list and delete it // and its backpath if necessary // if (search_mode_d == DECODE) { Instance::deleteInstance(curr_instance, true); } } // if it is active then propagate it // else { // if central is NULL, propagate down // if (curr_instance->getSymbol()->getCentralVertex() == (GraphVertex<SearchNode>*)NULL) { if ( (level_num_a + 1) == (getNumLevels() - 1) ){ instance_valid_hyps_d.insertLast(curr_instance); // go for next instance // continue; } } // if we propagate new instances, but not sure they are pruned or not // if ( descendInstance(level_num_a, curr_instance) ) { // if all new instances are pruned // bump the current instance off of the instance list // if (curr_instance->getRefCount() < 1) { if (search_mode_d == DECODE) { Instance::deleteInstance(curr_instance, true); } } else { // now, there is new instance survived // status = true; } instance_lists_d(level_num_a).gotoFirst(); } // else if no new instances can be generated. // else { float curr_score = curr_instance->getScore(); // update the maximal instance score for the beam pruning // if(getSearchLevel(level_num_a).useBeam() && (curr_score > max_instance_scores_d(level_num_a)) ) { max_instance_scores_d(level_num_a) = curr_score; } // keep the instance on this level // instance_lists_d(level_num_a).insertLast(curr_instance); instance_lists_d(level_num_a).gotoFirst(); } } } } // exit gracefully // return status;}// method: networkDecoder//// arguments:// Vector<VectorFloat>& fe: (input) vector of inputs// long num_frames: (input) the number of steps to move forward//// return: logical error status//// decode part (or all) of the search space//boolean HierarchicalSearch::networkDecoder(Vector<VectorFloat>& fe_a, long num_frames_a) { // if we haven't started the search then we need to initialize the // search // if ((long)current_frame_d == DEF_START_FRAME) { initializeNetworkDecoder(); } // determine the number of frames to loop through. If the user specifies // to loop over all frames then the frame_num is set to a default value // so that the decoder loops indefinitely // long frame_num = 0; if (num_frames_a == DEF_NUM_FRAMES) { frame_num = num_frames_a - 1; } // loop over the specified number of frames // long size = fe_a.length(); while (current_frame_d < size && features_d.assign(fe_a(current_frame_d)) && frame_num < num_frames_a) { // decode one frame of data // if (!traverseLexInstanceLevels()) { break; } // increment the frame_num if necessary - otherwise we loop indefinitely // if (num_frames_a != DEF_NUM_FRAMES) { frame_num++; } } // exit gracefully // return true;}// method: networkDecoder//// arguments:// FrontEnd& fe: (input) front-end for extracting features// long num_frames_a: (input) the number of steps to move forward//// return: logical error status//// decode part (or all) of the search space//boolean HierarchicalSearch::networkDecoder(FrontEnd& fe_a, long num_frames_a) { // if we haven't started the search then we need to initialize the // search // if ((long)current_frame_d == DEF_START_FRAME) { initializeNetworkDecoder(); } // determine the number of frames to loop through. If the user specifies // to loop over all frames then the frame_num is set to a default value // so that the decoder loops indefinitely // long frame_num = 0; if (num_frames_a == DEF_NUM_FRAMES) { frame_num = num_frames_a - 1; } // loop over the specified number of frames // ISIP_BUG: (hamaker) the channel is set to zero here which won't be // right for multi-channel data // while (fe_a.getVector(features_d, 0, current_frame_d) && frame_num < num_frames_a) { // ISIP_BUG: check the feature length here // decode one frame of data // if (!traverseLexInstanceLevels()) { break; } // increment the frame_num if necessary - otherwise we loop indefinitely // if (num_frames_a != DEF_NUM_FRAMES) { frame_num++; } } // exit gracefully // return true;}// method: initializeNetworkDecoder//// arguments: none//// return: logical error status//// initialize the lists, etc. needed to begin searching//boolean HierarchicalSearch::initializeNetworkDecoder() { // loccal variable // long num_levels = getNumLevels(); // make sure that we have at least one level defined // if ( num_levels < 1) { return Error::handle(name(), L"initializeLexNetworkDecoder", HierarchicalSearch::ERR_LEVEL, __FILE__, __LINE__); } // set the current frame // current_frame_d = 0; // clear the valid_hyps_d list // clearInstanceStorage(); // clear the instance lists of all the search nodes // clearSearchNodesInstanceLists(); // clear the trellis before starting //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -