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

📄 hsrch_14.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
	ulong symbol_id = (ulong)tmp_instance->getSymbol()->getCentralVertex();	tmp_instance->setSkipSymbol(symbol_id);	tmp_instance->setSymbol(context_pool_d.setCentralAndAllocate(tmp_instance->getSymbol(), tmp_vert));		// set the one before central context	//	tmp_instance->getSymbol()->setBeforeCentralVertex(symbol_id);	// add the instance to current level's instance list	//	addInstance( level_num_a - 1, new_instance, tmp_instance, pruning);	// clean the memory	//	if (new_instance->getRefCount() < 1	    && new_instance != curr_instance_a) {	  delete new_instance;	}	// exit gracefully	//	return true;      }            if ( new_instance->getInstanceState() == Instance::ACTIVE &&	   new_instance->getSkipLevel() == (ulong) level_num_a - 1 ){		Instance* tmp_instance = new Instance(*new_instance);	tmp_instance->setFrame((ulong)current_frame_d);	tmp_instance->setBackPointer(new_instance);	// set the new pointers	//	middle_instance = new_instance;	new_instance = tmp_instance;		// swap the central vertex	//	tmp_vert = (GraphVertex<SearchNode>*)new_instance->getSkipSymbol();	ulong symbol_id = (ulong)new_instance->getSymbol()->getCentralVertex();	new_instance->setSkipSymbol(symbol_id);	new_instance->setSymbol(context_pool_d.setCentralAndAllocate(new_instance->getSymbol(), tmp_vert));		// set to normal condition	//	new_instance->setInstanceState(Instance::INACTIVE);	      }            tmp_vert = new_instance->getSymbol()->getLastVertex();          }  }  // central vertext is an terminal, ready for propagate at the same level  //  else if (curr_context->getLastVertex()->getItem()->isDummyNode()) {    // new instance    //    new_instance = curr_instance_a;    tmp_vert = curr_context->getLastVertex();    dummy_node = true;    same_level = true;  }  // central vertext is an terminal, ready for propagate at the same level  //  else if (curr_context->getCentralVertex()->isStart()) {    // new instance    //    new_instance = curr_instance_a;    tmp_vert = curr_context->getLastVertex();    same_level = true;  }  // last vertext is at one level above, ready for propagate up  //  else if (curr_context->getLastVertex()->getItem()->	   getSearchLevel()->getLevelIndex() ==  level_num_a - 1) {    // new instance    //    new_instance = new Instance(*curr_instance_a);    new_instance->setFrame((ulong)current_frame_d);    new_instance->setBackPointer(curr_instance_a);    //tmp_score = getPosteriorScore(new_instance);    //new_instance->setScore(new_instance->getScore() + tmp_score);    // decrement the history of the new instance    //    changeHistory(new_instance, true);        new_instance->setSymbol(context_pool_d.shiftAndAllocate(new_instance->getSymbol(), curr_context->getLastVertex()));        tmp_vert = new_instance->getSymbol()->getLastVertex();    // apply n-symbol score    //    applyNSymbolScore(new_instance, level_num_a - 1);  }    // ready for propagate down, keep this instance  //  else if ( curr_context->getLastVertex()->getItem()->	    getSearchLevel()->getLevelIndex() >=  level_num_a ) {        // ready for propagate down, keep the instance    //    return false;  }  // give error message, it can not happen in a correct situation  //  else {    return Error::handle(name(),			 L"ascendInstance: Wrong instance",			 Error::ARG,			 __FILE__, __LINE__);  }  // keep the instance for propagate down  //  if ( tmp_vert == (GraphVertex<SearchNode>*)NULL) {        // new instance    //    tmp_instance = new Instance(*new_instance);    tmp_instance->setFrame((ulong)current_frame_d);    // generate a NULL right context    //    tmp_instance->setSymbol(context_pool_d.shiftAndAllocate(tmp_instance->getSymbol(), (GraphVertex<SearchNode>*)NULL));    if ( same_level ){      // add the instance to current level's instance list      //      addInstance( level_num_a, new_instance, tmp_instance, pruning);    }    else {      // add the instance to the higher level's instance list      //      addInstance( level_num_a - 1 , new_instance, tmp_instance, pruning);    }    // clean the memory, must clear new_instance first    //    if (new_instance->getRefCount() < 1	&& new_instance != curr_instance_a) {      delete new_instance;    }    // clean the memory, clear the middle_instance the second    //    if ( middle_instance != NULL ){      if (middle_instance->getRefCount() < 1	  && middle_instance != curr_instance_a) {	delete middle_instance;      }    }        // exit    //    return true;  }    // error, ISIP_REMOVE, this check can be removed  //  if (tmp_vert->isTerm()) {    return Error::handle(name(),			 L"ascendInstance: Wrong instance",			 Error::ARG,			 __FILE__, __LINE__);  }  // generate instances to all next vertices  //	    for (boolean more_paths = tmp_vert->gotoFirst(); more_paths;       more_paths = tmp_vert->gotoNext()) {        // create a new instance, we store the extra instance so we    // can later view the scores as they are added. this can    // be changed later for efficiency    //    tmp_instance = new Instance(*new_instance);    tmp_instance->setFrame((ulong)current_frame_d);          // update the score with the arc score    //    tmp_arc = tmp_vert->getCurr();    tmp_score = tmp_instance->getScore() + tmp_arc->getWeight();    tmp_instance->setScore(tmp_score);        // change the history    //    if ( dummy_node ){      tmp_instance->setSymbol(context_pool_d.setLastAndAllocate(tmp_instance->getSymbol(), tmp_arc->getVertex()));    }    else{      tmp_instance->setSymbol(context_pool_d.shiftAndAllocate(tmp_instance->getSymbol(), tmp_arc->getVertex()));    }        // add the instance to current level's instance list    //    if ( same_level ){      addInstance( level_num_a, new_instance, tmp_instance,  pruning);    }    // add the instance to the higher level's instance list    //    else {      addInstance( level_num_a - 1 , new_instance, tmp_instance, pruning);    }  }      // clean the memory, must clear new_instance first    //    if (new_instance->getRefCount() < 1	&& new_instance != curr_instance_a) {      delete new_instance;    }    // clean the memory, clear the middle_instance the second    //    if ( middle_instance != NULL ){      if (middle_instance->getRefCount() < 1	  && middle_instance != curr_instance_a) {	delete middle_instance;      }    }      // exit gracefully  //  return true;  }// method: descendInstance//// arguments://  long level_num: (input) the level for which we will propagate instances//  Instance*& curr_instance_a: (input) the instance that we want to descend//// return: logical error status//// propagate the instance down the hierarchy.//boolean HierarchicalSearch::descendInstance(long level_num_a,				 Instance*& curr_instance_a) {  // local variable  //  Context* curr_context = curr_instance_a->getSymbol();  Instance* new_instance = (Instance*) NULL;  Instance* tmp_instance = (Instance*) NULL;    GraphVertex<SearchNode>* tmp_vert = (GraphVertex<SearchNode>*)NULL;  GraphArc<SearchNode>* tmp_arc = (GraphArc<SearchNode>*)NULL;    float tmp_score = 0;  boolean pruning = true;  boolean ascend = false;  // if central is NULL, propagate down  //  if (curr_context->getCentralVertex() == (GraphVertex<SearchNode>*)NULL) {    // new instances    //    new_instance = new Instance(*curr_instance_a);    new_instance->setFrame((ulong)current_frame_d);    // descend one level    //    changeHistory(new_instance, ascend, level_num_a,		  (GraphVertex<SearchNode>*)NULL);      new_instance->setSymbol(context_pool_d.setLastAndAllocate(new_instance->getSymbol(), (GraphVertex<SearchNode>*)NULL));    // add the instance to the lower level's instance list    //    addInstance( level_num_a + 1 , curr_instance_a, new_instance, pruning);    // new instance is added, now exit    //    return true;  }    // 1) central is start, or  // 2) last node is the dummy node, the term node or at a higher level,  //    ready for propagate up  if  ((curr_context->getLastVertex()	!= (GraphVertex<SearchNode>*)NULL) &&       ( curr_context->getCentralVertex()->isStart() ||	 curr_context->getLastVertex()->isTerm() ||	 curr_context->getLastVertex()->getItem()->isDummyNode() ||	 curr_context->getLastVertex()->getItem()->	 getSearchLevel()->getLevelIndex() <  level_num_a )) {    // no new instance generated    //    return false;      }  // this part is added for skip-symbols  // if curr_instance_a is inactive and the last vertex is "sp"  // and level_num_a is the same as the curr_context->getLastVertex()  // ->getItem()->getSearchLevel()->getLevelIndex()  // 1) find all the successors of sp  // 2) generate new instances point to the central vertex, set the status  //    to pesudo_active, save the vertex "sp" in the instance  // 3) return  //  if ( curr_context->getLastVertex() != (GraphVertex<SearchNode>*)NULL) {    tmp_vert = curr_context->getLastVertex();    long symbol_id = tmp_vert->getItem()->getSymbolId();    // error checking    //    if ( getSearchLevel(level_num_a).isSkipSymbol(symbol_id) &&	 getSearchLevel(level_num_a).getRightContext() > 1 ){      return Error::handle(name(), L"propagateInstancesDown: skip symbol can't specified at the search level with right context great than one", Error::ARG,__FILE__, __LINE__);	        }    // if current symbol is skip symbol    //    if ( getSearchLevel(level_num_a).isSkipSymbol(symbol_id) &&	 getSearchLevel(level_num_a).getRightContext() > 0 &&	 tmp_vert->getItem()->getSearchLevel()->getLevelIndex() == level_num_a          && curr_context->getCentralVertex()->getItem()->getSearchLevel()->getLevelIndex() == level_num_a ){      // loop over all paths in the subgraph and create new      // instances in the next level      //      for (boolean more_paths = tmp_vert->gotoFirst(); more_paths;	   more_paths = tmp_vert->gotoNext()) {      	// initialize central vertex of the context	//	tmp_arc = tmp_vert->getCurr();      	// create a new instance, we store the extra instance so we	// can later view the scores as they are added. this can	// be changed later for efficiency	//	tmp_instance = new Instance(*curr_instance_a);	tmp_instance->setFrame((ulong)current_frame_d);      	// update the score with the arc score	//	tmp_score = tmp_instance->getScore() + tmp_arc->getWeight();	tmp_instance->setScore(tmp_score);      	// set the instance as special	//	tmp_instance->setSkipSymbol((ulong)tmp_vert);	tmp_instance->setSkipLevel(level_num_a);	tmp_instance->setInstanceState(Instance::PSEUDO_ACTIVE);		tmp_instance->setSymbol(context_pool_d.setLastAndAllocate(tmp_instance->getSymbol(), tmp_arc->getVertex()));		// add the instance to current level's instance list	//	addInstance( level_num_a, curr_instance_a, tmp_instance, false);      }      // exit gracefully      //      return true;    }  }    // central vertext is at the same level , ready for propagate down  //  if (curr_context->getCentralVertex()->getItem()->	   getSearchLevel()->getLevelIndex() ==  level_num_a ) {        // new instance    //    new_instance = curr_instance_a;    new_instance->setFrame((ulong)current_frame_d);    // acces the subgraph's start vertex    //    SearchLevel& sl_curr = getSearchLevel(level_num_a);    SearchLevel& sl_lower = getSearchLevel(level_num_a + 1);    // convert context vertices to search symbol indices    // we need to do it before hashing in getSubGraphIndex    //    Context convert_context = *curr_context;    Context* tmp_context = (Context*)NULL;    Ulong* subgr_ind = (Ulong*)NULL;        long symbol_id = curr_context->getCentralVertex()->      getItem()->getSymbolId();    // this part is added for skip-symbols    // if curr_instance is active and the central is sp, evaluate    // sp and replace the central sp with the original vertex, set to     //    if ( getSearchLevel(level_num_a).isSkipSymbol(symbol_id) ){            // if the instance is not active, return error      //      if ( new_instance->getInstanceState() != Instance::ACTIVE ){	return Error::handle(name(), L"propagateInstancesDown: search error, incorrect state for skip symbol",			   Error::ARG,__FILE__, __LINE__);	    	      }      else{	// swap the central vertex	//	//tmp_vert = (GraphVertex<SearchNode>*)new_instance->getSkipSymbol();	//new_instance->getHistory()->peek()->setCentralVertex((ulong)tmp_vert);	// back to normal operation	//	//new_instance->setInstanceState(Instance::INACTIVE);      }    }        // special case for those context-less symbols    //    if ( getSearchLevel(level_num_a).isContextLessSymbol(symbol_id) ||	 getSearchLevel(level_num_a).isSkipSymbol(symbol_id) ){            // generate the new context      //      long left_context_length =	getSearchLevel(level_num_a).getLeftContext();      long right_context_length =	getSearchLevel(level_num_a).getRightContext();      long central_pos = right_context_length + 1;      long total_context_length = left_context_length + central_pos;      // error checking      //      if (getSearchLevel(level_num_a).getLeftContext() !=	  getSearchLevel(level_num_a).getRightContext()) {	return Error::handle(name(), L"descendInstance - left and right context lengths must be the same", Error::ARG, __FILE__, __LINE__);	      }            // initialize the left context      //      tmp_context = new Context(total_context_length, central_pos);      for (long i = 0; i < left_context_length; i++) {	tmp_context->assignAndAdvance(getSearchLevel(level_num_a).getSymbolIndex(SearchSymbol::NO_LEFT_CONTEXT));      }      // initialize central vertex of the context      //      tmp_context->assignAndAdvance(symbol_id);            // initialize right vertices of the context      //	            for (long i = 0; i < right_context_length; i++) {	tmp_context->assignAndAdvance(getSearchLevel(level_num_a).getSymbolIndex(SearchSymbol::NO_RIGHT_CONTEXT));      }    }    // if it is not the context less symbol    //    else{            convert_context.convert(tmp_context);    }    // get the index corresponding to the current context    //    subgr_ind = sl_curr.getSubGraphIndex(*tmp_context);        if (subgr_ind == (Ulong*)NULL) {      String context;      curr_context->print(context);      String output(L"**** no subgraph found for context ");      output.concat(context);      output.concat(L" at level ");      output.concat(level_num_a);      output.concat(L" ****");      Console::put(output);      return Error::handle(name(), L"propagateInstancesDown", Error::ARG, __FILE__, __LINE__);	        }

⌨️ 快捷键说明

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