commit | dea908b0b601bdeea98765eeea2643e225a42bf4 | [log] [tgz] |
---|---|---|
author | aherbert <aherbert@apache.org> | Wed Jul 21 14:59:43 2021 +0100 |
committer | aherbert <aherbert@apache.org> | Wed Jul 21 14:59:43 2021 +0100 |
tree | 1bd5a9ca021dfba12df0a97244543266fd8f2776 | |
parent | 91ab0425cc7b8268918a630b787b572528ce7ec4 [diff] |
Use binary search for the quartile This reduces the comparisons to 2 for all points. Previous algorithm had: 25% - 1 25% - 2 50% - 3 Mean = 2.25
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TestUtils.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TestUtils.java index 717cdad..df770ee 100644 --- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TestUtils.java +++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TestUtils.java
@@ -230,14 +230,10 @@ * @param quartiles Quartiles. */ public static void updateCounts(double value, long[] counts, double[] quartiles) { - if (value < quartiles[0]) { - counts[0]++; - } else if (value > quartiles[2]) { - counts[3]++; - } else if (value > quartiles[1]) { - counts[2]++; + if (value > quartiles[1]) { + counts[value <= quartiles[2] ? 2 : 3]++; } else { - counts[1]++; + counts[value <= quartiles[0] ? 0 : 1]++; } }