Difference between revisions of "Thread:User talk:Skilgannon/KDTree/Regarding PrioQueue/reply (5)"

From Robowiki
Jump to navigation Jump to search
m (Reply to Regarding PrioQueue)
 
(No difference)

Latest revision as of 04:11, 18 July 2013

Here is the garbage creation code:

 public TestResult doTest(KNNImplementation algorithm, int numNeighbours, SampleData[] data, KNNPoint[][] solution) {
      TestResult result = new TestResult(algorithm.getName(), data.length, numNeighbours, solution);
   
      ArrayList<KNNPoint[]> neighbourLists = new ArrayList<KNNPoint[]>();
      double sum = 0;//DEPENDENCY FOR GARBAGE
      int addCount = 0;
      for (SampleData sample : data) {
         if (sample.save) {
            long time = -System.nanoTime();
            algorithm.addDataPoint(sample.entry);
            time += System.nanoTime();
            result.recordAdd(time);
            addCount++;
         }
      
         if (sample.search) {
            long time = -System.nanoTime();
            KNNPoint[] neighbourList = algorithm.getNearestNeighbors(sample.data, Math.min(numNeighbours, addCount));
            time += System.nanoTime();
            result.recordSearch(neighbourList, time);
         }
         //GARBAGE - vary size of array to vary effect - 0 should have no effect
         double[] garbageD = new double[1000];
         int[] garbageI = new int[garbageD.length];
         for(int i = 0; i < garbageD.length; i++){
            garbageD[i] = Math.random();
            garbageI[i] = (int)(Integer.MAX_VALUE*Math.random());
         }
         for(int i = 0; i < garbageD.length; i++){
            garbageD[i] *= garbageI[garbageD.length-1-i];
            sum += garbageD[garbageD.length-1 - i];
            garbageI[i] -= sum;
         }
      }
      if(sum == -1.0)//DEPENDENCY FOR GARBAGE
         System.out.println("Unlikely event, but cannot be eliminated.");
   
      return result;
   }