diff options
Diffstat (limited to 'src/crates')
-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() |