コード例 #1
0
  public void doTest2() {
    final int totalGenerated = 1000000;
    final int maxRandom = 100000;
    final int bucketSize = 100;
    final int iterations = 100;
    // final int samplesPerIteration = 100;

    ACETree aceTree;
    ACETreeSearch aceTreeSearch = null;

    ArrayList<Distribution> distributionsACETree = new ArrayList<Distribution>();
    ArrayList<Distribution> distributionsRandom = new ArrayList<Distribution>();

    /* Create data */
    Data dataACETree = new Data(totalGenerated, maxRandom);

    /* construct the ACETree */
    int numbers[] = new int[dataACETree.d.size()];
    for (int i = 0; i < numbers.length; i++) {
      numbers[i] = dataACETree.d.get(i);
    }
    aceTree = new ACETree(numbers);
    aceTreeSearch = new ACETreeSearch(aceTree, new Range(0, maxRandom));

    /* create distribution for ACETree */
    Buckets bucketsACETree = new Buckets(dataACETree, bucketSize, maxRandom);
    Distribution distACETree = new Distribution("ACETree", dataACETree, bucketsACETree);
    distACETree.print();
    distributionsACETree.add(distACETree);

    /* create distribution for RANDOM */
    Data dataRandom = new Data(dataACETree);
    Buckets bucketsRandom = new Buckets(dataRandom, bucketSize, maxRandom);
    Distribution distRandom = new Distribution("Random", dataRandom, bucketsRandom);
    distRandom.print();
    distributionsRandom.add(distACETree);

    Distribution dPrevACETree = distACETree;
    Distribution dPrevRandom = distRandom;

    for (int iter = 0; iter < iterations; iter++) {
      /* Remove the samples from ACETree */
      ArrayList<Integer> result = aceTreeSearch.search();

      Util.log(Util.None, "[%d] Samples returned from the ACETree\n", result.size());

      /* remove this from our bucket */
      for (int i : result) {
        dataACETree.d.remove(new Integer(i));
      }

      /* Remove the same number from Random */
      for (int samples = 0; samples < result.size(); samples++) {
        int index = (int) (dataRandom.d.size() * Math.random());
        dataRandom.d.remove(index);
      }

      /* create a new distribution for ACETree: */
      Buckets bNewACETree = new Buckets(dataACETree, bucketSize, maxRandom);
      Distribution dNewACETree = new Distribution("ACETree", dataACETree, bNewACETree);
      dNewACETree.print();
      distributionsACETree.add(dNewACETree);

      /* compare with the previous distribution */
      // dNewACETree.compare(dPrevACETree);
      dPrevACETree = dNewACETree;

      /* create a new distribution for Random: */
      Buckets bNewRandom = new Buckets(dataRandom, bucketSize, maxRandom);
      Distribution dNewRandom = new Distribution("Random", dataRandom, bNewRandom);
      dNewRandom.print();
      distributionsRandom.add(dNewRandom);

      /* compare with the previous distribution */
      // dNewRandom.compare(dPrevRandom);
      dPrevRandom = dNewRandom;
    }

    Distribution dFirst, dLast;

    Util.log(Util.Minimal, "Size of distributions [%d]\n", distributionsACETree.size());

    Util.log(Util.Minimal, "Comparing ACETree\n");
    dLast = distributionsACETree.get(distributionsACETree.size() - 1);
    dFirst = distributionsACETree.get(0);
    dLast.compare(dFirst);

    Util.log(Util.Minimal, "Comparing Random\n");
    Util.log(Util.Minimal, "Size of distributions [%d]\n", distributionsRandom.size());
    dLast = distributionsRandom.get(distributionsRandom.size() - 1);
    dFirst = distributionsRandom.get(0);
    dLast.compare(dFirst);
  }
コード例 #2
0
  /*
   *
   * 1. Create random data.  Create bucket for it and store it.
   * 2. for a few iterations:
   * 2.   Draw some random samples from data.
   * 3.   Create another distribution.
   * 4.   Compare the distribution with the previous one for score.
   */
  public void doTest(int sampleMethod) {
    final int totalGenerated = 100000;
    final int maxRandom = 10000;
    final int bucketSize = 100;
    final int iterations = 2;
    final int samplesPerIteration = 100;

    ACETree aceTree;
    ACETreeSearch aceTreeSearch = null;

    ArrayList<Distribution> distributions = new ArrayList<Distribution>();

    /* Create data */
    Data data = new Data(totalGenerated, maxRandom);

    if (sampleMethod == ACETreeSample) {
      int numbers[] = new int[data.d.size()];
      for (int i = 0; i < numbers.length; i++) {
        numbers[i] = data.d.get(i);
      }
      aceTree = new ACETree(numbers);
      aceTreeSearch = new ACETreeSearch(aceTree, new Range(0, maxRandom));
    }

    Buckets buckets = new Buckets(data, bucketSize, maxRandom);
    Distribution distribution =
        new Distribution(sampleMethod == RandomSample ? "Random" : "ACETree", data, buckets);
    distribution.print();
    distributions.add(distribution);

    Distribution dPrev = distribution;
    for (int iter = 0; iter < iterations; iter++) {
      /* remove a few samples */
      if (sampleMethod == RandomSample) {
        for (int samples = 0; samples < samplesPerIteration; samples++) {
          int index = (int) (data.d.size() * Math.random());
          data.d.remove(index);
        }
      } else if (sampleMethod == ACETreeSample) {
        ArrayList<Integer> result = aceTreeSearch.search();

        Util.log(Util.None, "[%d] Samples returned from the ACETree\n", result.size());

        /* remove this from our bucket */
        for (int i : result) {
          data.d.remove(new Integer(i));
        }
      }

      /* create a new distribution */
      Buckets bNew = new Buckets(data, bucketSize, maxRandom);
      Distribution dNew =
          new Distribution(sampleMethod == RandomSample ? "Random" : "ACETree", data, bNew);
      dNew.print();
      distributions.add(dNew);

      /* compare with the previous distribution */
      dNew.compare(dPrev);
      dPrev = dNew;
    }
  }