Skip to content

Instantly share code, notes, and snippets.

@tdunning
Created March 25, 2019 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdunning/11867865e17b8805d8f4da5938342961 to your computer and use it in GitHub Desktop.
Save tdunning/11867865e17b8805d8f4da5938342961 to your computer and use it in GitHub Desktop.
Test for moment sketches versus offset distribution
public class MomentSketchOffsetTest {
@Test
public void testOffsetUniform() throws Exception {
MomentSketch ms = new MomentSketch(1e-10);
ms.setSizeParam(7);
ms.initialize();
double[] data = TestDataSource.getUniform(20e1, 20e1 + 1, 1_000_000);
ms.add(data);
List<Double> ps = Arrays.asList(.1, .5, .9, 0.99, 0.999, 0.9999, 0.99999);
double[] qs = ms.getQuantiles(ps);
double[] expectedQs = QuantileUtil.getTrueQuantiles(ps, data);
assertArrayEquals(expectedQs, qs, 1.0);
DataGrouper grouper = new SeqDataGrouper(60);
ArrayList<double[]> cellData = grouper.group(data);
QuantileSketch mergedSketch = QuantileUtil.trainAndMerge(
() -> {
MomentSketch newMs = new MomentSketch(1e-10);
newMs.setSizeParam(7);
return newMs;
},
cellData
);
MomentSketch mmSketch = (MomentSketch)mergedSketch;
double[] qs2 = mmSketch.getQuantiles(ps);
assertArrayEquals(qs, qs2, 1e-7);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment