use of com.yahoo.sketches.quantiles.UpdateDoublesSketch in project sketches-pig by DataSketches.
the class DataToDoublesSketchTest method algebraicIntermediateFinalNormalCase.
@Test
public void algebraicIntermediateFinalNormalCase() throws Exception {
EvalFunc<Tuple> func = new DataToDoublesSketch.IntermediateFinal();
DataBag bag = bagFactory.newDefaultBag();
{
// this is to simulate an output from Initial
DataBag innerBag = bagFactory.newDefaultBag();
innerBag.add(tupleFactory.newTuple(1.0));
bag.add(tupleFactory.newTuple(innerBag));
}
{
// this is to simulate an output from a prior call of IntermediateFinal
UpdateDoublesSketch qs = DoublesSketch.builder().build();
qs.update(2.0);
bag.add(tupleFactory.newTuple(new DataByteArray(qs.toByteArray())));
}
Tuple resultTuple = func.exec(tupleFactory.newTuple(bag));
DoublesSketch sketch = getSketch(resultTuple);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getN(), 2);
}
use of com.yahoo.sketches.quantiles.UpdateDoublesSketch in project sketches-pig by DataSketches.
the class GetQuantilesFromDoublesSketchTest method numberOfEvenlySpacedIntervals.
@Test
public void numberOfEvenlySpacedIntervals() throws Exception {
EvalFunc<Tuple> func = new GetQuantilesFromDoublesSketch();
UpdateDoublesSketch sketch = DoublesSketch.builder().build();
for (int i = 1; i <= 10; i++) sketch.update(i);
Tuple resultTuple = func.exec(tupleFactory.newTuple(Arrays.asList(new DataByteArray(sketch.toByteArray()), 3)));
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 3);
Assert.assertEquals(((double) resultTuple.get(0)), 1.0);
Assert.assertEquals(((double) resultTuple.get(1)), 6.0);
Assert.assertEquals(((double) resultTuple.get(2)), 10.0);
}
use of com.yahoo.sketches.quantiles.UpdateDoublesSketch in project sketches-pig by DataSketches.
the class UnionDoublesSketchTest method algebraicIntermediateFinalNormalCase.
@Test
public void algebraicIntermediateFinalNormalCase() throws Exception {
EvalFunc<Tuple> func = new UnionDoublesSketch.IntermediateFinal();
DataBag bag = bagFactory.newDefaultBag();
{
// this is to simulate an output from Initial
DataBag innerBag = bagFactory.newDefaultBag();
UpdateDoublesSketch qs = DoublesSketch.builder().build();
qs.update(1.0);
innerBag.add(tupleFactory.newTuple(new DataByteArray(qs.toByteArray())));
bag.add(tupleFactory.newTuple(innerBag));
}
{
// this is to simulate an output from a prior call of IntermediateFinal
UpdateDoublesSketch qs = DoublesSketch.builder().build();
qs.update(2.0);
bag.add(tupleFactory.newTuple(new DataByteArray(qs.toByteArray())));
}
Tuple resultTuple = func.exec(tupleFactory.newTuple(bag));
DoublesSketch sketch = getSketch(resultTuple);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getN(), 2);
}
use of com.yahoo.sketches.quantiles.UpdateDoublesSketch in project Gaffer by gchq.
the class DoublesSketchAggregatorTest method testAggregate.
@Test
public void testAggregate() {
final DoublesSketchAggregator sketchAggregator = new DoublesSketchAggregator();
UpdateDoublesSketch sketch1 = DoublesSketch.builder().build();
sketch1.update(1.0D);
sketch1.update(2.0D);
sketch1.update(3.0D);
DoublesSketch currentState = sketch1;
assertEquals(3L, currentState.getN());
assertEquals(2.0D, currentState.getQuantile(0.5D), DELTA);
UpdateDoublesSketch sketch2 = DoublesSketch.builder().build();
sketch2.update(4.0D);
sketch2.update(5.0D);
sketch2.update(6.0D);
sketch2.update(7.0D);
currentState = sketchAggregator.apply(currentState, sketch2);
assertEquals(7L, currentState.getN());
assertEquals(4.0D, currentState.getQuantile(0.5D), DELTA);
}
Aggregations