Skip to content

Commit

Permalink
only reduce centroids
Browse files Browse the repository at this point in the history
also fix the compression setting in tests

tests pass 500 iters
  • Loading branch information
andyb-elastic committed Sep 27, 2018
1 parent d2b0787 commit bd2420b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Expand Up @@ -146,15 +146,13 @@ public void doClose() {
public static double computeMAD(TDigestState valuesSketch) {

final double approximateMedian = valuesSketch.quantile(0.5);
final TDigestState approximateDeviationsSketch = new TDigestState(valuesSketch.compression());
final TDigestState approximatedDeviationsSketch = new TDigestState(valuesSketch.compression());

for (int i = 1; i < 1000; i++) {
final double percentile = i / 1000d;
final double percentileValue = valuesSketch.quantile(percentile);
final double deviation = Math.abs(approximateMedian - percentileValue);
approximateDeviationsSketch.add(deviation);
}
valuesSketch.centroids().forEach(centroid -> {
final double deviation = Math.abs(approximateMedian - centroid.mean());
approximatedDeviationsSketch.add(deviation, centroid.count());
});

return approximateDeviationsSketch.quantile(0.5);
return approximatedDeviationsSketch.quantile(0.5);
}
}
Expand Up @@ -149,7 +149,8 @@ private void testCase(Query query,
IndexSearcher indexSearcher = newSearcher(indexReader, true, true);

MADAggregationBuilder builder = new MADAggregationBuilder("mad")
.field("number");
.field("number")
.setCompression(randomDoubleBetween(20, 1000, true));

MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
fieldType.setName("number");
Expand Down
Expand Up @@ -150,7 +150,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
private static MADAggregationBuilder randomBuilder() {
final MADAggregationBuilder builder = new MADAggregationBuilder("mad");
if (randomBoolean()) {
builder.setCompression(randomDoubleBetween(0, 1000, false));
builder.setCompression(randomDoubleBetween(20, 1000, false));
}
return builder;
}
Expand Down

0 comments on commit bd2420b

Please sign in to comment.