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

📄 hsrch_14.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
	prev_node = tmp_node;	prev_score = score;	prev_frame_ind = frame_ind;      }          }      }  total_score_a = score;  num_frames_a = frame_ind;    // exit gracefully  //  return true;}// method: evaluateLexInstanceModels//// arguments: (none)//// return: logical error status.//// evaluate all statistical models//boolean HierarchicalSearch::evaluateLexInstanceModels() {  // define local variables  //  String out;  String val;  long level_num = getNumLevels() - 1;  boolean end_loop = false;  Instance* curr_instance = (Instance*)NULL;  Instance* next_instance = (Instance*)NULL;    GraphVertex<SearchNode>* curr_vert = (GraphVertex<SearchNode>*)NULL;  SearchSymbol item;   // output the frame information  //  if (debug_level_d >= Integral::DETAILED) {    out.assign(L"\n-> evaluating data in frame: ");    val.assign((ullong)current_frame_d);    out.concat(val);    Console::put(out);      }  // if the beam pruning is required at this level  //    initialize the maximal instance score  //  if(getSearchLevel(level_num).useBeam()) {    max_instance_scores_d(level_num) = Instance::INACTIVE_SCORE;  }  // loop over all active instances and score them  //  for (boolean more_instances = instance_lists_d(level_num).gotoFirst();       more_instances;       more_instances = instance_lists_d(level_num).gotoNext()) {        // get the current vertex in the search graph    //    curr_instance = instance_lists_d(level_num).getCurr();    curr_vert = curr_instance->getSymbol()->getCentralVertex();    // evaluate the statistical model    //        float new_score = curr_instance->getScore() +      curr_vert->getItem()->evaluateData(features_d, (long)current_frame_d);    curr_instance->setScore(new_score);        // update the maximal instance score for the beam pruning    //    if(getSearchLevel(level_num).useBeam()       && (new_score > max_instance_scores_d(level_num))) {      max_instance_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 propagation instances up");    }        beamPruneLexInstance(getNumLevels() - 1);  }  // instance pruning at this level  //  if (getSearchLevel(getNumLevels() - 1).useInstance()) {    if (debug_level_d >= Integral::ALL) {      Console::put(L"\ninstance npruning after propagation instances up");    }        instancePruneLexInstance(getNumLevels() - 1);  }      // update current frame  //        - instances generated later will correspond to the next frame  //  current_frame_d += 1 ;  // print debugging information  //  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 instances  // forward that were just evaluated  //  instance_lists_d(level_num).gotoLast();  instance_lists_d(level_num).setMark();  instance_lists_d(level_num).gotoFirst();  // print debugging information  //  if (debug_level_d >= Integral::DETAILED) {    Console::put(L"\npropagating instances forward after the model evaluation");  }    // loop until we have propagated all evaluated instances forward  //  end_loop = instance_lists_d(level_num).isEmpty();  while (!end_loop) {        end_loop = instance_lists_d(level_num).isMarkedElement();        // get the current vertex in the search graph    //    curr_instance = instance_lists_d(level_num).getCurr();    curr_vert = curr_instance->getSymbol()->getLastVertex();        // if this instance is inactive, then delete it    //    if (!curr_instance->isActive()) {            // bump the current instance off of the instance list      //      if (debug_level_d >= Integral::ALL) {	Console::put(L" not active");      }            instance_lists_d(level_num).removeFirst(curr_instance);      Instance::deleteInstance(curr_instance, 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 instance	//	next_instance = new Instance(*curr_instance);	next_instance->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();	float transition_score = tr_scale * tmp_arc->getWeight() + symbol_penalty;	next_instance->setScore(next_instance->getScore() + transition_score);		// update the history with the next node at this level	//	next_instance->setSymbol(context_pool_d.shiftAndAllocate(next_instance->getSymbol(), tmp_arc->getVertex()));	// add any posterior score such as n-symbol probabilities	//  	if (getSearchLevel(level_num).useNSymbol()) {	  GraphVertex<SearchNode>* central_vertex =	    next_instance->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_instance, level_num, central_vertex);	    	    float posterior_score =	      getPosteriorScore(next_instance->getNSymbol(), level_num);	    next_instance->setScore(next_instance->getScore() + posterior_score);	  }	}	  		// add the instance to the search node's instance list	//	Instance* existing_instance = (Instance*)NULL;	SearchNode* next_node = next_instance->getSymbol()->	getCentralVertex()->getItem(); 	if (next_node->addInstance(next_instance, current_frame_d, existing_instance)) {	  	  // set the backpointer	  //	  next_instance->setBackPointer(curr_instance);		  // add the instance to this level's instance list	  //	  instance_lists_d(level_num).insertLast(next_instance);	  // print debugging information	  //	  if (debug_level_d >= Integral::DETAILED) {	    	    // print the best instance	    //	    printInstance(next_instance, level_num);	  }    	  // insert the trace in the trellis	  //	  if (search_mode_d == TRAIN) {	    if (!insertNewPath(curr_instance, next_instance, tmp_arc->getWeight())) {	      return Error::handle(name(), L"evaluateModels", Error::ARG, __FILE__, __LINE__);	    }	  }	  	}	else {	  // delete the instance since there is an existing instance	  // - same history	  //	  // print debugging information	  //	  if (debug_level_d >= Integral::DETAILED) {	    	    // print the best instance	    //	    printInstance(next_instance, level_num);	  }    	  delete next_instance;	  	  if (search_mode_d == TRAIN) {	    if (existing_instance != (Instance*)NULL) {	      if (!insertOldPath(curr_instance, existing_instance, tmp_arc->getWeight())) {		return Error::handle(name(), L"evaluateModels", Error::ARG, __FILE__, __LINE__);	      }	    }	    else {	      return Error::handle(name(), L"existing instance", Error::ARG, __FILE__, __LINE__);	    }	  }	}      }            // bump the current instance off of the instance list      //      instance_lists_d(level_num).removeFirst(curr_instance);      if (curr_instance->getRefCount() < 1) {	Instance::deleteInstance(curr_instance, true);      }      instance_lists_d(level_num).gotoFirst();          } // end if the instance is active  }   // end while (!end_loop)    // exit gracefully  //  return true;  }// method: instancePruneLexInstance//// arguments://  long level_num: (input) the level for which we will propagate traces//// return: logical error status.//boolean HierarchicalSearch::instancePruneLexInstance(long level_num_a) {  // define local variables  //  Instance* curr_instance = (Instance*)NULL;  long threshold = search_levels_d(level_num_a).getInstanceThreshold();  long pruned_instances = 0;  long orig_length = instance_lists_d(level_num_a).length();  // check if we need to prune any instances at this level  //  if (orig_length > threshold) {    long num_to_remove = orig_length - threshold;    // sort the instances    //    instance_lists_d(level_num_a).sort(Integral::ASCENDING,				       DstrBase::RAND_QUICK);        // loop over all active instances at this level    //    for (long i=0; i < num_to_remove; i++) {      instance_lists_d(level_num_a).remove(curr_instance);      if (curr_instance->getRefCount() < 1) {	Instance::deleteInstance(curr_instance, true);      }            pruned_instances++;    }  }  if (debug_level_d >= Integral::DETAILED) {    String output(L"frame: ");    output.concat(current_frame_d);    output.concat(L", level: ");    output.concat(level_num_a);    output.concat(L", original instances: ");    output.concat(orig_length);    output.concat(L", pruned instances: ");    output.concat(pruned_instances);    output.concat(L", current instances: ");    output.concat(instance_lists_d(level_num_a).length());    output.concat(L", threshold: ");    output.concat(threshold);    output.concat(L"\n");    Console::put(output);  }    // exit gracefully  //  return true;    }// method: beamPruneLexInstance//// arguments://  long level_num: (input) the level for which we will propagate traces//// return: logical error status.//boolean HierarchicalSearch::beamPruneLexInstance(long level_num_a) {  // define local variables  //  Instance* curr_instance = (Instance*)NULL;  float threshold = max_instance_scores_d(level_num_a)    - search_levels_d(level_num_a).getBeamThreshold();  float curr_score;  long pruned_instances = 0;  long orig_length = instance_lists_d(level_num_a).length();    // loop over all active instances at this level  //  boolean more_instances = instance_lists_d(level_num_a).gotoFirst();    while (more_instances) {    curr_instance = instance_lists_d(level_num_a).getCurr();    curr_score = curr_instance->getScore();    if (curr_score > max_instance_scores_d(level_num_a)) {      return Error::handle(name(), L"beamPruneLexInstance - bad maximal score", Error::ARG, __FILE__, __LINE__);    }          // prune the instances with too low score    //    if (curr_score < threshold)  {      if (debug_level_d >= Integral::ALL) {	String output(L"score is smaller than threshold: ");	output.concat(curr_score);	output.concat(L", instance:" );	output.concat(curr_instance);	Console::put(output);      }      if (instance_lists_d(level_num_a).isLast()) {	more_instances = false;      }	        // bump the current instance off of the instance list      //      instance_lists_d(level_num_a).remove();            if (curr_instance->getRefCount() < 1) {	Instance::deleteInstance(curr_instance, true);      }      pruned_instances++;    }        else {      if (debug_level_d >= Integral::ALL) {	String output(L"score is not smaller than threshold: ");	output.concat(curr_score);	output.concat(L", instance:" );	output.concat(curr_instance);	Console::put(output);      }            more_instances = instance_lists_d(level_num_a).gotoNext();    }      }  if (debug_level_d >= Integral::DETAILED) {    String output(L"frame: ");    output.concat(current_frame_d);    output.concat(L", level: ");    output.concat(level_num_a);    output.concat(L", original instances: ");    output.concat(orig_length);    output.concat(L", pruned instances: ");    output.concat(pruned_instances);    output.concat(L", current instances: ");    output.concat(instance_lists_d(level_num_a).length());    output.concat(L", threshold: ");    output.concat(threshold);    output.concat(L", max instance score: ");    output.concat(max_instance_scores_d(level_num_a));    output.concat(L"\n");    Console::put(output);  }    // exit gracefully  //  return true;}// method: clearValidHypsLexInstance//// arguments: none//// return: logical error status//// clear the instances stored in the valid hypothesis list//boolean HierarchicalSearch::clearValidHypsLexInstance() {   // define local variables  //  Instance* tmp_instance;    // use the trace_instance_valid_hyps_d list as temporary storage  //  while (instance_valid_hyps_d.removeFirst(tmp_instance)) {    if (tmp_instance != (Instance*)NULL) {      Instance::deleteInstance(tmp_instance, true);    }  }   // exit gracefully  //  return true;}// method: convertLexInstances//// arguments://  DoubleLinkedList<Instance>& instance_path: (output) best hypothesis instance path//// return: logical error status//// build a graph representing the hypotheses and return it//boolean HierarchicalSearch::convertLexInstances( DoubleLinkedList<Instance>&						 instance_path_a) {  // declare local variables  //  Instance* tmp_instance = (Instance*)NULL;  Instance* prev_instance = (Instance*)NULL;  Instance* term_instance = (Instance*)NULL;  Instance* start_instance = (Instance*)NULL;  Instance* end_instance = (Instance*)NULL;    GraphVertex<SearchNode>* tmp_vertex = (GraphVertex<SearchNode>*)NULL;  GraphVertex<SearchNode>* start_vertex = (GraphVe

⌨️ 快捷键说明

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