📄 ssrch_11.cc
字号:
// file: $isip/class/search/StackSearch/ssrch_11.cc// version: $Id: ssrch_11.cc,v 1.3 2002/08/02 02:07:17 jelinek Exp $//// isip include files//#include "StackSearch.h"// method: traverseTraceLevels//// arguments: none//// return: logical error status//// do a single-step traversal of the hypotheses at each level//boolean StackSearch::traverseTraceLevels() { // define local variables // boolean status = false; // make sure we have some paths left to traverse // if (!pathsRemainTrace()) { return false; } // propagate traces forward until they are all ready to be evaluated // status = (propagateTraces() || status); // now we evaluate all traces that are in the lowest level and move // them forward one arc. Viterbi pruning takes place at this level // as does beam pruning. // status = (evaluateTraceModels() || status); // exit gracefully // return status;}// method: propagateTraces//// arguments:// DoubleLinkedList<Trace>* top_list: (output) traces that reached top level//// return: logical error status//// move traces through the hierarchy until all active traces are ready to be// evaluated//boolean StackSearch::propagateTraces(DoubleLinkedList<Trace>* top_list_a) { // define local variables // long level_num = 0; boolean status = true; long num_levels = getNumLevels(); String out; // clear the hypothesis list since we are generating new hypotheses for this // frame // clearValidHypsTrace(); // move all traces forward in the search space. we do this by // pushing traces up and down in the hierarchy until they all rest // in a state that is ready to be evaluated. if there is an infinite // "skip" loop in the search graph then this process will go into an // infinite loop. an infinite skip loop is of the form: // A -> B && B -> A. // this infinite loop structure may be masked by the fact that it // extends over multiple search levels. // // when we exit the while loop below, all traces should be in the lowest // level and should be ready for evaluation. // while ((getActiveTraces() != getActiveTraces(num_levels - 1)) || status) { // status indicates whether any movement in the traces happened // status = false; // work from the bottom up until we reach a point where all traces // are ready to descend again. this segment takes care of // posterior scores such as nsymbol probabilities and applies // pruning (beam and instance) at each level. // for (level_num = num_levels - 1; level_num >= 0; level_num--) { // propagate up // status = (propagateTracesUp(level_num, top_list_a) || status); } for (level_num = 0; level_num < (num_levels - 1); level_num++) { if (getSearchLevel(level_num).useBeam()) { if (debug_level_d >= Integral::DETAILED) { Console::put(L"\npruning after propagation traces up"); } beamPruneTrace(level_num); } } // propagate traces down the hierarchy, carrying out Viterbi pruning // as we go. // for (level_num = 0; level_num < num_levels - 1; level_num++) { // propagate down // status = (propagateTracesDown(level_num) || status); } } // exit gracefully // return true;}// method: evaluateTraceModels//// arguments: (none)//// return: logical error status.//// evaluate all statistical models//boolean StackSearch::evaluateTraceModels() { // define local variables // String out; String val; long level_num = getNumLevels() - 1; boolean end_loop = false; Trace* curr_trace = (Trace*)NULL; Trace* next_trace = (Trace*)NULL; History* curr_history = (History*)NULL; GraphVertex<SearchNode>* curr_vert = (GraphVertex<SearchNode>*)NULL; SearchSymbol item; // output the frame information // if (debug_level_d >= Integral::DETAILED) { out.assign(L"\nevaluating data in frame "); out.concat(current_frame_d); Console::put(out); } // loop over all active traces and score them // for (boolean more_traces = trace_lists_d(level_num).gotoFirst(); more_traces; more_traces = trace_lists_d(level_num).gotoNext()) { // get the current vertex in the search graph // curr_trace = trace_lists_d(level_num).getCurr(); curr_history = curr_trace->getHistory(); curr_vert = curr_history->peek()->getCentralVertex(); // evaluate the statistical model // SearchNode* p_sn = curr_vert->getItem(); if (p_sn == NULL) { return Error::handle(name(), L"evaluateTraceModels - no SearchNode in Vertex", Error::ARG, __FILE__, __LINE__); } // find the statistical model index // note: this code is not effective because it needs to call a // hashing function to get the statistical model index, we plan to // use look up table access in the next version // // get the symbol id // long symbol_id = p_sn->getSymbolId(); // get search level and symbol table // SearchLevel* sl = p_sn->getSearchLevel(); Vector<SearchSymbol>& symbol_table = sl->getSymbolTable(); SearchSymbol& ss = symbol_table(symbol_id); // get a hashtable hashing search symbols to statistical model indices // HashTable<SearchSymbol, Long>& symbol_hashtable = sl->getSymbolHashTable(); // check if hash table is loaded // if (symbol_hashtable.getNumItems() == 0) { return Error::handle(name(), L"evaluateTraceModels - load stat models hashtable first", Error::ARG, __FILE__, __LINE__); } // get the statistical model index from hashtable // Long* p_stat_model_id = symbol_hashtable.get(ss); long stat_model_id = (long)*p_stat_model_id; // having the statistical model index, we can check whether the stat float stat_score = stat_model_scores_d(current_frame_d, stat_model_id); if (stat_score == SearchNode::INACTIVE_SCORE) { stat_score = p_sn->evaluateData(features_d(current_frame_d), current_frame_d); stat_model_scores_d.setValue(current_frame_d, stat_model_id, stat_score); } float new_score = curr_trace->getScore() + stat_score; curr_trace->setScore(new_score); // update the maximal trace score for the beam pruning // if (getSearchLevel(level_num).useBeam() && (new_score > max_frame_scores_d(current_frame_d, level_num))) { if (debug_level_d >= Integral::DETAILED) { // print the score update information // out.assign(L"fr:"); out.concat(current_frame_d); out.concat(L" lv:"); out.concat(level_num); out.concat(L" max_sc updt (after the model EVALUATION) "); out.concat(max_frame_scores_d(current_frame_d, level_num)); out.concat(L"->"); out.concat(new_score); Console::put(out); } // update the maximal trace score // max_frame_scores_d.setValue(current_frame_d, level_num, new_score); } } // do the beam pruning at this level // if (getSearchLevel(getNumLevels() - 1).useBeam()) { if (debug_level_d >= Integral::DETAILED) { Console::put(L"\npruning after the model EVALUATION"); } beamPruneTrace(getNumLevels() - 1); } // update current frame // - traces generated later will correspond to the next frame // current_frame_d += 1 ; if (debug_level_d >= Integral::DETAILED) { out.assign(L"\nTIME CHANGED to: "); out.concat(current_frame_d); Console::put(out); } // we mark the current end of the list so we only propagate those traces // forward that were just evaluated // trace_lists_d(level_num).gotoLast(); trace_lists_d(level_num).setMark(); trace_lists_d(level_num).gotoFirst(); if (debug_level_d >= Integral::DETAILED) { Console::put(L"\npropagating traces forward after the model EVALUATION"); } // loop until we have propagated all evaluated traces forward // end_loop = (trace_lists_d(level_num).length() < 1); while (!end_loop) { end_loop = trace_lists_d(level_num).isMarkedElement(); // get the current vertex in the search graph // curr_trace = trace_lists_d(level_num).getCurr(); curr_history = curr_trace->getHistory(); curr_vert = curr_history->peek()->getLastVertex(); // if this trace is inactive, then delete it // if (!curr_trace->isActive()) { // bump the current trace off of the trace list // if (debug_level_d >= Integral::ALL) { Console::put(L" not active"); } trace_lists_d(level_num).removeFirst(curr_trace); Trace::deleteTrace(curr_trace, true); } // else, extend paths and apply viterbi pruning // else { // extend all paths from that vertex and apply viterbi pruning // for (boolean more_paths = curr_vert->gotoFirst(); more_paths; more_paths = curr_vert->gotoNext()) { // create a new trace // next_trace = new Trace(*curr_trace); next_trace->setFrame((ulong)current_frame_d); // update the score with the arc score // GraphArc<SearchNode>* tmp_arc = curr_vert->getCurr(); next_trace->setScore(next_trace->getScore() + tmp_arc->getWeight()); // update the history with the next node at this level // next_trace->getHistory()->peek()-> assignAndAdvance((ulong)tmp_arc->getVertex()); // add the trace to the search node's trace list // Trace* existing_trace = (Trace*)NULL; SearchNode* next_node = next_trace->getHistory()->peek()-> getCentralVertex()->getItem(); if (next_node->addTrace(next_trace, current_frame_d, existing_trace)) { // set the backpointer // next_trace->setBackPointer(curr_trace); // add the trace to this level's trace list // trace_lists_d(level_num).insertLast(next_trace); if (debug_level_d >= Integral::ALL) { printNewPath(next_trace, curr_trace); } } else { // delete the trace since there is an existing trace - same history // if (debug_level_d >= Integral::ALL) { printDeletedPath(next_trace, curr_trace); } delete next_trace; } } // bump the current trace off of the trace list // if (curr_trace->getRefCount() < 1) { Trace::deleteTrace(curr_trace, true); } trace_lists_d(level_num).removeFirst(curr_trace); trace_lists_d(level_num).gotoFirst(); } // end if the trace is active } // end while (!end_loop) // exit gracefully //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -