⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hsrch_11.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
    // if the beam pruning is required at this level    //    initialize the maximal trace score    //    if(getSearchLevel(level_num).useBeam()) {      max_trace_scores_d(level_num) = Trace::INACTIVE_SCORE;    }    // 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_vert = curr_trace->getSymbol()->getCentralVertex();      // evaluate the statistical model      //      float model_score =	curr_vert->getItem()->evaluateData(features_d, (long)current_frame_d);      float new_score = curr_trace->getScore() + model_score;      curr_trace->setScore(new_score);      if (search_mode_d == TRAIN) {      	// update the trained node in the trellis	//	vertex = curr_trace->getReference();	if (vertex == (BiGraphVertex<TrainNode>*)NULL) {	  return Error::handle(name(), L"evaluateTraceModels", Error::ARG, __FILE__, __LINE__);	}	vertex->getItem()->setScore(model_score);      }          // update the maximal trace score for the beam pruning      //      if(getSearchLevel(level_num).useBeam()	 && (new_score > max_trace_scores_d(level_num))) {	max_trace_scores_d(level_num) = new_score;      }    }    // beam pruning at this level    //    if (getSearchLevel(getNumLevels() - 1).useBeam()) {      if (debug_level_d >= Integral::DETAILED) {	Console::put(L"\nbeam pruning after the model evaluation");      }          beamPruneTrace(getNumLevels() - 1);    }    // instance pruning at this level    //    if (getSearchLevel(getNumLevels() - 1).useInstance()) {      if (debug_level_d >= Integral::DETAILED) {	Console::put(L"\ninstance pruning after the model evaluation");      }          instancePruneTrace(getNumLevels() - 1);    }  } // end of non-context-generation mode    // 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"\n-> time 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_vert = curr_trace->getSymbol()->getLastVertex();    //  add for word-internal context generation    //  we do not need to evaluate the states at the lowest level    //    if (context_generation_mode_d) {      // get parent graph      //      DiGraph<SearchNode>* parent_graph = curr_vert->getParentGraph();      // create a new trace      //      next_trace = new Trace(*curr_trace);      next_trace->setFrame((ulong)current_frame_d);      // update the history with the next node at this level      //      next_trace->getSymbol()->assignAndAdvance((ulong)parent_graph->getTerm());      // 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::DETAILED) { 	printNewPath(next_trace, curr_trace);      }            // bump the current trace off of the trace list      //      trace_lists_d(level_num).removeFirst(curr_trace);      if (curr_trace->getRefCount() < 1) {	Trace::deleteTrace(curr_trace, true);      }      trace_lists_d(level_num).gotoFirst();      // evaluate the next trace in the list      //      continue;    }        // 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);	// determine the symbol insertion penalty and transition	// scale factor	//	float tr_scale = getSearchLevel(level_num).getTrScale();	float symbol_penalty = getSearchLevel(level_num).getSymbolPenalty();	      	// update the score with the arc score	//	GraphArc<SearchNode>* tmp_arc = curr_vert->getCurr();	long symbol_id = tmp_arc->getVertex()->getItem()->getSymbolId();	if (!getSearchLevel(level_num).isDummySymbol(symbol_id)) {	  next_trace->setScore(next_trace->getScore() + (tmp_arc->getWeight() * tr_scale) + symbol_penalty);	}	else {	  next_trace->setScore(next_trace->getScore() + tmp_arc->getWeight());	}	// has the context been previously generated? if so reuse the context,	// if not generate a new context and add it to the context pool	//	next_trace->setSymbol(context_pool_d.shiftAndAllocate(next_trace->getSymbol(), tmp_arc->getVertex()));		// add any posterior score such as n-symbol probabilities	//  	if (getSearchLevel(level_num).useNSymbol()) {	  GraphVertex<SearchNode>* central_vertex =	    next_trace->getSymbol()->getCentralVertex();	  long symbol_id = central_vertex->getItem()->getSymbolId();	  	  if (!getSearchLevel(level_num).isDummySymbol(symbol_id) &&	      !getSearchLevel(level_num).isSkipSymbol(symbol_id) &&	      !central_vertex->isStart() && !central_vertex->isTerm()) {	    shiftNSymbol(next_trace, level_num, central_vertex);	    	    float posterior_score =	      getPosteriorScore(next_trace->getNSymbol(), level_num);	    next_trace->setScore(next_trace->getScore() + posterior_score);	  }	}		// add the trace to the search node's trace list	//	if (!addHypothesisPath(next_trace, curr_trace, level_num, tmp_arc->getWeight())) {	  return Error::handle(name(), L"evaluateTraceModels", Error::ARG, __FILE__, __LINE__);	}	      }            // bump the current trace off of the trace list      //      trace_lists_d(level_num).removeFirst(curr_trace);      if (curr_trace->getRefCount() < 1) {	Trace::deleteTrace(curr_trace, true);      }      trace_lists_d(level_num).gotoFirst();          } // end if the trace is active  }   // end while (!end_loop)    // exit gracefully  //  return true;}// method: propagateInstancesUp//// 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::propagateInstancesUp(long level_num_a) {  // define local variables  //  boolean status = false;  boolean end_loop = false;  Context* tmp_context = (Context*)NULL;    Instance* curr_instance = (Instance*)NULL;  Instance* tmp_instance = (Instance*)NULL;  Instance* next_instance = (Instance*)NULL;  GraphVertex<SearchNode>* curr_vert = (GraphVertex<SearchNode>*)NULL;      // 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()) {      Instance::deleteInstance(curr_instance, true);    }        // else, extend paths and update scores    //    else {            // get the current vertex in the search graph      //      curr_vert = curr_instance->getSymbol()->getCentralVertex();      // if this vertex is a terminal vertex then ascend and create the traces      // at the higher level      //            if (curr_vert->isTerm()) {		// set the status to true since we are propagating a instance	//	status = true;	// if we are at the top level then put the instance into the valid	// hypothesis list	//	if (level_num_a == (long)initial_level_d) {	  instance_valid_hyps_d.insertLast(curr_instance);	}		// else move up one level and create the next set of instances	//	else {	  	  // create a new instance, 	  //	  next_instance = new Instance(*curr_instance);	  next_instance->setFrame((ulong)current_frame_d);	  next_instance->setBackPointer(curr_instance);	  // decrement the history of the instance	  //	  next_instance->setHistory(history_pool_d.popAndAllocate(next_instance->getHistory(), tmp_context));	  // the context must exist in the context pool in this case	  //	  next_instance->setSymbol(context_pool_d.get(*tmp_context));	  	  // print the debuging information	  //	  	  if (debug_level_d >= Integral::DETAILED) {	    printNewPath(next_instance, curr_instance);	  }	  // insert the instance into the trellis	  //	  if (search_mode_d == TRAIN) {	    if (!insertNewPath(curr_instance, next_instance, 0)) {	      return Error::handle(name(), L"propagateInstancesUp", Error::ARG, __FILE__, __LINE__);	    }	  }	  	  if (isTerminal(next_instance, level_num_a - 1)) {	    // create a temporary instance	    //	    tmp_instance = new Instance(*next_instance);	    tmp_instance->setFrame((ulong)current_frame_d);	    tmp_instance->setBackPointer(next_instance);	    	    // create a context with a terminal as the central context	    //	    Context term_context;	    term_context.assignAndAdvance((ulong)search_levels_d((long)initial_level_d).getSubGraph(0).getTerm());	      	    tmp_instance->setSymbolStack(history_pool_d.pushAndAllocate(tmp_instance->getSymbolStack(), tmp_instance->getSymbol()));	    tmp_instance->setSymbol(context_pool_d.get(term_context));	    	    // add the instance to this level's instance list	    //	    instance_lists_d(level_num_a - 1).insertLast(tmp_instance);	    // print the debuging information	    //	    if (debug_level_d >= Integral::DETAILED) {	      printNewPath(tmp_instance, next_instance);	    }	    	    // insert the insatnce into the trellis	    //	    if (search_mode_d == TRAIN) {	      if (!insertNewPath(next_instance, tmp_instance, 0)) {		return Error::handle(name(), L"propagateInstancesUp", Error::ARG, __FILE__, __LINE__);	      }	    }		    	  }	  	  // extend the current context	  //	  else {	    if (!extendRightContexts(next_instance, level_num_a - 1)) {	      return Error::handle(name(), L"propagateInstancesUp", Error::ARG, __FILE__, __LINE__);	    }	  }	  	  // delete next_instance if no instances propagated from it	  // have survived	  //	  if (next_instance->getRefCount() < 1) {	    Instance::deleteInstance(next_instance, false);	  }	}		// bump the current instance off of the instance list	//	if (curr_instance->getRefCount() < 1) {	  	  // if this is at top level, we can not delete them since they	  // are also referenced by the valid_hyps	  //	  if (level_num_a != (long)initial_level_d) {	    Instance::deleteInstance(curr_instance, 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      // evaluateInstanceModels function      //      else {		// update the maximal instance score for the beam pruning	//	float instance_score = curr_instance->getScore();	if(getSearchLevel(level_num_a).useBeam()	  && (instance_score > max_instance_scores_d(level_num_a)) ) {	  max_instance_scores_d(level_num_a) = instance_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: propagateTracesUp//// arguments://  long level_num: (input) the level for which we will propagate traces//// return: logical error status. if no propagations were made then return false//// propagate all traces up. only traces at the end of a subgraph are considered//boolean HierarchicalSearch::propagateTracesUp(long level_num_a) {  // define local variables  //  boolean status = false;  boolean end_loop = false;    Trace* curr_trace = (Trace*)NULL;  Trace* tmp_trace = (Trace*)NULL;  Trace* next_trace = (Trace*)NULL;      Context* tmp_context = (Context*)NULL;    GraphVertex<SearchNode>* curr_vert = (GraphVertex<SearchNode>*)NULL;  GraphVertex<SearchNode>* tmp_vert = (GraphVertex<SearchNode>*)NULL;    // make sure there is at least one trace to propagate  //  if (trace_lists_d(level_num_a).length() < 1) {    return false;  }    // loop over all current traces and create the next level's traces. all new  // traces will go at the end of the list so we set the mark to tell

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -