Skip to content

Instantly share code, notes, and snippets.

@kunigami
Last active April 1, 2018 00:53
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 kunigami/0cfb5bba74589f875a4f87579130727b to your computer and use it in GitHub Desktop.
Save kunigami/0cfb5bba74589f875a4f87579130727b to your computer and use it in GitHub Desktop.
const LARGE_ESTIMATE_THRESHOLD: f64 = 143165576.53333333;
const TWO_TO_32: f64 = 4294967296.0; // 2^32
if estimate <= 2.5 * m_multiplier {
// Small range correction
let mut buckets_with_zero = 0;
for first_non_zero in first_non_zero_by_experiment {
if first_non_zero == 0 {
buckets_with_zero += 1;
}
}
if buckets_with_zero > 0 {
estimate = m_multiplier * (m_multiplier / (buckets_with_zero as f64)).ln();
}
} else if estimate > LARGE_ESTIMATE_THRESHOLD {
// Large range correction
estimate = -TWO_TO_32 * (1.0 - estimate/TWO_TO_32).ln();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment