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

📄 hsrch_05.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
  Console::put(out);    return true;}// method: printDeletedPath//// arguments://  Trace* new_trace: (input) the endpoint of the new arc//  Trace* old_trace: (input) the start point of the new arc//// return: logical error status//// print an arc created in the hypothesis space//boolean HierarchicalSearch::printDeletedPath(Trace* new_trace_a,					     Trace* old_trace_a) {  SearchSymbol start_sym;  SearchSymbol end_sym;  long old_frame = -1;  long new_frame = -1;    if (old_trace_a != (Trace*)NULL) {    GraphVertex<SearchNode>* old_vertex = old_trace_a->getSymbol()->getCentralVertex();        old_frame = old_trace_a->getFrame();        if (old_vertex->isStart()) {      start_sym.assign(L"_START_");    }    else if (old_vertex->isTerm()) {      start_sym.assign(L"_TERM_");    }    else {      old_trace_a->getSymbol()->print(start_sym);          }  }  if (new_trace_a != (Trace*)NULL) {    GraphVertex<SearchNode>* new_vertex = new_trace_a->getSymbol()->getCentralVertex();        new_frame = new_trace_a->getFrame();    if (new_vertex->isStart()) {      end_sym.assign(L"_START_");    }    else if (new_vertex->isTerm()) {      end_sym.assign(L"_TERM_");    }    else {      new_trace_a->getSymbol()->print(end_sym);          }  }  String val;    String out(L"-> deleted trace: ");  out.concat(new_trace_a);  out.concat(L", backpointer: ");  out.concat(old_trace_a);    out.concat(L"\n   [");  out.concat(start_sym);  out.concat(L"], frame: ");  val.assign((long)old_frame);    out.concat(val);  out.concat(L" -> [");  out.concat(end_sym);  out.concat(L"], frame: ");  val.assign((long)new_frame);    out.concat(val);  Console::put(out);    return true;}// method: getHypotheses//// arguments://  String& output_hyp: (output) the current search hypotheses//  long level: (input) the level to print hypotheses from//  double& total_score: (output) the hypothesis total score//  long& num_frames: (output) frame index of the last instance//  DoubleLinkedList<Instance>& instance_path: (output) best hypothesis instance path//// return: logical error status//// build a graph representing the hypotheses and return it//boolean HierarchicalSearch::getHypotheses(String& output_hyp_a,					  long level_a,					  double& total_score_a,					  long& num_frames_a,					  DoubleLinkedList<Instance>& instance_path_a) {  // declare local variables  //  Instance* tmp_instance = (Instance*)NULL;  SearchNode*  prev_node = (SearchNode*)NULL;  SearchNode*  tmp_node = (SearchNode*)NULL;  BiGraphVertex<TrainNode>* vertex = (BiGraphVertex<TrainNode>*)NULL;    long counter = 0;  long curr_level = 0;  long frame_ind = 0;  long prev_frame_ind = -1;  long back_count = 0;  float score = 0.0;  float prev_score = 0.0;  long symbol_id = 0;    String out_str;  SearchSymbol sym;         // clear the output and set the allocation mode for the instance path  //  output_hyp_a.clear();  instance_path_a.clear();    instance_path_a.setAllocationMode(DstrBase::USER);    // move all instances forward in the search space  //  if (!propagateInstances()) {    return false;  }  // make sure we have at least one valid hypothesis  //    if (instance_valid_hyps_d.length() < 1) {    return false;  }  if (search_mode_d == TRAIN) {    // loop over all valid hypothesis and connect them to the trellis term    //        for (boolean more = instance_valid_hyps_d.gotoFirst(); more;	 more = instance_valid_hyps_d.gotoNext()) {            vertex = instance_valid_hyps_d.getCurr()->getReference();            if (vertex == (BiGraphVertex<TrainNode>*)NULL) {	return Error::handle(name(), L"getHypotheses - cannot find the valid hypothesis in the trellis", Error::ARG, __FILE__, __LINE__);      }            trellis_d.insertArc(vertex, trellis_d.getTerm(), false, 0);    }  }    // loop over all valid instances in the hypothesis list  //  instance_valid_hyps_d.gotoFirst();  Instance* best_end_hyp = instance_valid_hyps_d.getCurr();    // find the instance with the best score, i.e., best hypothesis instance  //  while (true) {      if (!instance_valid_hyps_d.gotoNext()) {      break;    }    tmp_instance = instance_valid_hyps_d.getCurr();    if (tmp_instance->getScore() > best_end_hyp->getScore()) {      best_end_hyp = tmp_instance;    }  }    // backtrack from the best hypothesis instance and generate the instance path  //  for (tmp_instance = best_end_hyp; tmp_instance != (Instance*)NULL;       tmp_instance = tmp_instance->getBackPointer()) {    instance_path_a.insertFirst(tmp_instance);    back_count++;  }  // use the best hypothesis instance path to generate the hypothesis string  //  for (boolean more_instances = instance_path_a.gotoFirst(); more_instances;       more_instances = instance_path_a.gotoNext()) {    counter++;    tmp_instance = instance_path_a.getCurr();    frame_ind = tmp_instance->getFrame();        // get the central vertex from the top of the history stack    //    GraphVertex<SearchNode>* tmp_vertex = (GraphVertex<SearchNode>*)NULL;    tmp_vertex = tmp_instance->getSymbol()->getCentralVertex();        // check for a NULL vertex    //    if (tmp_vertex == (GraphVertex<SearchNode>*)NULL) {      return Error::handle(name(), L"getHypotheses - NULL VERTEX", Error::ARG, __FILE__, __LINE__);    }        // make sure the vertex is neither the dummy    // start nor terminating node    //    if ((!tmp_vertex->isStart()) &&	(!tmp_vertex->isTerm())) {      tmp_node = tmp_vertex->getItem();      curr_level = tmp_node->getSearchLevel()->getLevelIndex();      if ((level_a < 0) && (curr_level == (long)initial_level_d)) {	tmp_node->getSymbol(sym);	score = tmp_instance->getScore();	symbol_id = tmp_node->getSymbolId();		// generate the output hypothesis containing only search symbols	//	if (!getSearchLevel(curr_level).isExcludeSymbol(symbol_id)) {	  out_str.assign(sym);	  out_str.concat(L" ");	}	else {	  out_str.assign(L"");	}		// append partial string to the complete hypothesis report	//	if ((frame_ind != prev_frame_ind) && (frame_ind != 0)) {	  output_hyp_a.concat(out_str);	}		prev_node = tmp_node;	prev_score = score;	prev_frame_ind = frame_ind;      }            if ((level_a >= 0) && (curr_level == level_a)) {	String context;	tmp_instance->getSymbol()->print(context);		score = tmp_instance->getScore();	sym.assign(context);		// generate the output hypothesis	//	if (counter > 1) {	  out_str.assign(L"\n");	} else {	  out_str.assign(L"");	}	// append previous frame index	//	if (level_a != (getNumLevels() - 1)) {	  out_str.concat(prev_frame_ind);	}	else {	  out_str.concat(prev_frame_ind + 1);	}	out_str.concat(L"\t");	// append current frame index	//	if (level_a != (getNumLevels() - 1)) {	  out_str.concat(frame_ind);	}	else {	  out_str.concat(frame_ind + 1);	}	out_str.concat(L"\t");		// append search symbol	//	out_str.concat(sym);	out_str.concat(L"\t\t");		// append score	//	out_str.concat(score - prev_score);		// append partial string to the complete hypothesis report	//	if (level_a == (getNumLevels() - 1)) {	  output_hyp_a.concat(out_str);	}	else {	  if ((frame_ind != prev_frame_ind) && (frame_ind != 0)) {	    output_hyp_a.concat(out_str);	  }	}			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: printNewPath//// arguments://  Instance* new_instance: (input) newly created instance//  Instance* old_instance: (input) previous instance (backpointer)//// return: logical error status//// prints a transition generated in the hypothesis space//boolean HierarchicalSearch::printNewPath(Instance* new_instance_a,					 Instance* old_instance_a) {    SearchSymbol start_sym;  SearchSymbol end_sym;    float old_score = 0.0;  float new_score = 0.0;  long old_frame = -1;  long new_frame = -1;        if (old_instance_a != (Instance*)NULL) {        GraphVertex<SearchNode>* old_vertex = old_instance_a->getSymbol()->getCentralVertex();        old_frame = old_instance_a->getFrame();       if (old_vertex->isStart()) {      start_sym.assign(L"_START_");    }    else if (old_vertex->isTerm()) {      start_sym.assign(L"_TERM_");    }    else {      old_instance_a->getSymbol()->print(start_sym);          }    old_score = old_instance_a->getScore();  }  if (new_instance_a != (Instance*)NULL) {    GraphVertex<SearchNode>* new_vertex = new_instance_a->getSymbol()->getCentralVertex();            new_frame = new_instance_a->getFrame();    if (new_vertex->isStart()) {      end_sym.assign(L"_START_");    }    else if (new_vertex->isTerm()) {      end_sym.assign(L"_TERM_");    }    else {      new_instance_a->getSymbol()->print(end_sym);          }    new_score = new_instance_a->getScore();  }  String val;    String output(L"\n-> instance: ");  output.concat(new_instance_a);  output.concat(L", backpointer: ");  output.concat(old_instance_a);      output.concat(L"\n   [");  output.concat(start_sym);  output.concat(L"], frame: ");  val.assign((long)old_frame);    output.concat(val);  output.concat(L", score: ");  output.concat(old_score);    output.concat(L" -> [");  output.concat(end_sym);  output.concat(L"], frame: ");  val.assign((long)new_frame);    output.concat(val);  output.concat(L", score: ");  output.concat(new_score);  Console::put(output);    return true;}// method: printDeletedPath//// arguments://  Instance* new_instance: (input) the endpoint of the new arc//  Instance* old_instance: (input) the start point of the new arc//// return: logical error status//// print an arc created in the hypothesis space//boolean HierarchicalSearch::printDeletedPath(Instance* new_instance_a,					     Instance* old_instance_a) {  SearchSymbol start_sym;  SearchSymbol end_sym;  long old_frame = -1;  long new_frame = -1;  if (old_instance_a != (Instance*)NULL) {    GraphVertex<SearchNode>* old_vertex = old_instance_a->getSymbol()->getCentralVertex();        old_frame = old_instance_a->getFrame();        if (old_vertex->isStart()) {      start_sym.assign(L"_START_");    }    else if (old_vertex->isTerm()) {      start_sym.assign(L"_TERM_");    }    else {      old_instance_a->getSymbol()->print(start_sym);          }  }  if (new_instance_a != (Instance*)NULL) {    GraphVertex<SearchNode>* new_vertex = new_instance_a->getSymbol()->getCentralVertex();        new_frame = new_instance_a->getFrame();    if (new_vertex->isStart()) {      end_sym.assign(L"_START_");    }    else if (new_vertex->isTerm()) {      end_sym.assign(L"_TERM_");    }    else {      new_instance_a->getSymbol()->print(end_sym);          }  }  String val;    String output(L"\n-> deleted instance: ");  output.concat(new_instance_a);  output.concat(L", backpointer: ");  output.concat(old_instance_a);    output.concat(L"\n   [");  output.concat(start_sym);  output.concat(L"], frame: ");  val.assign((long)old_frame);    output.concat(val);  output.concat(L" -> [");  output.concat(end_sym);  output.concat(L"], frame: ");  val.assign((long)new_frame);    output.concat(val);  Console::put(output);    return true;}

⌨️ 快捷键说明

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