From e84687da98058d7be1acf47dc18b2bb7d9b871ca Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Sat, 11 Jun 2011 22:28:52 +0000 Subject: [PATCH] Fixed error in javadoc describing the behavior of the Percentile algorithm for small percentiles in small datasets. JIRA: MATH-582 Reported by Andre Herbst Patched by Christopher Nix git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1134802 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math/stat/descriptive/rank/Percentile.java | 7 ++++--- src/site/xdoc/changes.xml | 4 ++++ .../commons/math/stat/descriptive/rank/PercentileTest.java | 7 +++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java index c3cd66e0f..c813a2e99 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java @@ -41,9 +41,10 @@ import org.apache.commons.math.util.MathUtils; *
  • Compute the estimated percentile position * pos = p * (n + 1) / 100 and the difference, d * between pos and floor(pos) (i.e. the fractional - * part of pos). If pos >= n return the largest - * element in the array; otherwise
  • - *
  • Let lower be the element in position + * part of pos).
  • + *
  • If pos < 1 return the smallest element in the array.
  • + *
  • Else if pos >= n return the largest element in the array.
  • + *
  • Else let lower be the element in position * floor(pos) in the array and let upper be the * next element in the array. Return lower + d * (upper - lower) *
  • diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 1d0b40e37..2cf53d89a 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -52,6 +52,10 @@ The type attribute can be add,update,fix,remove. If the output is not quite correct, check for invisible trailing spaces! --> + + Fixed error in javadoc describing the behavior of the Percentile algorithm for + small percentiles in small datasets. + New "filter" package. Initial implementation of Kalman filter. diff --git a/src/test/java/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java b/src/test/java/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java index ad66549ed..584c5dcd5 100644 --- a/src/test/java/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java +++ b/src/test/java/org/apache/commons/math/stat/descriptive/rank/PercentileTest.java @@ -52,6 +52,13 @@ public class PercentileTest extends UnivariateStatisticAbstractTest{ Percentile p = new Percentile(75); Assert.assertEquals(3.0, p.evaluate(d), 1.0e-5); } + + @Test + public void testLowPercentile() { + double[] d = new double[] {0, 1}; + Percentile p = new Percentile(25); + Assert.assertEquals(0d, p.evaluate(d), Double.MIN_VALUE); + } @Test public void testPercentile() {