diff options
author | Aria Shrimpton <me@aria.rip> | 2024-03-25 13:28:23 +0000 |
---|---|---|
committer | Aria Shrimpton <me@aria.rip> | 2024-03-25 13:28:23 +0000 |
commit | d8cee46d271b9336ddccf4485436845451f9b218 (patch) | |
tree | bf64f7084409f753f151f94bf3080e25591b341a /src/crates/candelabra | |
parent | ed8f7c8a62862ab220f69367254084e1b3bcb8fc (diff) |
change outlier detection to within a standard deviation
Diffstat (limited to 'src/crates/candelabra')
-rw-r--r-- | src/crates/candelabra/src/cost/fit.rs | 12 |
1 files changed, 8 insertions, 4 deletions
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::<f64>() / n_results.len() as f64; + let dev = (n_results + .iter() + .map(|(_, x)| (x - mean).powi(2)) + .sum::<f64>() + / 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() |