use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch in project sketches-pig by DataSketches.
the class UnionArrayOfDoublesSketchTest method algebraicIntemediateFinalExact.
@Test
public void algebraicIntemediateFinalExact() throws Exception {
EvalFunc<Tuple> func = new UnionArrayOfDoublesSketch.IntermediateFinal("1");
DataBag bag = BagFactory.getInstance().newDefaultBag();
// this is to simulate the output from Initial
{
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
sketch.update(1, new double[] { 1.0 });
sketch.update(2, new double[] { 1.0 });
DataBag innerBag = PigUtil.tuplesToBag(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
bag.add(PigUtil.objectsToTuple(innerBag));
}
// this is to simulate the output from a prior call of IntermediateFinal
{
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
sketch.update(1, new double[] { 1.0 });
sketch.update(2, new double[] { 1.0 });
bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
}
Tuple resultTuple = func.exec(PigUtil.objectsToTuple(bag));
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.heapifySketch(Memory.wrap(bytes.get()));
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);
for (double[] values : sketch.getValues()) {
Assert.assertEquals(values[0], 2.0, 0.0);
}
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToEstimateAndErrorBoundsTest method emptyInputSketch.
@Test
public void emptyInputSketch() throws Exception {
EvalFunc<Tuple> func = new ArrayOfDoublesSketchToEstimateAndErrorBounds();
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
Tuple resultTuple = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.compact().toByteArray())));
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 3);
Assert.assertEquals(resultTuple.get(0), 0.0);
Assert.assertEquals(resultTuple.get(1), 0.0);
Assert.assertEquals(resultTuple.get(2), 0.0);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToEstimatesTest method emptySketch.
@Test
public void emptySketch() throws Exception {
EvalFunc<Tuple> func = new ArrayOfDoublesSketchToEstimates();
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
Tuple inputTuple = PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray()));
Tuple resultTuple = func.exec(inputTuple);
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 2);
Assert.assertEquals(resultTuple.get(0), 0.0);
Assert.assertEquals(resultTuple.get(1), 0.0);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToMeansTest method oneEntryInputSketch.
@Test
public void oneEntryInputSketch() throws Exception {
EvalFunc<Tuple> func = new ArrayOfDoublesSketchToMeans();
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
sketch.update(1, new double[] { 1 });
Tuple inputTuple = PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray()));
Tuple resultTuple = func.exec(inputTuple);
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
Assert.assertEquals(resultTuple.get(0), 1.0);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToMeansTest method manyEntriesTwoValuesInputSketch.
@Test
public void manyEntriesTwoValuesInputSketch() throws Exception {
EvalFunc<Tuple> func = new ArrayOfDoublesSketchToMeans();
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setNumberOfValues(2).build();
Random rand = new Random(0);
// to saturate the sketch with default number of nominal entries (4K)
int numKeys = 10000;
for (int i = 0; i < numKeys; i++) {
// two random values normally distributed with means of 0 and 1
sketch.update(i, new double[] { rand.nextGaussian(), rand.nextGaussian() + 1.0 });
}
Assert.assertTrue(sketch.getRetainedEntries() >= 4096);
Tuple inputTuple = PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray()));
Tuple resultTuple = func.exec(inputTuple);
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 2);
Assert.assertEquals((double) resultTuple.get(0), 0.0, 0.04);
Assert.assertEquals((double) resultTuple.get(1), 1.0, 0.04);
}
Aggregations