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

📄 pdt_07.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/pr/PhoneticDecisionTree/pdt_07.cc// version: $Id: pdt_07.cc,v 1.9 2002/11/03 05:53:34 parihar Exp $//// isip include files//#include "PhoneticDecisionTree.h"// method: getStatTrain//// arguments://  Vector<ContextMap>& comtext_map: (input) context-map//  Vector<DiGraph<SearchNode>& sub_graphs: (input) sub-graphs//  Vector<SearchSymbol>& symbol_table: (input) symbol-table//  Vector<SearchSymbol>& contextless_symbol_table: (input) contextless//                                                  symbol-table//  Vector<StatisticalModel>& stat_models: (input/output) Pool of//                                         StatisticalModels//  HashTable<SearchSymbol, Long>& symbol_hash: (input/output) Mapping from//                                                symbols to StatisticalModels//  Filename& ques_ans_file: (input) file for phonetic questions and answers//  HashTable<SearchSymbol, Long>& tied_symbol_hash: (output) hashtable//                                                containing the tied symbols// Vector<StatisticalModel>& tied_stat_models_a: tied models//// return: a boolean value indicating status//// this method gets the new set of statistical models and a mapping// table that maps symbols(states) to the statistical models. it also// stores the decision-tree in the binary format//boolean PhoneticDecisionTree::getStatTrain(Vector<ContextMap>& context_map_a,					   Vector<DiGraph<SearchNode> >&					   sub_graphs_a,					   Vector<SearchSymbol>&					   symbol_table_a,					   Vector<SearchSymbol>&					   contextless_symbol_table_a,					   HashTable<SearchSymbol,Long>&					   symbol_hash_a,					   Vector<StatisticalModel>&					   stat_models_a,					   Filename& phonetic_dt_file_a,					   HashTable<SearchSymbol, Long>&					   tied_symbol_hash_a,					   Vector<StatisticalModel>&					   tied_stat_models_a) {    // local variables  //  boolean res = true;  TreeNode* root_node = (TreeNode*)NULL;  SingleLinkedList<TreeNode> leaf_nodes(DstrBase::USER);  HashTable<Long, Long> map;  Vector<StatisticalModel> stat_models_out;  HashTable<SearchSymbol,Long> symbol_hash_out;    // get all the leaf nodes below the root-node  //  root_node = getFirst();    // check the node  //  if (root_node == (TreeNode*)NULL) {    return Error::handle(name(), L"getStatTrain - NULL VERTEX",			 Error::ARG, __FILE__, __LINE__);  }    res = getLeafNodes(*root_node, leaf_nodes);  // set the capacity of the stat_models_out. each leaf node has a  // typical-statistical model  //  long stat_len = leaf_nodes.length() + tied_stat_models_a.length();  stat_models_out.setCapacity(stat_len);  stat_models_out.setLength(leaf_nodes.length());      // loop-over all the leaf-nodes that exists (that were not merged)  // and reindex the map  //  for (boolean more = leaf_nodes.gotoFirst(); more;       more = leaf_nodes.gotoNext()) {    // local variables    //    TreeNode* node = (TreeNode*)NULL;    // get the leaf-node    //    node = leaf_nodes.getCurr();    // check the node    //    if (node == (TreeNode*)NULL) {      return Error::handle(name(), L"getStatTrain - NULL VERTEX",			   Error::ARG, __FILE__, __LINE__);    }    // local variables    //    PhoneticDecisionTreeNode* pdt_node = (PhoneticDecisionTreeNode*)NULL;    Long index = (Long)-1;    boolean flag_exists = true;      // loop-over all the data at this leaf-node and get the typical    // statistical-model to which all the rest of the    // statistical-models at this node will be tied to. the model with    // the highest scale or lowest variance is a typical model    //    // get all the data points on the node    //    pdt_node = node->getItem();    // check the node    //    if (pdt_node == (PhoneticDecisionTreeNode*)NULL) {      return Error::handle(name(), L"getStatTrain - NULL PDT VERTEX",			   Error::ARG, __FILE__, __LINE__);    }    Data& data = pdt_node->getDataPoints();        // get the typical statistical-model at this pdt-node    //    StatisticalModel& typical_stat_model = pdt_node->getTypicalStatModel();            // see if this pdt-node exists    //    flag_exists = pdt_node->getFlagExists();        // proceed further only if this node exists, otherwise the data on    // this node is already merged to some other node    //    if(flag_exists) {            // get the typical-index of the statistical-model at this pdt-node      //      index = pdt_node->getTypicalIndex();            for (boolean morea = data.gotoFirst(); morea; morea = data.gotoNext()) {		// local variables	//	Long temp_index = 0;		// get the index of this statistical-model	//	DataPoint* datapoint = data.getCurr();	temp_index = datapoint->first();		// reindexing from previous to new indices in the hashtable	//	if (!map.insert(temp_index, &index)) {	  return Error::handle(name(), L"getStatTrain",			       ERR, __FILE__, __LINE__);	}      } // end of for-loop over all datapoints at a leafnode    } // end of if statement for leaf-nodes that exists        // add the typical statistical model at this leafnode to the new    // pool of statistical models    //    long actual_index = -1;    actual_index = pdt_node->getActualIndex();    stat_models_out(actual_index).assign(typical_stat_model);  } // end of for loop over leaf-nodes    // create the new mapping table  //  Vector<SearchSymbol> symbols;  res = symbol_hash_a.keys(symbols);  // add the untied models  //  for (long moreb = 0; moreb < symbols.length(); moreb++) {    SearchSymbol temp_symbol = symbols(moreb);    Long prev_index;    prev_index = *(symbol_hash_a.get(temp_symbol));    Long new_index;    // if the statistical model corresponding to the search symbol is    // not tied    //    if (!tied_symbol_hash_a.containsKey(temp_symbol)) {      new_index = *(map.get(prev_index));      if (!symbol_hash_out.insert(symbols(moreb), &new_index)) {	return Error::handle(name(), L"poolStatTrain",			     ERR, __FILE__, __LINE__);      }	             }  }    // update the tied and contexts with contextless symbols as central  // symbols  //  for (long i = 0; i < tied_stat_models_a.length(); i++) {    // add the statistical model    //    Long tmp_index = stat_models_out.length();    stat_models_out.setLength((long)tmp_index + (long)1);    stat_models_out(tmp_index).assign(tied_stat_models_a(i));        // add all the search-symbols that are tied to this same    // statistical-model    //    Vector<SearchSymbol> tied_symbols;    tied_symbol_hash_a.keys(tied_symbols);        for (long j = 0; j < tied_symbols.length(); j++) {      long old_index = *(tied_symbol_hash_a.get(tied_symbols(j)));      // update hash_table with the search-symbol & statistical-model      // index      //      if (old_index == i) {	if (!symbol_hash_out.insert(tied_symbols(j), &tmp_index)) {	  return Error::handle(name(), L"poolStatTrain - non-unique search-symbols", ERR, __FILE__, __LINE__);	}	               }    }    }      // update the statistical-models and symbol hashtable  //  stat_models_a.assign(stat_models_out);  symbol_hash_a.assign(symbol_hash_out);      // store the decision-tree into the output file in the binary format  //  if (phonetic_dt_file_a.length() == 0) {     return Error::handle(name(), L"store - invalid decidion-tree file", ERR, __FILE__, __LINE__);  }    // open the decision-tree sof file  //  Sof out_sof;  if(!out_sof.open(phonetic_dt_file_a, File::WRITE_ONLY, File::BINARY)) {    return Error::handle(phonetic_dt_file_a, L"open", ERR, __FILE__, __LINE__);  }    // write the decision-tree to an sof file  //  write(out_sof, long(0));  // close the output sof file  //  out_sof.close();    // exit gracefully  //  return res;}// method: getStatTest//// arguments://  Vector<ContextMap>& context_map: (input) contextMaps//  long& left_context: (input) length of the left-context//  long& right_context: (input) length of the right-context//  Vector<SearchSymbol>& upper_symbol_table: (input) symbol-table at level//                                             upper to the lowest level//  Vector<SearchSymbol>& upper_contextless_symbol_table: (input) contextless//                                                        symbol-table//  Vector<DiGraph<SearchNode> >& sub_graphs: (input) subgraphs for the//                                            contextMaps//  Vector<SearchSymbol>& symbol_table: (input) symbol-table (states)//  HashTable<SearchSymbol, Long>& symbol_hash: (input) mapping from symbols//                                              to statistical-models//  Filename& ques_ans_file: (input) file for phonetic questions and answers//// return: a boolean value indicating status//// this method runs the PhoneticDecisionTree class in TEST mode//boolean PhoneticDecisionTree::getStatTest(Vector<ContextMap>& context_map_a,					  long& left_context_a,					  long& right_context_a,					  Vector<SearchSymbol>&					  upper_symbol_table_a,					  Vector<SearchSymbol>&					  upper_contextless_symbol_table_a,					  Vector<DiGraph<SearchNode> >&					  sub_graphs_a,					  Vector<SearchSymbol>&					  symbol_table_a,					  HashTable<SearchSymbol,Long>&					  symbol_hash_a,					  Filename& ques_ans_file_a) {  // local variables  //  Vector<Triple<Long, String, String> > ques_ans;  SingleLinkedList<Pair<Long, String> > questions;  HashTable<String, String>  answers;  boolean res = true;        // check the question and answers  //  if (ques_ans_file_a.length() == 0) {     return Error::handle(name(), L"loadTest - invalid question-answer file", ERR, __FILE__, __LINE__);  }  // print debugging information  //  if (debug_level_d >= Integral::DETAILED) {    Console::increaseIndention();    String output;    output.assign(L"\nloading question and answers: ");    output.concat(ques_ans_file_a);    Console::put(output);    Console::decreaseIndention();  }  // open the input sof file  //  Sof input_sof;  if(!input_sof.open(ques_ans_file_a, File::READ_ONLY)) {    return Error::handle(ques_ans_file_a, L"open", ERR, __FILE__, __LINE__);

⌨️ 快捷键说明

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