📄 ssrch_15.cc
字号:
// file: $isip/class/search/StackSearch/ssrch_15.cc// version: $Id: ssrch_15.cc,v 1.5 2002/09/06 21:46:31 jelinek Exp $//// isip include files//#include "StackSearch.h"// method: extend//// arguments:// DoubleLinkedList<Trace>& hypothesis_list: (input) word level traces// long start_frame: (input) start frame// // return: logical error status//// extend all word level hypotheses in hypothesis_list by one word//boolean StackSearch::extend(DoubleLinkedList<Trace>& hypothesis_list_a, long start_frame_a) { // initialize top level traces and time synchronously extend all // of them by one word // setTopLevelTraces(hypothesis_list_a); setFrame(start_frame_a); // output debugging information // if (debug_level_d >= Integral::DETAILED) { String out(L"\nExtending from start frame "); out.concat(start_frame_a); out.concat(L", first propagate down"); Console::put(out); } // first propagate all the top level traces to the state level // for (long i = 0; i < getNumLevels() - 1; i++) { propagateTracesDown(i); } // for all next frames generate one word extensions of the // hypotheses from the current frame's stack. // each extension is moved to the stack corresponding to frame // when extension was generated. // note that current frame is changed during the model evaluation. // while ((pathsRemainTrace()) && (current_frame_d < num_frames_d)) { evaluateTraceModels(); // propagate traces one frame forward and pick up the traces from // the top (0-th) level // DoubleLinkedList<Trace> top_traces(DstrBase::USER); propagateTraces(&top_traces); // output debugging information // if (debug_level_d >= Integral::DETAILED) { String out(L"\nExtending FROM frame "); out.concat(start_frame_a); out.concat(L" TO frame "); out.concat(current_frame_d); out.concat(L" top traces generated: "); out.concat(top_traces.length()); Console::put(out); } // insert valid top level traces into stack // boolean more = top_traces.gotoFirst(); while (more) { // get the trace from list // Trace* current_trace = top_traces.getCurr(); // if trace is not active, delete it recursively // if (!current_trace->isActive()) { Trace::deleteTrace(current_trace, true); } // since the trace is active, insert hypothesis into // corresponding stack // else { // get the score of current trace and create temporary // hypothesis // float current_score = current_trace->getScore(); Hypothesis tmp_hypothesis(current_trace, current_score); // find the stack for the hypothesis // HashKey<GVSnode> key; key.assign(current_trace->getHistory()->peek()->getLastVertex()); Stack<Hypothesis>* stack = stacks_d(current_frame_d).get(key); // if there is no stack for this hypothesis yet, create one // and put the current hypothesis into it // if (stack == NULL) { Stack<Hypothesis> tmp_stack; tmp_stack.push(&tmp_hypothesis); stacks_d(current_frame_d).insert(key, &tmp_stack); } // if there are less then n-best hypotheses in the stack, // insert also current hypotheses // else if (stack->length() < n_best_d) { stack->push(&tmp_hypothesis); } // if there are n-best hypotheses in the stack, // keep the better one and delete worse // else if (stack->length() == n_best_d) { if (current_score > stack->peek()->getScore()) { Hypothesis worse; stack->pop(&worse); Trace::deleteTrace(worse.getTrace(), true); stack->push(&tmp_hypothesis); } else { Trace::deleteTrace(current_trace, true); } } // update max stack score if it is exceeded // if (current_score > max_stack_scores_d(current_frame_d)) { max_stack_scores_d(current_frame_d) = current_score; } } more = top_traces.gotoNext(); } // end of the loop over top traces (over word extensions) } // end of loop over all end frames // remove state level traces after the last frame, because the will // not be propagated any more // DoubleLinkedList<Trace> state_traces(DstrBase::USER); getTraces(state_traces, getNumLevels() - 1); Trace* current_trace = NULL; while (state_traces.removeFirst(current_trace)) { Trace::deleteTrace(current_trace, true); } // after the end of one time-synchronous stack extension, // clean the trace lists of all search nodes // (later we can clean only those actually visited nodes) // clearSearchNodesTraceLists(); // exit gracefully // return true;}// method: decode//// arguments: none// // return: logical error status//// this is the core decoding method//boolean StackSearch::decode() { // initialize maximal trace and stack scores // initSizes(num_frames_d); // this will set current frame to 0, clear trace lists, search nodes // and generate initial trace // initializeLinearDecoder(); // put top traces in frame 0 to stacks(0) // DoubleLinkedList<Trace> top_traces(DstrBase::USER); getTraces(top_traces, 0); boolean more = top_traces.gotoFirst(); while (more) { // create temporary hypothesis for each trace // Trace* curr_trace = top_traces.getCurr(); float score = curr_trace->getScore(); Hypothesis tmp_hypothesis(curr_trace, score); // create stack for each word // Stack<Hypothesis> tmp_stack; tmp_stack.push(&tmp_hypothesis); HashKey<GVSnode> key; key.assign(curr_trace->getHistory()->peek()->getLastVertex()); // insert the stack into hashtable // stacks_d(0).insert(key, &tmp_stack); more = top_traces.gotoNext(); } // propagate word hypotheses from all stacks frame by frame // for (long curr_frame = 0; curr_frame < features_d.length(); curr_frame++) { // pop word hypotheses from the stack of the current frame one by one // DoubleLinkedList<Trace> valid_traces(DstrBase::USER); if (debug_level_d >= Integral::BRIEF) { String out(L"Popping the stack "); out.concat(curr_frame); out.concat(L" of size "); out.concat(stacks_d(curr_frame).getNumItems()); Console::put(out); } Vector< Stack<Hypothesis> > stacks; stacks_d(curr_frame).values(stacks); for (long i = 0; i < stacks.length(); i++) { Stack<Hypothesis>* stack = &stacks(i); Hypothesis curr_hypothesis; while (stack->pop(&curr_hypothesis)) { Trace* curr_trace = curr_hypothesis.getTrace(); valid_traces.insertLast(curr_trace); if (debug_level_d >= Integral::DETAILED) { float curr_score = curr_hypothesis.getScore(); String out(L" "); out.concat(curr_score); out.concat(L" "); out.concat((float)max_stack_scores_d(curr_frame)); } } } // extend all valid traces // extend(valid_traces, curr_frame); } // get hypotheses // DoubleLinkedList<Trace> traces(DstrBase::USER); Hypothesis curr_hypothesis; Vector< Stack<Hypothesis> > stacks; stacks_d(features_d.length()).values(stacks); for (long i = 0; i < stacks.length(); i++) { Stack<Hypothesis>* stack = &stacks(i); while (stack->pop(&curr_hypothesis)) { Trace* curr_trace = curr_hypothesis.getTrace(); traces.insertLast(curr_trace); } } setTopLevelTraces(traces); // exit gracefully // return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -