Skip to content

Add HLL++ bias correction to the dense visitor estimate - #4

Merged
sinnercode228 merged 3 commits into
mainfrom
feature/hll-bias-correction
Oct 15, 2026
Merged

sinnercode228 merged 3 commits into
mainfrom
feature/hll-bias-correction

Conversation

@sinnercode228

Copy link
Copy Markdown
Owner

What

  • packages/core/src/hll-bias.ts holds the empirical data for precision 11 from the HyperLogLog++ paper (Heule, Nunkesser, Hall, EDBT 2013): rawEstimateData, biasData and the linear counting threshold 1,800, with the paper's 6-nearest-neighbour bias lookup.
  • Hll.count() for dense sketches: linear counting up to 1,800, then the raw estimate minus its bias up to 5·m = 10,240, the plain raw estimate above.
  • Unchanged: the sparse exact mode, merge and the toBytes/fromBytes format, so stored sketches keep working.
  • README: the error table, limitation 2 and the test counts.

Why

The old count switched from linear counting to the uncorrected raw estimate at 5,120, where the raw estimate runs about 2.5% high. The 5,000 row was the worst in the README table:

distinct ids rms before -> after worst of 50
5,000 3.27% -> 1.82% 7.88% -> 5.80%

Other sizes are unchanged; every size from 1,800 to 6,000 improves.

How it is tested

  • Accuracy over 100 seeded streams up to 200,000: rms under 3%, mean under 1%. Fails on main at 5,000.
  • Continuity around 1,800, 5,120 and 10,240: on main one sketch jumps by 7.35% at the old switch; now the largest step is 3.16%.
  • Sketches serialized by main decode to identical bytes and count the same; merge stays associative and commutative.
  • The tables match three independent transcriptions of the appendix.
  • 118 tests pass (core 63, server 34, web 21); lint, typecheck and build pass.

@sinnercode228
sinnercode228 merged commit 9a5246e into main Oct 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant