void ExtendedTbrProposer::buildPath(Path &path, BranchPlain bisectedBranch, TreeAln &traln, Randomness &rand, std::vector<AbstractParameter*> params ) const 
{
  double stopProb = _stopProb; 

  nodeptr p= traln.findNodePtr(bisectedBranch ); 
  path.clear();

  nodeptr pn = p->next->back,
    pnn = p->next->next->back; 
  
  
  auto pnBranch = traln.getBranch(pn, params),
    pnnBranch = traln.getBranch(pnn, params);

  // prune  
  traln.clipNodeDefault(pn, pnn); 
  p->next->next->back = p->next->back = NULL; 

  path.append(bisectedBranch);
  path.append(BranchPlain(pn->number, pnn->number)); 
  nodeptr currentNode = rand.drawRandDouble01() < 0.5  ? pn : pnn;
  bool accepted = false; 
  while(not accepted )
    {
      nodeptr n = 
	rand.drawRandDouble01()  < 0.5 
	? currentNode->next->back
	: currentNode->next->next->back; 

      path.pushToStackIfNovel(BranchPlain(currentNode->number, n->number),traln); 
      currentNode = n;       
      accepted = rand.drawRandDouble01() < stopProb && path.size() > 2 ; 
    }

  // reset
  traln.clipNode(p->next, pn); 
  traln.setBranch(pnBranch, params);
  traln.clipNode(p->next->next, pnn); 
  traln.setBranch(pnnBranch, params);

  // a correction is necessary 
  if(path.at(2).hasNode(path.at(1).getPrimNode() ))
    path.at(1).setSecNode(p->number); 
  else if (path.at(2).hasNode(path.at(1).getSecNode() ))
    path.at(1).setPrimNode(p->number); 
  else 
    assert(0); 

  // for reasons of resetting the first branch in the path must be
  // identifyable later
  path.at(0) = traln.getThirdBranch(bisectedBranch, path.at(1)); 
}
示例#2
0
  std::unique_ptr<AbstractParameter> getParameterFromCategory(Category cat, nat id, nat idOfMyKind, std::vector<nat> partitions, nat numTaxa)
  {
    switch(cat)
      {
      case Category::DIVERGENCE_RATES: 
	return make_unique<DivergenceRates>(id, idOfMyKind, partitions,numTaxa);
      case Category::DIVERGENCE_TIMES: 
	// dummy initialize, let's set the proper node-age object
	// later, as soon as we know the topology 
	return make_unique<DivergenceTimes>(id, idOfMyKind, partitions, NodeAge{BranchPlain(0,0),0.}); 
      case Category::TOPOLOGY :
	return  make_unique<TopologyParameter>( id, idOfMyKind,partitions );
      case Category::BRANCH_LENGTHS:
	return  make_unique<BranchLengthsParameter>( id, idOfMyKind, partitions);
      case Category::FREQUENCIES :
	return  make_unique<FrequencyParameter>( id, idOfMyKind,partitions);
      case Category::SUBSTITUTION_RATES :
	return  make_unique<RevMatParameter>( id, idOfMyKind,partitions);
      case Category::RATE_HETEROGENEITY:
	return  make_unique<RateHetParameter>( id, idOfMyKind,partitions);
      case Category::AA_MODEL :
	return make_unique<ProtModelParameter>( id, idOfMyKind,partitions);
      default : 
	{
	  assert(0); 
	  return make_unique<RateHetParameter>(id, idOfMyKind, partitions);
	}
      }    
  }  
示例#3
0
void ParsSprProposer::testInsertParsimony(TreeAln &traln, nodeptr insertPos, nodeptr prunedTree, branch2parsScore &result, int curDepth)  
{
  if(curDepth == 0 )
    return; 
  --curDepth; 

  nodeptr insertBack =  insertPos->back;   
  traln.clipNode(insertPos, prunedTree->next);
  traln.clipNode( insertBack, prunedTree->next->next); 
  
  auto b = BranchPlain(insertPos->number, insertBack->number); 

  if(_computedInsertions.size() > 0 && _computedInsertions.find(b) != _computedInsertions.end()) 
    {
      result[b] = _computedInsertions.at(b); 
    }
  else 
    {
      ParsimonyEvaluator::disorientNode(prunedTree); 
      result[b] =  _pEval.evaluate(traln, prunedTree, false  ); 
    }

  traln.clipNode(insertPos, insertBack); 
  prunedTree->next->back = prunedTree->next->next->back = NULL; 

  // recursively descend 
  if(not traln.isTipNode(insertPos))
    {
      testInsertParsimony(traln, insertPos->next->back, prunedTree, result, curDepth); 
      testInsertParsimony(traln, insertPos->next->next->back, prunedTree, result, curDepth); 
    }
}
示例#4
0
BranchPlain ParsSprProposer::determinePrimeBranch(const TreeAln &traln, Randomness& rand) const 
{
  auto prunedTree = BranchPlain();
  nodeptr p, pn, pnn;  
  do 
    {
      prunedTree  = TreeRandomizer::drawBranchWithInnerNode(traln,rand); 
      p = traln.findNodePtr(prunedTree);
      pn = p->next->back; 
      pnn = p->next->next->back;         

    } while( (traln.isTipNode(pn) &&  traln.isTipNode(pnn))     ); 

  return prunedTree; 
} 
示例#5
0
/** 
    @brief draw a branch that has an inner node as primary node   
    
    => equals draw subtree uniformly
 */ 
BranchPlain TreeRandomizer::drawBranchWithInnerNode(const TreeAln& traln,Randomness &rand)  
{
  nat idA = drawInnerNode(traln, rand); 
  nat r = rand.drawIntegerClosed(2);  
  nodeptr p = traln.getNode(idA); 
  assert(not traln.isTipNode(p)) ; 

  BranchPlain b; 
  switch(r)
    {
    case 0: 
      b = BranchPlain(idA, p->back->number); 
      break; 
    case 1: 
      b = BranchPlain(idA, p->next->back->number); 
      break; 
    case 2: 
      b = BranchPlain(idA, p->next->next->back->number); 
      break; 
    default: assert(0); 
    }
 
  return b; 
}
示例#6
0
BranchPlain TreeRandomizer::drawBranchUniform_helper(const TreeAln &traln, Randomness &rand , nat curNumTax)  
{ 
  int randId = 0; 
  double r = rand.drawRandDouble01(); 

  // for the randomization part, i assume that when a tree is built
  // successively, I assume that the inner nodes start with an offset
  // in the nodeptr array that is the number of trees in the final
  // tree
  if( r <= 0.75) 		// draw an inner node 
    randId = 1 + traln.getTrHandle().mxtips + rand.drawIntegerClosed(curNumTax -3 )  ; 
  else 				// draw a tip 
    randId = rand.drawIntegerOpen(curNumTax) + 1 ;           

  auto p = traln.getNode(randId); 
  nat thisNode = randId,
    thatNode = 0;   
  if(traln.isTipNode(p))
    {
      thatNode = p->back->number; 
    }
  else 
    {
      switch(rand.drawIntegerOpen(3))
  	{
  	case 0 : 
  	  thatNode = p->back->number; 
  	  break; 
  	case 1 : 
  	  thatNode = p->next->back->number; 
  	  break; 
  	case 2: 
  	  thatNode = p->next->next->back->number; 
  	  break; 
  	default: assert(0); 
  	}
    }

  return BranchPlain(thisNode, thatNode); 
}
示例#7
0
BranchPlain TreeRandomizer::drawInnerBranchUniform( const TreeAln& traln, Randomness &rand)  
{
  bool acc = false;   
  int aNode = 0; 
  nodeptr p = nullptr; 
  while(not acc)
    {      
      aNode = drawInnerNode(traln, rand); 
      p = traln.getNode(aNode); 
      
      nat numTips = 0; 
      if(  traln.isTipNode(p->back) ) 
	numTips++; 
      if(traln.isTipNode(p->next->back))
	numTips++;
      if(traln.isTipNode(p->next->next->back))
	numTips++; 
      
      assert(numTips != 3); 
      
      acc = numTips == 0 || rand.drawRandDouble01() <  (3. - double(numTips)) / 3.;       
    }
  assert(aNode != 0); 
  
  std::vector<nat> options; 
  if(not traln.isTipNode(p->back))
    options.push_back(p->back->number); 
  if(not traln.isTipNode(p->next->back))
    options.push_back(p->next->back->number); 
  if(not traln.isTipNode(p->next->next->back))
    options.push_back(p->next->next->back->number); 

  nat other = 0;
  if(options.size() == 1 )
    other = options[0]; 
  else 
    other = options.at(rand.drawIntegerOpen(int(options.size())));   
  return BranchPlain(aNode, other); 
}
示例#8
0
 InsertionResult(BranchPlain branch = BranchPlain(0,0), log_double prob = log_double::fromAbs(1.), std::vector<OptimizedParameter> optParams = std::vector<OptimizedParameter>{})
   : _branch{branch}
   , _lprob{prob}
   , _optParams{optParams}
 {
 } 
示例#9
0
 BranchLengths(const BranchPlain &b = BranchPlain() , std::vector<InternalBranchLength> lengths = {{}})
   : BranchPlain(b)
   , _lengths(lengths)
 {
 }
示例#10
0
 BranchPlain getInverted() const 
 {
   return BranchPlain(_secNode, _primNode); 
 }