psteitz 2004/05/10 19:04:21
Modified: math/src/java/org/apache/commons/math/distribution
AbstractDiscreteDistribution.java
Log:
Improved documentation. Added x0 <= x1 check in cumulativeProbability. Required p <
1 in inverseCumulativeProbability.
Revision Changes Path
1.13 +15 -10
jakarta-commons/math/src/java/org/apache/commons/math/distribution/AbstractDiscreteDistribution.java
Index: AbstractDiscreteDistribution.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/AbstractDiscreteDistribution.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- AbstractDiscreteDistribution.java 8 Apr 2004 20:45:59 -0000 1.12
+++ AbstractDiscreteDistribution.java 11 May 2004 02:04:21 -0000 1.13
@@ -36,31 +36,36 @@
}
/**
- * For this disbution, X, this method returns P(x0 ≤ X ≤ x1).
+ * For this distribution, X, this method returns P(x0 ≤ X ≤ x1).
* @param x0 the inclusive, lower bound
* @param x1 the inclusive, upper bound
* @return the cumulative probability.
* @exception MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
+ * @exception IllegalArgumentException if x0 > x1
*/
- public double cumulativeProbability(int x0, int x1) throws MathException{
- return cumulativeProbability(x1) -
- cumulativeProbability(x0 - 1);
+ public double cumulativeProbability(int x0, int x1) throws MathException {
+ if (x0 > x1) {
+ throw new IllegalArgumentException
+ ("lower endpoint must be less than or equal to upper endpoint");
+ }
+ return cumulativeProbability(x1) - cumulativeProbability(x0 - 1);
}
/**
- * For this distribution, X, this method returns the critical point x, such
+ * For this distribution, X, this method returns the lagest x, such
* that P(X ≤ x) ≤ <code>p</code>.
*
* @param p the desired probability
- * @return x, such that P(X < x) = <code>p</code>
+ * @return the largest x such that P(X ≤ x) <= p
* @exception MathException if the inverse cumulative probability can not be
* computed due to convergence or other numerical errors.
+ * @exception IllegalArgumentException if p < 0 or p >= 1
*/
public int inverseCumulativeProbability(final double p) throws MathException{
- if (p < 0.0 || p > 1.0) {
+ if (p < 0.0 || p >= 1.0) {
throw new IllegalArgumentException(
- "p must be between 0.0 and 1.0, inclusive.");
+ "p must be greater than or equal to 0.0 and strictly less than
1.0");
}
// by default, do simple bisection.
@@ -100,7 +105,7 @@
--x0;
pm = cumulativeProbability(x0);
}
-
+
return x0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]