use of com.yahoo.sketches.tuple.ArrayOfDoublesSketchIterator in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchStats method sketchToSummaryStatistics.
/**
* Convert sketch to summary statistics.
*
* @param sketch ArrayOfDoublesSketch to convert to summary statistics.
* @return An array of SummaryStatistics.
*/
static SummaryStatistics[] sketchToSummaryStatistics(final ArrayOfDoublesSketch sketch) {
final SummaryStatistics[] summaryStatistics = new SummaryStatistics[sketch.getNumValues()];
for (int i = 0; i < sketch.getNumValues(); i++) {
summaryStatistics[i] = new SummaryStatistics();
}
final ArrayOfDoublesSketchIterator it = sketch.iterator();
while (it.next()) {
final double[] values = it.getValues();
for (int i = 0; i < it.getValues().length; i++) {
summaryStatistics[i].addValue(values[i]);
}
}
return summaryStatistics;
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesSketchIterator in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToEstimates method exec.
@Override
public Tuple exec(final Tuple input) throws IOException {
if ((input == null) || (input.size() == 0)) {
return null;
}
final DataByteArray dba = (DataByteArray) input.get(0);
final ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.wrapSketch(Memory.wrap(dba.get()));
final double[] estimates = new double[sketch.getNumValues() + 1];
estimates[0] = sketch.getEstimate();
if (sketch.getRetainedEntries() > 0) {
// remove unnecessary check when version of sketches-core > 0.4.0
final ArrayOfDoublesSketchIterator it = sketch.iterator();
while (it.next()) {
final double[] values = it.getValues();
for (int i = 0; i < sketch.getNumValues(); i++) {
estimates[i + 1] += values[i];
}
}
for (int i = 0; i < sketch.getNumValues(); i++) {
estimates[i + 1] /= sketch.getTheta();
}
}
return Util.doubleArrayToTuple(estimates);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesSketchIterator in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToQuantilesSketch method exec.
@Override
public DataByteArray exec(final Tuple input) throws IOException {
if ((input == null) || (input.size() == 0)) {
return null;
}
final DataByteArray dba = (DataByteArray) input.get(0);
final ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.wrapSketch(Memory.wrap(dba.get()));
int column = 1;
if (input.size() > 1) {
column = (int) input.get(1);
if ((column < 1) || (column > sketch.getNumValues())) {
throw new IllegalArgumentException("Column number out of range. The given sketch has " + sketch.getNumValues() + " columns");
}
}
final DoublesSketchBuilder builder = DoublesSketch.builder();
if (k > 0) {
builder.setK(k);
}
final UpdateDoublesSketch qs = builder.build();
final ArrayOfDoublesSketchIterator it = sketch.iterator();
while (it.next()) {
qs.update(it.getValues()[column - 1]);
}
return new DataByteArray(qs.compact().toByteArray());
}
Aggregations