Пример #1
0
  // @Test
  public void realCountsInBounds() {
    int n = 4213;
    int size = 50;
    long key;
    double prob = .04;
    double eps = 1.0 / size;
    double delta = .01;
    int bad = 0;

    CountMin countmin = new CountMin(eps, delta);
    PositiveCountersMap realCounts = new PositiveCountersMap();
    for (int i = 0; i < n; i++) {
      key = randomGeometricDist(prob);
      countmin.update(key);
      realCounts.increment(key);
      long realCount = realCounts.get(key);
      long upperBound = countmin.getEstimateUpperBound(key);
      long lowerBound = countmin.getEstimateLowerBound(key);
      if (upperBound >= realCount && realCount >= lowerBound) {
        continue;
      } else {
        System.out.format(
            "upperbound: %d, realCount: %d, lowerbound: %d \n", upperBound, realCount, lowerBound);
        bad += 1;
      }
    }
    // System.out.format("bad is: %d and eps * n is: %f \n", bad, eps*n);
    Assert.assertTrue(bad <= eps * n);
  }
Пример #2
0
  // @Test
  public void realCountsInBoundsAfterUnionCU() {
    int n = 1000;
    int size = 400;
    double delta = .01;
    double eps = 1.0 / size;

    double prob1 = .01;
    double prob2 = .005;

    PositiveCountersMap realCounts = new PositiveCountersMap();
    CountMin countmin1 = new CountMin(eps, delta);
    CountMin countmin2 = new CountMin(eps, delta);
    for (int i = 0; i < n; i++) {
      long key1 = randomGeometricDist(prob1);
      long key2 = randomGeometricDist(prob2);

      countmin1.conservative_update(key1);
      countmin2.conservative_update(key2);

      // Updating the real counters
      realCounts.increment(key1);
      realCounts.increment(key2);
    }
    CountMin countmin = countmin1.merge(countmin2);

    int bad = 0;
    int i = 0;
    for (long key : realCounts.keys()) {
      i = i + 1;

      long realCount = realCounts.get(key);
      long upperBound = countmin.getEstimateUpperBound(key);
      long lowerBound = countmin.getEstimateLowerBound(key);

      if (upperBound < realCount || realCount < lowerBound) {
        bad = bad + 1;
        System.out.format(
            "upperbound: %d, realCount: %d, lowerbound: %d \n", upperBound, realCount, lowerBound);
      }
    }
    Assert.assertTrue(bad <= delta * i);
  }