Skip to main content

intersect_error_bound

Function intersect_error_bound 

Source
pub fn intersect_error_bound(
    a: &HyperLogLog,
    b: &HyperLogLog,
) -> Result<f64, HllError>
Expand description

Absolute error the inclusion-exclusion estimate carries at one standard deviation. It scales with |A| + |B|, so a thin overlap between two large sets can come back with an error bar wider than the answer. Check it against the estimate before believing an intersection.

Examples found in repository?
examples/sample_app.rs (line 190)
175fn cross_venue_overlap(tape: &[Event]) {
176    use subms_hyperloglog::{estimate_intersect, estimate_union, intersect_error_bound};
177    println!("\n== venues: account reach and overlap ==");
178
179    let mut a = HyperLogLog::new(14);
180    let mut b = HyperLogLog::new(14);
181    for e in tape {
182        if e.venue == 0 {
183            a.add_u64(e.account);
184        } else {
185            b.add_u64(e.account);
186        }
187    }
188    let union = estimate_union(&a, &b).expect("same precision");
189    let inter = estimate_intersect(&a, &b).expect("same precision");
190    let bound = intersect_error_bound(&a, &b).expect("same precision");
191    println!("  venue 0: {:>7.0} accounts", a.estimate());
192    println!("  venue 1: {:>7.0} accounts", b.estimate());
193    println!("  reach:   {union:>7.0} (true 50000)");
194    println!("  both:    {inter:>7.0} (true 10000) +/- {bound:.0}");
195    assert!(
196        (union - 50_000.0).abs() / 50_000.0 < 0.05,
197        "reach within 5%, got {union}"
198    );
199    assert!(inter > 0.0, "a 10k overlap must survive the subtraction");
200}