From d8cee46d271b9336ddccf4485436845451f9b218 Mon Sep 17 00:00:00 2001 From: Aria Shrimpton Date: Mon, 25 Mar 2024 13:28:23 +0000 Subject: change outlier detection to within a standard deviation --- src/crates/candelabra/src/cost/fit.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/crates/candelabra/src/cost/fit.rs b/src/crates/candelabra/src/cost/fit.rs index a6dbce0..0807f49 100644 --- a/src/crates/candelabra/src/cost/fit.rs +++ b/src/crates/candelabra/src/cost/fit.rs @@ -107,12 +107,16 @@ impl Estimator { for &n in ns.iter() { let mut n_results: Vec<_> = results.iter().filter(|(n2, _)| *n2 == n).collect(); let old_len = n_results.len(); - n_results.sort_by(|(_, x1), (_, x2)| x1.partial_cmp(x2).unwrap()); - let (_, lq) = n_results[n_results.len() / 4]; - let (_, uq) = n_results[(n_results.len() / 2) + (n_results.len() / 4)]; + let mean = n_results.iter().map(|(_, x)| x).sum::() / n_results.len() as f64; + let dev = (n_results + .iter() + .map(|(_, x)| (x - mean).powi(2)) + .sum::() + / n_results.len() as f64) + .sqrt(); - n_results.retain(|(_, x)| *x >= *lq && *x < *uq); + n_results.retain(|(_, x)| (*x - mean).abs() >= dev); trace!( "Discarded {} outliers for n = {n}", old_len - n_results.len() -- cgit v1.2.3