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

📄 hsrch_11.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
// file: $isip/class/search/HierarchicalSearch/hsrch_11.cc//// isip include files//#include "HierarchicalSearch.h"// method: addHypothesisPath//// arguments://   Trace*& new_trace: (input) new input trace//   Trace*& old_trace: (input) old input trace//   long level_num: (input) current level number//   float weight: (input) transition score//// return: logical error status//// this method add an trace to the hypothesis path//boolean HierarchicalSearch::addHypothesisPath(Trace*& new_trace_a,					      Trace*& old_trace_a,					      long level_num_a,					      float weight_a) {  // declare local variables  //  Context* symbol = (Context*)NULL;  Trace* existing_trace = (Trace*)NULL;    // error checking  //  if ((symbol = new_trace_a->getSymbol()) == (Context*)NULL) {    return false;  }    // add the trace to the search node's trace list  //  SearchNode* search_node = symbol->getCentralVertex()->getItem();        if (search_node->addTrace(new_trace_a, current_frame_d,			       existing_trace)) {        // update the maximal trace score for the beam pruning    //    float trace_score = new_trace_a->getScore();    if( getSearchLevel(level_num_a).useBeam()	&& (trace_score > max_trace_scores_d(level_num_a))) {      max_trace_scores_d(level_num_a) = trace_score;    }        // set the backpointer    //    new_trace_a->setBackPointer(old_trace_a);        // add the trace to the next level's trace list    //    trace_lists_d(level_num_a).insertLast(new_trace_a);    // print debugging information    //    if (debug_level_d >= Integral::DETAILED) {      printNewPath(new_trace_a, old_trace_a);    }    // insert the trace in the trellis    //    if (search_mode_d == TRAIN) {      if (!insertNewPath(old_trace_a, new_trace_a, weight_a)) {	return Error::handle(name(), L"addHypothesisPath", Error::ARG, __FILE__, __LINE__);      }    }        }  else {    // print debugging information    //          if (debug_level_d >= Integral::DETAILED) {       printDeletedPath(new_trace_a, old_trace_a);    }          // delete the trace since there is existing trace - same history    //    delete new_trace_a;    new_trace_a = (Trace*)NULL;        if (search_mode_d == TRAIN) {      if (existing_trace != (Trace*)NULL) {	if (!insertOldPath(old_trace_a, existing_trace, weight_a)) {	  return Error::handle(name(), L"addHypothesisPath", Error::ARG, __FILE__, __LINE__);	}      }      else {	return Error::handle(name(), L"addHypothesisPath", Error::ARG, __FILE__, __LINE__);      }    }        }  // exit gracefully  //  return true;}// method: addHypothesisPath//// arguments://   Instance*& new_instance: (input) new input instance//   Instance*& old_instance: (input) old input instance//   long level_num: (input) current level number//   float weight: (input) transition score//// return: logical error status//// this method add an instance to the hypothesis path//boolean HierarchicalSearch::addHypothesisPath(Instance*& new_instance_a,					      Instance*& old_instance_a,					      long level_num_a,					      float weight_a) {  // declare local variables  //  Context* symbol = (Context*)NULL;  Instance* existing_instance = (Instance*)NULL;    // error checking  //  if ((symbol = new_instance_a->getSymbol()) == (Context*)NULL) {    return false;  }    // add the instance to the search node's instance list  //  SearchNode* search_node = symbol->getCentralVertex()->getItem();        if (search_node->addInstance(new_instance_a, current_frame_d,			       existing_instance)) {        // update the maximal instance score for the beam pruning    //    float instance_score = new_instance_a->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;    }        // set the backpointer    //    new_instance_a->setBackPointer(old_instance_a);        // add the instance to the next level's instance list    //    instance_lists_d(level_num_a).insertLast(new_instance_a);    // print debugging information    //    if (debug_level_d >= Integral::DETAILED) {      printNewPath(new_instance_a, old_instance_a);    }    // insert the instance in the trellis    //    if (search_mode_d == TRAIN) {      if (!insertNewPath(old_instance_a, new_instance_a, weight_a)) {	return Error::handle(name(), L"addHypothesisPath", Error::ARG, __FILE__, __LINE__);      }    }        }  else {    // print debugging information    //          if (debug_level_d >= Integral::DETAILED) {       printDeletedPath(new_instance_a, old_instance_a);    }          // delete the instance since there is existing instance - same history    //    delete new_instance_a;    new_instance_a = (Instance*)NULL;        if (search_mode_d == TRAIN) {      if (existing_instance != (Instance*)NULL) {	if (!insertOldPath(old_instance_a, existing_instance, weight_a)) {	  return Error::handle(name(), L"addHypothesisPath", Error::ARG, __FILE__, __LINE__);	}      }      else {	return Error::handle(name(), L"addHypothesisPath", Error::ARG, __FILE__, __LINE__);      }    }        }  // exit gracefully  //  return true;}// method: insertNewPath//// arguments://   Trace* parent: (input) source trace//   Trace* child: (input) destination trace//   float weight: (input) transition probability//// return: logical error status//// method adds a new path to the trellis//boolean HierarchicalSearch::insertNewPath(Trace* parent_a, Trace* child_a,					  float weight_a) {  // declare local variables  //  BiGraphVertex<TrainNode>* ptr = (BiGraphVertex<TrainNode>*)NULL;  BiGraphVertex<TrainNode>* src = (BiGraphVertex<TrainNode>*)NULL;  BiGraphVertex<TrainNode>* dst = (BiGraphVertex<TrainNode>*)NULL;    // make sure that neither the parent nor the child traces are null  //  if ((parent_a == (Trace*)NULL) || (child_a == (Trace*)NULL)) {    return false;  }  // retrieve the refernece pointer  //  ptr = parent_a->getReference();    // check to see if the parent trace exists in the map  //  if (ptr != (BiGraphVertex<TrainNode>*)NULL) {        // get the parent and child vertices    //    src = ptr;    dst = insertTrace(child_a);        // add a transition in the trellis from the parent to the child    //    if (src != trellis_d.getTerm()) {      trellis_d.insertArc(src, dst, false, weight_a);    }  } else {        // get the parent and child vertices    //        src = insertTrace(parent_a);    dst = insertTrace(child_a);    // add a transition in the trellis from the parent to the child    //        if (src != trellis_d.getTerm()) {      trellis_d.insertArc(src, dst, false, weight_a);    }  }  // print debugging information  //  if (debug_level_d >= Integral::DETAILED) {      GraphVertex<SearchNode>* src_vertex = src->getItem()->getReference()->getCentralVertex();    GraphVertex<SearchNode>* dst_vertex = dst->getItem()->getReference()->getCentralVertex();        long src_frame = src->getItem()->getFrame();    long dst_frame = dst->getItem()->getFrame();      SearchSymbol src_sym;    if (src_vertex->isStart()) {      src_sym.assign(L"_START_");    }    else if (src_vertex->isTerm()) {      src_sym.assign(L"_TERM_");    }    else {      src->getItem()->getReference()->print(src_sym);    }       SearchSymbol dst_sym;    if (dst_vertex->isStart()) {      dst_sym.assign(L"_START_");    }    else if (dst_vertex->isTerm()) {      dst_sym.assign(L"_TERM_");    }    else {      dst->getItem()->getReference()->print(dst_sym);    }        String val;      String output(L"\n-> source: ");    output.concat(src_vertex);    output.concat(L", destination: ");    output.concat(dst_vertex);            output.concat(L"\n   [");    output.concat(src_sym);    output.concat(L"], frame: ");    val.assign((long)src_frame);      output.concat(val);    output.concat(L" -> [");    output.concat(dst_sym);    output.concat(L"], frame: ");    val.assign((long)dst_frame);      output.concat(val);    Console::put(output);  }    // exit gracefully  //  return true;}// method: insertNewPath//// arguments://   Instance* parent: (input) source instance//   Instance* child: (input) destination instance//   float weight: (input) transition probability//// return: logical error status//// method adds a new path to the trellis//boolean HierarchicalSearch::insertNewPath(Instance* parent_a,Instance* child_a,					  float weight_a) {  // declare local variables  //  BiGraphVertex<TrainNode>* ptr = (BiGraphVertex<TrainNode>*)NULL;  BiGraphVertex<TrainNode>* src = (BiGraphVertex<TrainNode>*)NULL;  BiGraphVertex<TrainNode>* dst = (BiGraphVertex<TrainNode>*)NULL;    // make sure that the child instances is not null  //  if (child_a == (Instance*)NULL) {    return false;  }  // when the parent is null we are at the begining of the utterance  //  if (parent_a == (Instance*)NULL) {    // get the parent and child vertices    //    src = trellis_d.getStart();    dst = insertInstance(child_a);        // add a transition in the trellis from the parent to the child    //    if (src != trellis_d.getTerm()) {      trellis_d.insertArc(src, dst, false, 0);    }    return true;  }  // retrieve the refernece pointer  //  ptr = parent_a->getReference();    // check to see if the parent trace exists in the map  //  if (ptr != (BiGraphVertex<TrainNode>*)NULL) {        // get the parent and child vertices    //    src = ptr;    dst = insertInstance(child_a);        // add a transition in the trellis from the parent to the child    //    if (src != trellis_d.getTerm()) {      trellis_d.insertArc(src, dst, false, weight_a);    }  } else {        // get the parent and child vertices    //        src = insertInstance(parent_a);    dst = insertInstance(child_a);    // add a transition in the trellis from the parent to the child    //        if (src != trellis_d.getTerm()) {      trellis_d.insertArc(src, dst, false, weight_a);    }  }  // print debugging information  //  if (debug_level_d >= Integral::DETAILED) {      GraphVertex<SearchNode>* src_vertex = src->getItem()->getReference()->getCentralVertex();    GraphVertex<SearchNode>* dst_vertex = dst->getItem()->getReference()->getCentralVertex();        long src_frame = src->getItem()->getFrame();    long dst_frame = dst->getItem()->getFrame();      SearchSymbol src_sym;    if (src_vertex->isStart()) {      src_sym.assign(L"_START_");    }    else if (src_vertex->isTerm()) {      src_sym.assign(L"_TERM_");    }    else {      src->getItem()->getReference()->print(src_sym);    }       SearchSymbol dst_sym;    if (dst_vertex->isStart()) {      dst_sym.assign(L"_START_");    }    else if (dst_vertex->isTerm()) {      dst_sym.assign(L"_TERM_");    }    else {      dst->getItem()->getReference()->print(dst_sym);    }        String val;      String output(L"\n-> source: ");    output.concat(src_vertex);    output.concat(L", destination: ");    output.concat(dst_vertex);            output.concat(L"\n   [");    output.concat(src_sym);    output.concat(L"], frame: ");    val.assign((long)src_frame);      output.concat(val);    output.concat(L" -> [");    output.concat(dst_sym);    output.concat(L"], frame: ");    val.assign((long)dst_frame);      output.concat(val);    Console::put(output);  }    // exit gracefully  //  return true;}// method: insertOldPath//// arguments://   Trace* parent: (input) source trace//   Trace* child: (input) destination trace//   float weight: (input) transition probability//// return: logical error status//// method adds a new path to the trellis//boolean HierarchicalSearch::insertOldPath(Trace* parent_a, Trace* child_a,					  float weight_a) {  // declare local variables  //  BiGraphVertex<TrainNode>* ptr = (BiGraphVertex<TrainNode>*)NULL;    BiGraphVertex<TrainNode>* src = (BiGraphVertex<TrainNode>*)NULL;  BiGraphVertex<TrainNode>* dst = (BiGraphVertex<TrainNode>*)NULL;    // make sure that neither the parent nor the child traces are null  //  if ((parent_a == (Trace*)NULL) || (child_a == (Trace*)NULL)) {    return false;  }    // check to see if the parent trace exists in the map  //    ptr = parent_a->getReference();  if (ptr != (BiGraphVertex<TrainNode>*)NULL) {    src = ptr;  }

⌨️ 快捷键说明

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