Search in sources :

Example 1 with NumericHistogramValue

use of org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic.NumericHistogramValue in project geowave by locationtech.

the class NumericHistogramStatisticsTest method testRapidIncreaseInRange.

@Test
public void testRapidIncreaseInRange() {
    final NumericHistogramStatistic stat = new NumericHistogramStatistic("", "pop");
    final NumericHistogramValue statValue = stat.createEmpty();
    final Random rand = new Random(7777);
    double next = 1;
    for (int i = 0; i < 100; i++) {
        next = next + (rand.nextDouble() * 100.0);
        statValue.entryIngested(dataAdapter, create(next));
    }
    for (long i = 0; i < 100; i++) {
        final NumericHistogramValue statValue2 = stat.createEmpty();
        for (int j = 0; j < 100; j++) {
            statValue2.entryIngested(dataAdapter, create(4839000434.547854578 * rand.nextDouble() * rand.nextGaussian()));
        }
        byte[] b = statValue2.toBinary();
        statValue2.fromBinary(b);
        b = statValue.toBinary();
        statValue.fromBinary(b);
        statValue.merge(statValue2);
    }
}
Also used : NumericHistogramValue(org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic.NumericHistogramValue) Random(java.util.Random) NumericHistogramStatistic(org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic) Test(org.junit.Test)

Example 2 with NumericHistogramValue

use of org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic.NumericHistogramValue in project geowave by locationtech.

the class NumericHistogramStatisticsTest method testNegative.

@Test
public void testNegative() {
    final NumericHistogramStatistic stat = new NumericHistogramStatistic("", "pop");
    final NumericHistogramValue statValue = stat.createEmpty();
    final Random rand = new Random(7777);
    statValue.entryIngested(dataAdapter, create(-100.0));
    statValue.entryIngested(dataAdapter, create(-101.0));
    statValue.entryIngested(dataAdapter, create(-2.0));
    double next = -1;
    for (int i = 0; i < 10000; i++) {
        next = next - (Math.round(rand.nextDouble()));
        statValue.entryIngested(dataAdapter, create(next));
    }
    final NumericHistogramValue statValue2 = stat.createEmpty();
    final double start2 = next;
    double min = 0;
    for (long i = 0; i < 10000; i++) {
        final double val = next - (long) (1000 * rand.nextDouble());
        statValue2.entryIngested(dataAdapter, create(val));
        min = Math.min(val, min);
    }
    final double skewvalue = next - (1000 * rand.nextDouble());
    final SimpleFeature skewedFeature = create(skewvalue);
    for (int i = 0; i < 10000; i++) {
        statValue2.entryIngested(dataAdapter, skewedFeature);
    }
    assertEquals(1.0, statValue2.cdf(0), 0.00001);
    final byte[] b = statValue2.toBinary();
    statValue2.fromBinary(b);
    assertEquals(0.0, statValue2.cdf(min), 0.00001);
    statValue.merge(statValue2);
    assertEquals(1.0, statValue.cdf(0), 0.00001);
    assertEquals(0.66, statValue.cdf(start2), 0.01);
    assertEquals(30003, sum(statValue.count(10)));
    final double r = statValue.percentPopulationOverRange(skewvalue - 1, skewvalue + 1);
    assertTrue((r > 0.3) && (r < 0.35));
}
Also used : NumericHistogramValue(org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic.NumericHistogramValue) Random(java.util.Random) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NumericHistogramStatistic(org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic) Test(org.junit.Test)

Example 3 with NumericHistogramValue

use of org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic.NumericHistogramValue in project geowave by locationtech.

the class NumericHistogramStatisticsTest method testPositive.

@Test
public void testPositive() {
    final NumericHistogramStatistic stat = new NumericHistogramStatistic("", "pop");
    final NumericHistogramValue statValue = stat.createEmpty();
    final Random rand = new Random(7777);
    statValue.entryIngested(dataAdapter, create(100.0));
    statValue.entryIngested(dataAdapter, create(101.0));
    statValue.entryIngested(dataAdapter, create(2.0));
    double next = 1;
    for (int i = 0; i < 10000; i++) {
        next = next + (Math.round(rand.nextDouble()));
        statValue.entryIngested(dataAdapter, create(next));
    }
    final NumericHistogramValue statValue2 = stat.createEmpty();
    final double start2 = next;
    double max = 0;
    for (long i = 0; i < 10000; i++) {
        final double val = next + (1000 * rand.nextDouble());
        statValue2.entryIngested(dataAdapter, create(val));
        max = Math.max(val, max);
    }
    final double skewvalue = next + (1000 * rand.nextDouble());
    final SimpleFeature skewedFeature = create(skewvalue);
    for (int i = 0; i < 10000; i++) {
        statValue2.entryIngested(dataAdapter, skewedFeature);
    // skewedFeature.setAttribute("pop", Long.valueOf(next + (long)
    // (1000 * rand.nextDouble())));
    }
    final byte[] b = statValue2.toBinary();
    statValue2.fromBinary(b);
    assertEquals(1.0, statValue2.cdf(max + 1), 0.00001);
    statValue.merge(statValue2);
    assertEquals(1.0, statValue.cdf(max + 1), 0.00001);
    assertEquals(0.33, statValue.cdf(start2), 0.01);
    assertEquals(30003, sum(statValue.count(10)));
    final double r = statValue.percentPopulationOverRange(skewvalue - 1, skewvalue + 1);
    assertTrue((r > 0.3) && (r < 0.35));
}
Also used : NumericHistogramValue(org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic.NumericHistogramValue) Random(java.util.Random) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NumericHistogramStatistic(org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic) Test(org.junit.Test)

Example 4 with NumericHistogramValue

use of org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic.NumericHistogramValue in project geowave by locationtech.

the class NumericHistogramStatisticsTest method testMix.

@Test
public void testMix() {
    final NumericHistogramStatistic stat = new NumericHistogramStatistic("", "pop");
    final NumericHistogramValue statValue = stat.createEmpty();
    final Random rand = new Random(7777);
    double min = 0;
    double max = 0;
    double next = 0;
    for (int i = 1; i < 300; i++) {
        final NumericHistogramValue statValue2 = stat.createEmpty();
        final double m = 10000.0 * Math.pow(10.0, ((i / 100) + 1));
        if (i == 50) {
            next = 0.0;
        } else if (i == 100) {
            next = Double.NaN;
        } else if (i == 150) {
            next = Double.MAX_VALUE;
        } else if (i == 200) {
            next = Integer.MAX_VALUE;
        } else if (i == 225) {
            next = Integer.MIN_VALUE;
        } else {
            next = (m * rand.nextDouble() * MathUtils.sign(rand.nextGaussian()));
        }
        statValue2.entryIngested(dataAdapter, create(next));
        if (!Double.isNaN(next)) {
            max = Math.max(next, max);
            min = Math.min(next, min);
            stat.fromBinary(stat.toBinary());
            statValue2.fromBinary(statValue2.toBinary());
            statValue.merge(statValue2);
        }
    }
    assertEquals(0.5, statValue.cdf(0), 0.1);
    assertEquals(0.0, statValue.cdf(min), 0.00001);
    assertEquals(1.0, statValue.cdf(max), 0.00001);
    assertEquals(298, sum(statValue.count(10)));
}
Also used : NumericHistogramValue(org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic.NumericHistogramValue) Random(java.util.Random) NumericHistogramStatistic(org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic) Test(org.junit.Test)

Aggregations

Random (java.util.Random)4 Test (org.junit.Test)4 NumericHistogramStatistic (org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic)4 NumericHistogramValue (org.locationtech.geowave.core.store.statistics.field.NumericHistogramStatistic.NumericHistogramValue)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2