Пример #1
0
int main() {
  TLSHash LSH(7, 7, DIM, TLSHash::EUCLIDEAN);
  LSH.Init();

  TRnd Gen;
  Gen.Randomize();

  TVec<TFltV> DataV;
  for (int i=0; i<1000000; i++) {
    TFltV Datum;
    for (int j=0; j<3; j++) {
      Datum.Add(Gen.GetUniDev()*2100);
    }
    DataV.Add(Datum);
  }
  LSH.AddV(DataV);
  
  TVec<TPair<TFltV, TFltV> > NeighborsV = LSH.GetAllCandidatePairs();
  printf("Number of Candidates: %d\n", NeighborsV.Len());

  NeighborsV = LSH.GetAllNearPairs();
  printf("Number of Close Pairs: %d\n", NeighborsV.Len());
  for (int i=0; i<NeighborsV.Len(); i++) {
    outputPoint(NeighborsV[i].GetVal1());
    printf(" ");
    outputPoint(NeighborsV[i].GetVal2());
    printf("\n");
  }
  return 0;
}
Пример #2
0
bool generateLinearSeparation(std::vector<point>& inputPoints,
															double& a,
															double& b,
															double& c,
															int& nBad1,
															int& nBad2,
															point& centroidOne,
															point& centroidTwo)
{
	int numOne=0, numTwo=0;
	for (std::vector<point>::iterator pt = inputPoints.begin(); pt != inputPoints.end(); pt++)
	{
		if (pt->isClassOne)
		{
			numOne++;
			centroidOne.x += pt->x;
			centroidOne.y += pt->y;
		}
		else
		{
			numTwo++;
			centroidTwo.x += pt->x;
			centroidTwo.y += pt->y;
		}
	}
	centroidOne.x /= numOne;
	centroidOne.y /= numOne;

	centroidTwo.x /= numTwo;
	centroidTwo.y /= numTwo;

	outputPoint(centroidOne);
	outputPoint(centroidTwo);

	point midpt(
			(centroidTwo.x+centroidOne.x)/2,
			(centroidTwo.y+centroidOne.y)/2);
	outputPoint(midpt);

	//direction vector
	point oneToTwo(
			centroidTwo.x-centroidOne.x,
			centroidTwo.y-centroidOne.y);

	double mag = distance(oneToTwo,point(0,0,false));
	std::cerr << mag << std::endl;

	oneToTwo.x /= mag;
	oneToTwo.y /= mag;
	//actual direction
	
	point bisector(oneToTwo.x,oneToTwo.y);
	outputPoint(bisector);
	
	b = bisector.y;
	a = bisector.x;
	c = -(a*midpt.x+b*midpt.y);

	for (std::vector<point>::iterator pt = inputPoints.begin(); pt != inputPoints.end(); pt++)
	{
		if(pt->isClassOne)
		{
			if(SGN(a*pt->x+b*pt->y+c) != SGN(a*centroidOne.x+b*centroidOne.y+c))
				nBad1++;
		}
		else
		{
			if(SGN(a*pt->x+b*pt->y+c) != SGN(a*centroidTwo.x+b*centroidTwo.y+c))
				nBad2++;
		}
	}
	return true;
}