use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class AexcludeBTest method checkNullCombinations.
@Test
public void checkNullCombinations() throws IOException {
EvalFunc<Tuple> aNbFunc = new AexcludeB();
EvalFunc<Double> estFunc = new Estimate();
Tuple inputTuple, resultTuple;
Double est;
// Two nulls
inputTuple = TupleFactory.getInstance().newTuple(2);
resultTuple = aNbFunc.exec(inputTuple);
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
est = estFunc.exec(resultTuple);
assertEquals(est, 0.0, 0.0);
// A is null
inputTuple = TupleFactory.getInstance().newTuple(2);
inputTuple.set(1, createDbaFromQssRange(256, 0, 128));
resultTuple = aNbFunc.exec(inputTuple);
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
est = estFunc.exec(resultTuple);
assertEquals(est, 0.0, 0.0);
// A is valid, B is null
inputTuple = TupleFactory.getInstance().newTuple(2);
inputTuple.set(0, createDbaFromQssRange(256, 0, 256));
resultTuple = aNbFunc.exec(inputTuple);
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
est = estFunc.exec(resultTuple);
assertEquals(est, 256.0, 0.0);
// Both valid
inputTuple = TupleFactory.getInstance().newTuple(2);
inputTuple.set(0, createDbaFromQssRange(256, 0, 256));
inputTuple.set(1, createDbaFromQssRange(256, 0, 128));
resultTuple = aNbFunc.exec(inputTuple);
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
est = estFunc.exec(resultTuple);
assertEquals(est, 128.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class DataToSketchTest method checkAlgFinalOuterBagEmptyTuples.
@Test
public void checkAlgFinalOuterBagEmptyTuples() throws IOException {
EvalFunc<Tuple> interFuncFinal = new DataToSketch.IntermediateFinal("256");
EvalFunc<Double> estFunc = new Estimate();
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
Tuple resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
DataBag bag = BagFactory.getInstance().newDefaultBag();
// inputTuple.bag0:null
inputTuple.set(0, bag);
resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
bag.add(innerTuple);
resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class DataToSketchTest method checkAlgFinalInnerNotDBA.
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkAlgFinalInnerNotDBA() throws IOException {
EvalFunc<Tuple> interFuncFinal = new DataToSketch.IntermediateFinal("256");
EvalFunc<Double> estFunc = new Estimate();
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
Tuple resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
DataBag bag = BagFactory.getInstance().newDefaultBag();
// inputTuple.bag0:null
inputTuple.set(0, bag);
resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
bag.add(innerTuple);
// not a DBA
innerTuple.set(0, new Double(1.0));
resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class EstimateTest method testExactWithSeed.
@Test
public void testExactWithSeed() throws IOException {
EvalFunc<Double> func = new Estimate(Long.toString(DEFAULT_UPDATE_SEED));
Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
dataTuple.set(0, createDbaFromQssRange(64, 0, 64));
Double result = func.exec(dataTuple);
assertNotNull(result);
assertEquals(result, 64.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class IntersectTest method checkExactTopExec.
@Test
public void checkExactTopExec() throws IOException {
EvalFunc<Tuple> interFunc = new Intersect();
EvalFunc<Double> estFunc = new Estimate();
// create inputTuple and a bag, add bag to inputTuple
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
DataBag bag = BagFactory.getInstance().newDefaultBag();
inputTuple.set(0, bag);
// create 4 overlapping sketches of 64 in a bag
for (int i = 0; i < 4; i++) {
Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
dataTuple.set(0, createDbaFromQssRange(256, i * 64, 256));
bag.add(dataTuple);
}
Tuple resultTuple = interFunc.exec(inputTuple);
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
Double est = estFunc.exec(resultTuple);
assertEquals(est, 64.0, 0.0);
}
Aggregations