Search in sources :

Example 6 with TDigest

use of com.facebook.presto.tdigest.TDigest in project presto by prestodb.

the class TestTDigestFunctions method testAddElementsInOrder.

@Test
public void testAddElementsInOrder() {
    TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < NUMBER_OF_ENTRIES; i++) {
        tDigest.add(i);
        list.add(i);
    }
    for (int i = 0; i < quantiles.length; i++) {
        assertDiscreteQuantileWithinBound(quantiles[i], STANDARD_ERROR, list, tDigest);
    }
}
Also used : TDigest(com.facebook.presto.tdigest.TDigest) TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 7 with TDigest

use of com.facebook.presto.tdigest.TDigest in project presto by prestodb.

the class TestTDigestFunctions method testPoissonDistribution.

@Test(enabled = false)
public void testPoissonDistribution() {
    int trials = 10;
    for (int k = 1; k < trials; k++) {
        TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
        PoissonDistribution poisson = new PoissonDistribution(k * 0.1);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < NUMBER_OF_ENTRIES; i++) {
            int sample = poisson.sample();
            tDigest.add(sample);
            list.add(sample);
        }
        Collections.sort(list);
        for (int i = 0; i < quantiles.length; i++) {
            assertDiscreteQuantileWithinBound(quantiles[i], STANDARD_ERROR, list, tDigest);
        }
    }
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) TDigest(com.facebook.presto.tdigest.TDigest) TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 8 with TDigest

use of com.facebook.presto.tdigest.TDigest in project presto by prestodb.

the class TestTDigestFunctions method testGeometricDistribution.

@Test(enabled = false)
public void testGeometricDistribution() {
    int trials = 10;
    for (int k = 1; k < trials; k++) {
        TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
        GeometricDistribution geometric = new GeometricDistribution(k * 0.1);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < NUMBER_OF_ENTRIES; i++) {
            int sample = geometric.sample();
            tDigest.add(sample);
            list.add(sample);
        }
        Collections.sort(list);
        for (int i = 0; i < quantiles.length; i++) {
            assertDiscreteQuantileWithinBound(quantiles[i], STANDARD_ERROR, list, tDigest);
        }
    }
}
Also used : TDigest(com.facebook.presto.tdigest.TDigest) TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) ArrayList(java.util.ArrayList) GeometricDistribution(org.apache.commons.math3.distribution.GeometricDistribution) Test(org.testng.annotations.Test)

Example 9 with TDigest

use of com.facebook.presto.tdigest.TDigest in project presto by prestodb.

the class TestTDigestFunctions method testMergeTwoNormalDistributionsGetQuantile.

@Test
public void testMergeTwoNormalDistributionsGetQuantile() {
    TDigest tDigest1 = createTDigest(STANDARD_COMPRESSION_FACTOR);
    TDigest tDigest2 = createTDigest(STANDARD_COMPRESSION_FACTOR);
    List<Double> list = new ArrayList<>();
    NormalDistribution normal = new NormalDistribution(0, 50);
    for (int i = 0; i < NUMBER_OF_ENTRIES / 2; i++) {
        double value1 = normal.sample();
        double value2 = normal.sample();
        tDigest1.add(value1);
        tDigest2.add(value2);
        list.add(value1);
        list.add(value2);
    }
    tDigest1.merge(tDigest2);
    sort(list);
    for (int i = 0; i < quantiles.length; i++) {
        assertValueWithinBound(quantiles[i], STANDARD_ERROR, list, tDigest1);
    }
}
Also used : TDigest(com.facebook.presto.tdigest.TDigest) TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) NormalDistribution(org.apache.commons.math3.distribution.NormalDistribution) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 10 with TDigest

use of com.facebook.presto.tdigest.TDigest in project presto by prestodb.

the class TestTDigestFunctions method testMergeManyLargeNormalDistributions.

@Test
public void testMergeManyLargeNormalDistributions() {
    TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
    List<Double> list = new ArrayList<>();
    NormalDistribution normal = new NormalDistribution(500, 20);
    int digests = 1000;
    for (int k = 0; k < digests; k++) {
        TDigest current = createTDigest(STANDARD_COMPRESSION_FACTOR);
        for (int i = 0; i < NUMBER_OF_ENTRIES / digests; i++) {
            double value = normal.sample();
            current.add(value);
            list.add(value);
        }
        tDigest.merge(current);
    }
    sort(list);
    for (int i = 0; i < quantiles.length; i++) {
        assertContinuousQuantileWithinBound(quantiles[i], STANDARD_ERROR, list, tDigest);
    }
}
Also used : TDigest(com.facebook.presto.tdigest.TDigest) TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) NormalDistribution(org.apache.commons.math3.distribution.NormalDistribution) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Aggregations

TDigest (com.facebook.presto.tdigest.TDigest)27 TDigest.createTDigest (com.facebook.presto.tdigest.TDigest.createTDigest)27 Test (org.testng.annotations.Test)21 ArrayList (java.util.ArrayList)18 NormalDistribution (org.apache.commons.math3.distribution.NormalDistribution)8 SqlVarbinary (com.facebook.presto.common.type.SqlVarbinary)6 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)4 Description (com.facebook.presto.spi.function.Description)4 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)4 SqlType (com.facebook.presto.spi.function.SqlType)4 Block (com.facebook.presto.common.block.Block)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 DoubleType (com.facebook.presto.common.type.DoubleType)1 Type (com.facebook.presto.common.type.Type)1 Centroid (com.facebook.presto.tdigest.Centroid)1 BinomialDistribution (org.apache.commons.math3.distribution.BinomialDistribution)1 GeometricDistribution (org.apache.commons.math3.distribution.GeometricDistribution)1 PoissonDistribution (org.apache.commons.math3.distribution.PoissonDistribution)1