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