Skip to content

Instantly share code, notes, and snippets.

@abramsm
Created April 29, 2013 19:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abramsm/5483928 to your computer and use it in GitHub Desktop.
Save abramsm/5483928 to your computer and use it in GitHub Desktop.
example HLL+ for different p values
for (int p = 10; p < 18; p++)
{
HyperLogLogPlus hyperLogLogPlus = new HyperLogLogPlus(p, 25);
int count = 4200000;
for (int i = 0; i < count; i++)
{
hyperLogLogPlus.offer("i" + i);
}
long estimate = hyperLogLogPlus.cardinality();
double se = count * (1.04 / Math.sqrt(Math.pow(2, p)));
long expectedCardinality = count;
double error = (count - estimate) / (double) count;
System.out.println("Expect estimate for p=" + p + " is " + estimate + " with error: " + error + " is between " + (expectedCardinality - (3 * se)) + " and " + (expectedCardinality + (3 * se)) + " mem:" + hyperLogLogPlus.getBytes().length);
assertTrue(estimate >= expectedCardinality - se);
assertTrue(estimate <= expectedCardinality + se);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment