Search in sources :

Example 1 with ArrayOfDoublesSketchIterator

use of org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator in project druid by druid-io.

the class ArrayOfDoublesSketchToVariancesPostAggregator method compute.

@Override
public double[] compute(final Map<String, Object> combinedAggregators) {
    final ArrayOfDoublesSketch sketch = (ArrayOfDoublesSketch) getField().compute(combinedAggregators);
    final SummaryStatistics[] stats = new SummaryStatistics[sketch.getNumValues()];
    Arrays.setAll(stats, i -> new SummaryStatistics());
    final ArrayOfDoublesSketchIterator it = sketch.iterator();
    while (it.next()) {
        final double[] values = it.getValues();
        for (int i = 0; i < values.length; i++) {
            stats[i].addValue(values[i]);
        }
    }
    final double[] variances = new double[sketch.getNumValues()];
    Arrays.setAll(variances, i -> stats[i].getVariance());
    return variances;
}
Also used : ArrayOfDoublesSketchIterator(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) ArrayOfDoublesSketch(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch)

Example 2 with ArrayOfDoublesSketchIterator

use of org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator in project druid by druid-io.

the class ArrayOfDoublesSketchTTestPostAggregator method getStats.

private static SummaryStatistics[] getStats(final ArrayOfDoublesSketch sketch) {
    final SummaryStatistics[] stats = new SummaryStatistics[sketch.getNumValues()];
    Arrays.setAll(stats, i -> new SummaryStatistics());
    final ArrayOfDoublesSketchIterator it = sketch.iterator();
    while (it.next()) {
        final double[] values = it.getValues();
        for (int i = 0; i < values.length; i++) {
            stats[i].addValue(values[i]);
        }
    }
    return stats;
}
Also used : ArrayOfDoublesSketchIterator(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics)

Example 3 with ArrayOfDoublesSketchIterator

use of org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator in project druid by druid-io.

the class ArrayOfDoublesSketchToMeansPostAggregator method compute.

@Override
public double[] compute(final Map<String, Object> combinedAggregators) {
    final ArrayOfDoublesSketch sketch = (ArrayOfDoublesSketch) getField().compute(combinedAggregators);
    final SummaryStatistics[] stats = new SummaryStatistics[sketch.getNumValues()];
    Arrays.setAll(stats, i -> new SummaryStatistics());
    final ArrayOfDoublesSketchIterator it = sketch.iterator();
    while (it.next()) {
        final double[] values = it.getValues();
        for (int i = 0; i < values.length; i++) {
            stats[i].addValue(values[i]);
        }
    }
    final double[] means = new double[sketch.getNumValues()];
    Arrays.setAll(means, i -> stats[i].getMean());
    return means;
}
Also used : ArrayOfDoublesSketchIterator(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) ArrayOfDoublesSketch(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch)

Example 4 with ArrayOfDoublesSketchIterator

use of org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator in project druid by druid-io.

the class ArrayOfDoublesSketchToQuantilesSketchPostAggregator method compute.

@Override
public DoublesSketch compute(final Map<String, Object> combinedAggregators) {
    final ArrayOfDoublesSketch sketch = (ArrayOfDoublesSketch) getField().compute(combinedAggregators);
    final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build();
    final ArrayOfDoublesSketchIterator it = sketch.iterator();
    while (it.next()) {
        // convert 1-based column number to zero-based index
        qs.update(it.getValues()[column - 1]);
    }
    return qs;
}
Also used : ArrayOfDoublesSketchIterator(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator) UpdateDoublesSketch(org.apache.datasketches.quantiles.UpdateDoublesSketch) ArrayOfDoublesSketch(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch)

Aggregations

ArrayOfDoublesSketchIterator (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator)4 SummaryStatistics (org.apache.commons.math3.stat.descriptive.SummaryStatistics)3 ArrayOfDoublesSketch (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch)3 UpdateDoublesSketch (org.apache.datasketches.quantiles.UpdateDoublesSketch)1