Corrected inverseCumulativeProbability(0).
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141417 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bec758a4e5
commit
b134bf41f7
|
@ -24,7 +24,7 @@ import org.apache.commons.math.util.MathUtils;
|
|||
/**
|
||||
* The default implementation of {@link BinomialDistribution}.
|
||||
*
|
||||
* @version $Revision: 1.17 $ $Date: 2004/07/23 05:22:36 $
|
||||
* @version $Revision: 1.18 $ $Date: 2004/07/25 16:29:24 $
|
||||
*/
|
||||
public class BinomialDistributionImpl
|
||||
extends AbstractDiscreteDistribution
|
||||
|
@ -162,6 +162,9 @@ public class BinomialDistributionImpl
|
|||
/**
|
||||
* For this distribution, X, this method returns the largest x, such
|
||||
* that P(X ≤ x) ≤ <code>p</code>.
|
||||
* <p>
|
||||
* Returns <code>-1</code> for p=0 and <code>Integer.MAX_VALUE</code> for
|
||||
* p=1.
|
||||
*
|
||||
* @param p the desired probability
|
||||
* @return the largest x such that P(X ≤ x) <= p
|
||||
|
@ -172,7 +175,7 @@ public class BinomialDistributionImpl
|
|||
public int inverseCumulativeProbability(final double p) throws MathException {
|
||||
// handle extreme values explicitly
|
||||
if (p == 0) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
if (p == 1) {
|
||||
return Integer.MAX_VALUE;
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.apache.commons.math.MathException;
|
|||
/**
|
||||
* Base interface for various discrete distributions.
|
||||
*
|
||||
* @version $Revision: 1.15 $ $Date: 2004/06/23 16:26:15 $
|
||||
* @version $Revision: 1.16 $ $Date: 2004/07/25 16:29:24 $
|
||||
*/
|
||||
public interface DiscreteDistribution {
|
||||
/**
|
||||
|
@ -51,11 +51,26 @@ public interface DiscreteDistribution {
|
|||
double cumulativeProbability(int x0, int x1) throws MathException;
|
||||
|
||||
/**
|
||||
* For this distribution, X, this method returns the largest x such that P(X ≤ x) <= p.
|
||||
* For this distribution, X, this method returns the largest x such that
|
||||
* P(X ≤ x) <= p.
|
||||
* <p>
|
||||
* Note that this definition implies: <ul>
|
||||
* <li> If there is a minimum value, <code>m</code>, with postive
|
||||
* probablility under (the density of) X, then <code>m - 1</code> is
|
||||
* returned by <code>inverseCumulativeProbability(0).</code> If there is
|
||||
* no such value <code>m, Integer.MIN_VALUE</code> is
|
||||
* returned.</li>
|
||||
* <li> If there is a maximum value, <code>M</code>, such that
|
||||
* P(X ≤ M) =1, then <code>M</code> is returned by
|
||||
* <code>inverseCumulativeProbability(1).</code>
|
||||
* If there is no such value, <code>M, Integer.MAX_VALUE</code> is
|
||||
* returned.</li></ul>
|
||||
*
|
||||
* @param p the cumulative probability.
|
||||
* @return x.
|
||||
* @return the largest x such that P(X ≤ x) <= p
|
||||
* @throws MathException if the inverse cumulative probability can not be
|
||||
* computed due to convergence or other numerical errors.
|
||||
* @throws IllegalArgumentException if p is not between 0 and 1 (inclusive)
|
||||
*/
|
||||
int inverseCumulativeProbability(double p) throws MathException;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.commons.math.distribution;
|
|||
* Extends DiscreteDistributionAbstractTest. See class javadoc for
|
||||
* DiscreteDistributionAbstractTest for details.
|
||||
*
|
||||
* @version $Revision: 1.14 $ $Date: 2004/07/23 05:22:36 $
|
||||
* @version $Revision: 1.15 $ $Date: 2004/07/25 16:29:25 $
|
||||
*/
|
||||
public class BinomialDistributionTest extends DiscreteDistributionAbstractTest {
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class BinomialDistributionTest extends DiscreteDistributionAbstractTest {
|
|||
|
||||
/** Creates the default inverse cumulative probability density test expected values */
|
||||
public int[] makeInverseCumulativeTestValues() {
|
||||
return new int[] {0,1, 2, 3, 4, 4, 9, 9, 9, 8, 8, Integer.MAX_VALUE};
|
||||
return new int[] {-1, 1, 2, 3, 4, 4, 9, 9, 9, 8, 8, Integer.MAX_VALUE};
|
||||
}
|
||||
|
||||
//----------------- Additional test cases ---------------------------------
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.commons.math.distribution;
|
|||
* Extends DiscreteDistributionAbstractTest. See class javadoc for
|
||||
* DiscreteDistributionAbstractTest for details.
|
||||
*
|
||||
* @version $Revision: 1.11 $ $Date: 2004/05/11 02:12:11 $
|
||||
* @version $Revision: 1.12 $ $Date: 2004/07/25 16:29:25 $
|
||||
*/
|
||||
public class HypergeometricDistributionTest extends DiscreteDistributionAbstractTest {
|
||||
|
||||
|
@ -64,13 +64,13 @@ public class HypergeometricDistributionTest extends DiscreteDistributionAbstract
|
|||
|
||||
/** Creates the default inverse cumulative probability test input values */
|
||||
public double[] makeInverseCumulativeTestPoints() {
|
||||
return new double[] {0.001d, 0.010d, 0.025d, 0.050d, 0.100d, 0.999d,
|
||||
0.990d, 0.975d, 0.950d, 0.900d};
|
||||
return new double[] {0d, 0.001d, 0.010d, 0.025d, 0.050d, 0.100d, 0.999d,
|
||||
0.990d, 0.975d, 0.950d, 0.900d, 1d};
|
||||
}
|
||||
|
||||
/** Creates the default inverse cumulative probability density test expected values */
|
||||
public int[] makeInverseCumulativeTestValues() {
|
||||
return new int[] {-1, 0, 0, 0, 0, 4, 3, 3, 3, 3};
|
||||
return new int[] {-1, -1, 0, 0, 0, 0, 4, 3, 3, 3, 3, 5};
|
||||
}
|
||||
|
||||
//-------------------- Additional test cases ------------------------------
|
||||
|
|
Loading…
Reference in New Issue