Search in sources :

Example 1 with UniformIntegerDistribution

use of org.apache.commons.math3.distribution.UniformIntegerDistribution in project RoaringBitmap by RoaringBitmap.

the class BenchmarkDataGenerator method generate.

static BenchmarkData generate(int param, int howMany, int smallType, int bigType) {
    IntegerDistribution ud = new UniformIntegerDistribution(new Well19937c(param + 17), Short.MIN_VALUE, Short.MAX_VALUE);
    ClusteredDataGenerator cd = new ClusteredDataGenerator();
    IntegerDistribution p = new UniformIntegerDistribution(new Well19937c(param + 123), SMALLEST_ARRAY, BIGGEST_ARRAY / param);
    BenchmarkContainer[] smalls = new BenchmarkContainer[howMany];
    BenchmarkContainer[] bigs = new BenchmarkContainer[howMany];
    for (int i = 0; i < howMany; i++) {
        int smallSize = p.sample();
        int bigSize = smallSize * param;
        short[] small = smallType == 0 ? generateUniform(ud, smallSize) : generateClustered(cd, smallSize);
        short[] big = bigType == 0 ? generateUniform(ud, bigSize) : generateClustered(cd, bigSize);
        smalls[i] = new BenchmarkContainer(small);
        bigs[i] = new BenchmarkContainer(big);
    }
    return new BenchmarkData(smalls, bigs);
}
Also used : IntegerDistribution(org.apache.commons.math3.distribution.IntegerDistribution) UniformIntegerDistribution(org.apache.commons.math3.distribution.UniformIntegerDistribution) Well19937c(org.apache.commons.math3.random.Well19937c) UniformIntegerDistribution(org.apache.commons.math3.distribution.UniformIntegerDistribution) ClusteredDataGenerator(me.lemire.integercompression.synth.ClusteredDataGenerator)

Example 2 with UniformIntegerDistribution

use of org.apache.commons.math3.distribution.UniformIntegerDistribution in project RoaringBitmap by RoaringBitmap.

the class BenchmarkDataGenerator method generate.

static BenchmarkData generate(int param, int howMany, int smallType, int bigType) {
    IntegerDistribution ud = new UniformIntegerDistribution(new Well19937c(param + 17), Short.MIN_VALUE, Short.MAX_VALUE);
    ClusteredDataGenerator cd = new ClusteredDataGenerator();
    IntegerDistribution p = new UniformIntegerDistribution(new Well19937c(param + 123), SMALLEST_ARRAY, BIGGEST_ARRAY / param);
    BenchmarkContainer[] smalls = new BenchmarkContainer[howMany];
    BenchmarkContainer[] bigs = new BenchmarkContainer[howMany];
    for (int i = 0; i < howMany; i++) {
        int smallSize = p.sample();
        int bigSize = smallSize * param;
        short[] small = smallType == 0 ? generateUniform(ud, smallSize) : generateClustered(cd, smallSize);
        short[] big = bigType == 0 ? generateUniform(ud, bigSize) : generateClustered(cd, bigSize);
        smalls[i] = new BenchmarkContainer(small);
        bigs[i] = new BenchmarkContainer(big);
    }
    return new BenchmarkData(smalls, bigs);
}
Also used : IntegerDistribution(org.apache.commons.math3.distribution.IntegerDistribution) UniformIntegerDistribution(org.apache.commons.math3.distribution.UniformIntegerDistribution) Well19937c(org.apache.commons.math3.random.Well19937c) UniformIntegerDistribution(org.apache.commons.math3.distribution.UniformIntegerDistribution) ClusteredDataGenerator(me.lemire.integercompression.synth.ClusteredDataGenerator)

Example 3 with UniformIntegerDistribution

use of org.apache.commons.math3.distribution.UniformIntegerDistribution in project druid by druid-io.

the class ColumnValueGenerator method initDistribution.

private void initDistribution() {
    GeneratorColumnSchema.ValueDistribution distributionType = schema.getDistributionType();
    ValueType type = schema.getType();
    List<Object> enumeratedValues = schema.getEnumeratedValues();
    List<Double> enumeratedProbabilities = schema.getEnumeratedProbabilities();
    List<Pair<Object, Double>> probabilities = new ArrayList<>();
    switch(distributionType) {
        case SEQUENTIAL:
            // not random, just cycle through numbers from start to end, or cycle through enumerated values if provided
            distribution = new SequentialDistribution(schema.getStartInt(), schema.getEndInt(), schema.getEnumeratedValues());
            break;
        case UNIFORM:
            distribution = new UniformRealDistribution(schema.getStartDouble(), schema.getEndDouble());
            break;
        case DISCRETE_UNIFORM:
            if (enumeratedValues == null) {
                enumeratedValues = new ArrayList<>();
                for (int i = schema.getStartInt(); i < schema.getEndInt(); i++) {
                    Object val = convertType(i, type);
                    enumeratedValues.add(val);
                }
            }
            // give them all equal probability, the library will normalize probabilities to sum to 1.0
            for (Object enumeratedValue : enumeratedValues) {
                probabilities.add(new Pair<>(enumeratedValue, 0.1));
            }
            distribution = new EnumeratedTreeDistribution<>(probabilities);
            break;
        case NORMAL:
            distribution = new NormalDistribution(schema.getMean(), schema.getStandardDeviation());
            break;
        case ROUNDED_NORMAL:
            NormalDistribution normalDist = new NormalDistribution(schema.getMean(), schema.getStandardDeviation());
            distribution = new RealRoundingDistribution(normalDist);
            break;
        case ZIPF:
            int cardinality;
            if (enumeratedValues == null) {
                Integer startInt = schema.getStartInt();
                cardinality = schema.getEndInt() - startInt;
                ZipfDistribution zipf = new ZipfDistribution(cardinality, schema.getZipfExponent());
                for (int i = 0; i < cardinality; i++) {
                    probabilities.add(new Pair<>((Object) (i + startInt), zipf.probability(i)));
                }
            } else {
                cardinality = enumeratedValues.size();
                ZipfDistribution zipf = new ZipfDistribution(enumeratedValues.size(), schema.getZipfExponent());
                for (int i = 0; i < cardinality; i++) {
                    probabilities.add(new Pair<>(enumeratedValues.get(i), zipf.probability(i)));
                }
            }
            distribution = new EnumeratedTreeDistribution<>(probabilities);
            break;
        case LAZY_ZIPF:
            int lazyCardinality;
            Integer startInt = schema.getStartInt();
            lazyCardinality = schema.getEndInt() - startInt;
            distribution = new ZipfDistribution(lazyCardinality, schema.getZipfExponent());
            break;
        case LAZY_DISCRETE_UNIFORM:
            distribution = new UniformIntegerDistribution(schema.getStartInt(), schema.getEndInt());
            break;
        case ENUMERATED:
            for (int i = 0; i < enumeratedValues.size(); i++) {
                probabilities.add(new Pair<>(enumeratedValues.get(i), enumeratedProbabilities.get(i)));
            }
            distribution = new EnumeratedTreeDistribution<>(probabilities);
            break;
        default:
            throw new UnsupportedOperationException("Unknown distribution type: " + distributionType);
    }
    if (distribution instanceof AbstractIntegerDistribution) {
        ((AbstractIntegerDistribution) distribution).reseedRandomGenerator(seed);
    } else if (distribution instanceof AbstractRealDistribution) {
        ((AbstractRealDistribution) distribution).reseedRandomGenerator(seed);
    } else {
        ((EnumeratedDistribution) distribution).reseedRandomGenerator(seed);
    }
}
Also used : ValueType(org.apache.druid.segment.column.ValueType) ArrayList(java.util.ArrayList) UniformRealDistribution(org.apache.commons.math3.distribution.UniformRealDistribution) AbstractIntegerDistribution(org.apache.commons.math3.distribution.AbstractIntegerDistribution) AbstractRealDistribution(org.apache.commons.math3.distribution.AbstractRealDistribution) NormalDistribution(org.apache.commons.math3.distribution.NormalDistribution) ZipfDistribution(org.apache.commons.math3.distribution.ZipfDistribution) UniformIntegerDistribution(org.apache.commons.math3.distribution.UniformIntegerDistribution) Pair(org.apache.commons.math3.util.Pair)

Aggregations

UniformIntegerDistribution (org.apache.commons.math3.distribution.UniformIntegerDistribution)3 ClusteredDataGenerator (me.lemire.integercompression.synth.ClusteredDataGenerator)2 IntegerDistribution (org.apache.commons.math3.distribution.IntegerDistribution)2 Well19937c (org.apache.commons.math3.random.Well19937c)2 ArrayList (java.util.ArrayList)1 AbstractIntegerDistribution (org.apache.commons.math3.distribution.AbstractIntegerDistribution)1 AbstractRealDistribution (org.apache.commons.math3.distribution.AbstractRealDistribution)1 NormalDistribution (org.apache.commons.math3.distribution.NormalDistribution)1 UniformRealDistribution (org.apache.commons.math3.distribution.UniformRealDistribution)1 ZipfDistribution (org.apache.commons.math3.distribution.ZipfDistribution)1 Pair (org.apache.commons.math3.util.Pair)1 ValueType (org.apache.druid.segment.column.ValueType)1