Exemple #1
0
void KDTree::BuildTree()
{
	uint32_t primCount = GetPrimitiveCount();
	
	uint32_t* indices = new uint32_t[primCount];

	// Cache prim bounds
	vector<BoundingBoxf> primBounds;
	primBounds.reserve(primCount);
	for (uint32_t i = 0; i < GetPrimitiveCount(); ++i) 
	{
		indices[i] = i;
		BoundingBoxf b = GetBound(i);
		mBound = Merge(mBound, b);
		primBounds.push_back(b);
	}

	// Allocate working memory for kd-tree construction
	BoundEdge *edges[3];
	for (int i = 0; i < 3; ++i)
		edges[i] = new BoundEdge[2*primCount];
	uint32_t *prims0 = new uint32_t[primCount];
	uint32_t *prims1 = new uint32_t[(mMaxDepth+1) *primCount];

}
 int divide(int dividend, int divisor) {
     bool isPos = false;
     if(0 == dividend) {return 0;}
     if((dividend > 0 && divisor > 0) || (dividend < 0 && divisor < 0))
     {
         isPos = true;
     }
     else
     {
         isPos = false;
     }
     long long divdendll = dividend;
     long long divisorll = divisor;
     if(divdendll < 0) {divdendll = 0 - divdendll;}
     if(divisorll < 0) {divisorll = 0 - divisorll;}
     if(divdendll < divisor) {return 0;}
     int n = GetBound(divdendll, divisorll);
     long long ret = BSearch(divdendll, divisorll, n);
     if(!isPos) {ret = 0 - ret;}
     return ret;
 }
Exemple #3
0
void TNetInfBs::GreedyOpt(const int& MxEdges) {
    double CurProb = GetAllCascProb(-1, -1);
    double LastGain = TFlt::Mx;
    int attempts = 0;
    bool msort = false;

    for (int k = 0; k < MxEdges && EdgeGainV.Len() > 0; k++) {
      double prev = CurProb;

      const TIntPr BestE = GetBestEdge(CurProb, LastGain, msort, attempts);
      if (BestE == TIntPr(-1, -1)) // if we cannot add more edges, we stop
    	  break;

      if (CompareGroundTruth) {
    	  double precision = 0, recall = 0;
    	  if (PrecisionRecall.Len() > 1) {
    		  precision = PrecisionRecall[PrecisionRecall.Len()-1].Val2.Val;
    		  recall = PrecisionRecall[PrecisionRecall.Len()-1].Val1.Val;
    	  }
    	  if (GroundTruth->IsEdge(BestE.Val1, BestE.Val2)) {
			  recall++;
		  }	else {
			  precision++;
		  }

    	  PrecisionRecall.Add(TPair<TFlt, TFlt>(recall, precision));
      }

      Graph->AddEdge(BestE.Val1, BestE.Val2); // add edge to network

      double Bound = 0;
      if (BoundOn)
    	  Bound = GetBound(BestE, prev);

      // localized update!
      TIntV &CascsEdge = CascPerEdge.GetDat(BestE); // only check cascades that contain the edge
      for (int c = 0; c < CascsEdge.Len(); c++) {
    	  CascV[CascsEdge[c]].UpdateProb(BestE.Val1, BestE.Val2, true); // update probabilities
      }

      // some extra info for the added edge
      TInt Vol; TFlt AverageTimeDiff; TFltV TimeDiffs;
      Vol = 0; AverageTimeDiff = 0;
      for (int i=0; i< CascV.Len(); i++) {
    	  if (CascV[i].IsNode(BestE.Val2) && CascV[i].GetParent(BestE.Val2) == BestE.Val1) {
    		  Vol += 1; TimeDiffs.Add(CascV[i].GetTm(BestE.Val2)-CascV[i].GetTm(BestE.Val1));
    		  AverageTimeDiff += TimeDiffs[TimeDiffs.Len()-1]; }
      }
      AverageTimeDiff /= Vol;
      if (TimeDiffs.Len() > 0)
    	  TimeDiffs.Sort();
      else
    	  TimeDiffs.Add(0);

      // compute bound only if explicitly required
      EdgeInfoH.AddDat(BestE) = TEdgeInfo(Vol,
										  LastGain,
										  Bound,
										  TimeDiffs[(int)(TimeDiffs.Len()/2)],
										  AverageTimeDiff);
    }

    if (CompareGroundTruth) {
  	  for (int i=0; i<PrecisionRecall.Len(); i++) {
  		  PrecisionRecall[i].Val2 = 1.0 - PrecisionRecall[i].Val2/(PrecisionRecall[i].Val2+PrecisionRecall[i].Val1);
  		  PrecisionRecall[i].Val1 /= (double)GroundTruth->GetEdges();
  	  }
    }
}