commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/distribution AbstractDiscreteDistribution.java
Date Tue, 11 May 2004 02:04:21 GMT
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 &le; X &le; x1).
  +     * For this distribution, X, this method returns P(x0 &le; X &le; 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 &le; x) &le; <code>p</code>.
        *
        * @param p the desired probability
  -     * @return x, such that P(X &lt; x) = <code>p</code>
  +     * @return the largest x such that P(X &le; 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message