commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject [math] Corrected the fix for MATH-1208.
Date Mon, 09 Mar 2015 19:38:05 GMT
Repository: commons-math
Updated Branches:
  refs/heads/master b148046ad -> ce2badf02


Corrected the fix for MATH-1208.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/ce2badf0
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/ce2badf0
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/ce2badf0

Branch: refs/heads/master
Commit: ce2badf02e266a84e2485f1793f13bf722c29306
Parents: b148046
Author: Phil Steitz <phil.steitz@gmail.com>
Authored: Mon Mar 9 12:37:57 2015 -0700
Committer: Phil Steitz <phil.steitz@gmail.com>
Committed: Mon Mar 9 12:37:57 2015 -0700

----------------------------------------------------------------------
 .../apache/commons/math4/random/EmpiricalDistribution.java   | 6 +++++-
 .../commons/math4/random/EmpiricalDistributionTest.java      | 8 ++++----
 2 files changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/ce2badf0/src/main/java/org/apache/commons/math4/random/EmpiricalDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/EmpiricalDistribution.java b/src/main/java/org/apache/commons/math4/random/EmpiricalDistribution.java
index 61bb65b..685c08b 100644
--- a/src/main/java/org/apache/commons/math4/random/EmpiricalDistribution.java
+++ b/src/main/java/org/apache/commons/math4/random/EmpiricalDistribution.java
@@ -610,7 +610,11 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
         final double pB = pB(binIndex);
         final RealDistribution kernel = k(x);
         if (kernel instanceof ConstantRealDistribution) {
-            return pBminus + pB;
+            if (x < kernel.getNumericalMean()) {
+                return pBminus;
+            } else {
+                return pBminus + pB;
+            }
         }
         final double[] binBounds = getUpperBounds();
         final double kB = kB(binIndex);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ce2badf0/src/test/java/org/apache/commons/math4/random/EmpiricalDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/EmpiricalDistributionTest.java
b/src/test/java/org/apache/commons/math4/random/EmpiricalDistributionTest.java
index 47a6185..6f38711 100644
--- a/src/test/java/org/apache/commons/math4/random/EmpiricalDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/random/EmpiricalDistributionTest.java
@@ -446,7 +446,7 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
         Assert.assertEquals(0.5, dist.cumulativeProbability(0), Double.MIN_VALUE);
         Assert.assertEquals(1.0, dist.cumulativeProbability(1), Double.MIN_VALUE);
         Assert.assertEquals(0.5, dist.cumulativeProbability(0.5), Double.MIN_VALUE);
-        Assert.assertEquals(1.0, dist.cumulativeProbability(0.7), Double.MIN_VALUE);
+        Assert.assertEquals(0.5, dist.cumulativeProbability(0.7), Double.MIN_VALUE);
     }
     
     /**
@@ -486,11 +486,11 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
             Assert.assertTrue(Arrays.binarySearch(values, dist.sample()) >= 0);
         }
         final double tol = 10E-12;
-        Assert.assertEquals(0.2, dist.cumulativeProbability(1), tol);
+        Assert.assertEquals(0.0, dist.cumulativeProbability(1), tol);
         Assert.assertEquals(0.2, dist.cumulativeProbability(2), tol);
-        Assert.assertEquals(0.8, dist.cumulativeProbability(10), tol);
+        Assert.assertEquals(0.6, dist.cumulativeProbability(10), tol);
         Assert.assertEquals(0.8, dist.cumulativeProbability(12), tol);
-        Assert.assertEquals(1.0, dist.cumulativeProbability(13), tol);
+        Assert.assertEquals(0.8, dist.cumulativeProbability(13), tol);
         Assert.assertEquals(1.0, dist.cumulativeProbability(15), tol);
 
         Assert.assertEquals(2.0, dist.inverseCumulativeProbability(0.1), tol);


Mime
View raw message