mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Add MAD=0 unit tests for outlier detection, see #329
This commit is contained in:
1 parent
25f8129212
commit
1477c68658
1 file changed
+13
@@ -29,6 +29,9 @@ pub fn modified_zscores(xs: &[f64]) -> Vec<f64> {
|
||||
// Compute median absolute deviation:
|
||||
let mad = median(&deviations);
|
||||
|
||||
// Handle MAD == 0 case
|
||||
let mad = if mad > 0.0 { mad } else { f64::EPSILON };
|
||||
|
||||
// Compute modified Z-scores (x_i - x_median) / MAD
|
||||
xs.iter().map(|&x| (x - x_median) / mad).collect()
|
||||
}
|
||||
@@ -99,3 +102,13 @@ fn test_detect_outliers() {
|
||||
];
|
||||
assert_eq!(2, num_outliers(&xs));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_outliers_if_mad_becomes_0() {
|
||||
// See https://stats.stackexchange.com/q/339932
|
||||
let xs = [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 100.0];
|
||||
assert_eq!(1, num_outliers(&xs));
|
||||
|
||||
let xs = [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 100.0, 100.0];
|
||||
assert_eq!(2, num_outliers(&xs));
|
||||
}
|
||||
Reference in new issue
Block a user