Corrected the fix for MATH-1208.

This commit is contained in:
Phil Steitz 2015-03-09 12:49:12 -07:00
parent d41364faa4
commit 13abd04b46
2 changed files with 9 additions and 5 deletions

View File

@ -637,8 +637,12 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
final double pB = pB(binIndex); final double pB = pB(binIndex);
final RealDistribution kernel = k(x); final RealDistribution kernel = k(x);
if (kernel instanceof ConstantRealDistribution) { if (kernel instanceof ConstantRealDistribution) {
if (x < kernel.getNumericalMean()) {
return pBminus;
} else {
return pBminus + pB; return pBminus + pB;
} }
}
final double[] binBounds = getUpperBounds(); final double[] binBounds = getUpperBounds();
final double kB = kB(binIndex); final double kB = kB(binIndex);
final double lower = binIndex == 0 ? min : binBounds[binIndex - 1]; final double lower = binIndex == 0 ? min : binBounds[binIndex - 1];

View File

@ -448,7 +448,7 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
Assert.assertEquals(0.5, dist.cumulativeProbability(0), Double.MIN_VALUE); Assert.assertEquals(0.5, dist.cumulativeProbability(0), Double.MIN_VALUE);
Assert.assertEquals(1.0, dist.cumulativeProbability(1), 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(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);
} }
/** /**
@ -488,11 +488,11 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
Assert.assertTrue(Arrays.binarySearch(values, dist.sample()) >= 0); Assert.assertTrue(Arrays.binarySearch(values, dist.sample()) >= 0);
} }
final double tol = 10E-12; 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.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(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(1.0, dist.cumulativeProbability(15), tol);
Assert.assertEquals(2.0, dist.inverseCumulativeProbability(0.1), tol); Assert.assertEquals(2.0, dist.inverseCumulativeProbability(0.1), tol);