use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class QuantileSketchTest method testResetting.
@Test
public void testResetting() {
QuantileSketch sketch = new QuantileSketch(64, Distribution.Type.CDF, makePoints(0.0, 9.0, 1.0));
IntStream.range(0, 30).forEach(i -> sketch.update(i % 10));
QuantileSketch anotherSketch = new QuantileSketch(64, Distribution.Type.CDF, makePoints(0.0, 9.0, 1.0));
IntStream.range(0, 30).forEach(i -> sketch.update(i % 3));
sketch.union(anotherSketch.serialize());
Clip result = sketch.getResult(null, null);
List<BulletRecord> records = result.getRecords();
for (BulletRecord record : records) {
String range = (String) record.get(RANGE_FIELD);
double count = (Double) record.get(COUNT_FIELD);
String rangeEnd = getEnd(range);
if (rangeEnd.equals(POSITIVE_INFINITY)) {
Assert.assertEquals(count, 60.0);
} else {
double end = Double.valueOf(rangeEnd);
if (end <= 3.0) {
Assert.assertEquals(count, end * 13.0);
} else {
Assert.assertEquals(count, 39.0 + (end - 3) * 3.0);
}
}
}
sketch.reset();
sketch.update(1.0);
result = sketch.getResult(null, null);
records = result.getRecords();
for (BulletRecord record : records) {
String range = (String) record.get(RANGE_FIELD);
double count = (Double) record.get(COUNT_FIELD);
String rangeEnd = getEnd(range);
if (rangeEnd.equals(POSITIVE_INFINITY)) {
Assert.assertEquals(count, 1.0);
} else {
double end = Double.valueOf(rangeEnd);
if (end <= 1.0) {
Assert.assertEquals(count, 0.0);
} else {
Assert.assertEquals(count, 1.0);
}
}
}
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class QuantileSketchTest method testExactQuantilesWithProvidedPoints.
@Test
public void testExactQuantilesWithProvidedPoints() {
// Same results as the testExactQuantilesWithNumberOfPoints
QuantileSketch sketch = new QuantileSketch(64, Distribution.Type.QUANTILE, makePoints(0.0, 1.0, 0.1));
IntStream.range(0, 11).forEach(i -> sketch.update(i * 10.0));
List<BulletRecord> records = sketch.getResult(null, null).getRecords();
for (BulletRecord record : records) {
Double quantile = (Double) record.get(QUANTILE_FIELD);
Double value = (Double) record.get(VALUE_FIELD);
double percent = quantile * 100;
assertApproxEquals(percent, value);
}
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class ThetaSketchTest method testResetting.
@Test
public void testResetting() {
ThetaSketch sketch = new ThetaSketch(ResizeFactor.X4, Family.ALPHA, 1.0f, 512);
sketch.update("foo");
sketch.update("bar");
sketch.update("baz");
List<BulletRecord> actuals = sketch.getResult(null, null).getRecords();
Assert.assertEquals(actuals.size(), 1);
BulletRecord expected = RecordBox.get().add(ThetaSketch.COUNT_FIELD, 3.0).getRecord();
BulletRecord actual = actuals.get(0);
Assert.assertEquals(actual, expected);
sketch.reset();
actuals = sketch.getResult(null, null).getRecords();
Assert.assertEquals(actuals.size(), 1);
expected = RecordBox.get().add(ThetaSketch.COUNT_FIELD, 0.0).getRecord();
actual = actuals.get(0);
Assert.assertEquals(actual, expected);
ThetaSketch anotherSketch = new ThetaSketch(ResizeFactor.X4, Family.ALPHA, 1.0f, 512);
IntStream.range(0, 41).forEach(i -> anotherSketch.update(String.valueOf(i)));
sketch.union(anotherSketch.serialize());
sketch.update("foo");
actuals = sketch.getResult(null, null).getRecords();
Assert.assertEquals(actuals.size(), 1);
expected = RecordBox.get().add(ThetaSketch.COUNT_FIELD, 42.0).getRecord();
actual = actuals.get(0);
Assert.assertEquals(actual, expected);
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class ThetaSketchTest method testUpdatingForExactResult.
@Test
public void testUpdatingForExactResult() {
ThetaSketch sketch = new ThetaSketch(ResizeFactor.X4, Family.ALPHA, 1.0f, 512);
sketch.update("foo");
sketch.update("bar");
sketch.update("baz");
List<BulletRecord> actuals = sketch.getResult(null, null).getRecords();
Assert.assertEquals(actuals.size(), 1);
BulletRecord expected = RecordBox.get().add(ThetaSketch.COUNT_FIELD, 3.0).getRecord();
BulletRecord actual = actuals.get(0);
Assert.assertEquals(actual, expected);
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class TupleSketchTest method testResetting.
@Test
public void testResetting() {
data = new CachingGroupData(null, new HashMap<>());
TupleSketch sketch = new TupleSketch(ResizeFactor.X4, 1.0f, 32, 16);
sketch.update(addToData("foo", 0.0, data), data);
sketch.update(addToData("bar", 0.2, data), data);
TupleSketch anotherSketch = new TupleSketch(ResizeFactor.X4, 1.0f, 32, 16);
sketch.update(addToData("bar", 0.2, data), data);
sketch.update(addToData("baz", 0.2, data), data);
sketch.update(addToData("qux", 0.2, data), data);
sketch.union(anotherSketch.serialize());
List<BulletRecord> actuals = sketch.getResult(null, null).getRecords();
Assert.assertEquals(actuals.size(), 4);
BulletRecord expectedA = RecordBox.get().add("A", "foo").add("B", "0.0").getRecord();
BulletRecord expectedB = RecordBox.get().add("A", "bar").add("B", "0.2").getRecord();
BulletRecord expectedC = RecordBox.get().add("A", "baz").add("B", "0.2").getRecord();
BulletRecord expectedD = RecordBox.get().add("A", "qux").add("B", "0.2").getRecord();
TestHelpers.assertContains(actuals, expectedA);
TestHelpers.assertContains(actuals, expectedB);
TestHelpers.assertContains(actuals, expectedC);
TestHelpers.assertContains(actuals, expectedD);
sketch.reset();
sketch.update(addToData("foo", 0.0, data), data);
sketch.update(addToData("bar", 0.2, data), data);
actuals = sketch.getResult(null, null).getRecords();
Assert.assertEquals(actuals.size(), 2);
expectedA = RecordBox.get().add("A", "foo").add("B", "0.0").getRecord();
expectedB = RecordBox.get().add("A", "bar").add("B", "0.2").getRecord();
TestHelpers.assertContains(actuals, expectedA);
TestHelpers.assertContains(actuals, expectedB);
}
Aggregations