From df813355c8c2d6e887010f64b258aa84d3984d5a Mon Sep 17 00:00:00 2001 From: Vecna Date: Mon, 27 May 2024 19:49:19 -0400 Subject: [PATCH] Integrate from 3 StdDevs down instead of starting at 0 --- src/analysis.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/analysis.rs b/src/analysis.rs index 77f472f..6496bd6 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -376,11 +376,19 @@ impl Analyzer for NormalAnalyzer { if mvn.is_ok() { let mvn = mvn.unwrap(); + // Start 3 standard deviations below the mean, based on + // 68-95-99.7 rule, assuming the confidence will be high + // enough that 99.7 is close enough to "the whole + // distribution" to be reasonable + let bip_start = (bridge_ips_mean - (3.0 * bridge_ips_f64.std_dev()).ceil()) as i32; + let pr_start = + (positive_reports_mean - (3.0 * positive_reports_f64.std_dev()).ceil()) as i32; + // Estimate the CDF by integrating the PDF by hand with step // size 1 let mut cdf = 0.0; - for bip in 0..bridge_ips_today { - for pr in 0..positive_reports_today { + for bip in bip_start..bridge_ips_today as i32 { + for pr in pr_start..positive_reports_today as i32 { cdf += mvn.pdf(&DVector::from_vec(vec![bip as f64, pr as f64])); } }