You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2004/07/25 18:29:25 UTC

cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/distribution BinomialDistributionTest.java HypergeometricDistributionTest.java

psteitz     2004/07/25 09:29:25

  Modified:    math/src/java/org/apache/commons/math/distribution
                        BinomialDistributionImpl.java
                        DiscreteDistribution.java
               math/src/test/org/apache/commons/math/distribution
                        BinomialDistributionTest.java
                        HypergeometricDistributionTest.java
  Log:
  Corrected inverseCumulativeProbability(0).
  
  Revision  Changes    Path
  1.18      +5 -2      jakarta-commons/math/src/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
  
  Index: BinomialDistributionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- BinomialDistributionImpl.java	23 Jul 2004 05:22:36 -0000	1.17
  +++ BinomialDistributionImpl.java	25 Jul 2004 16:29:24 -0000	1.18
  @@ -162,6 +162,9 @@
       /**
        * For this distribution, X, this method returns the largest x, such
        * that P(X &le; x) &le; <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 &le; x) <= p
  @@ -172,7 +175,7 @@
       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; 
  
  
  
  1.16      +18 -3     jakarta-commons/math/src/java/org/apache/commons/math/distribution/DiscreteDistribution.java
  
  Index: DiscreteDistribution.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/DiscreteDistribution.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DiscreteDistribution.java	23 Jun 2004 16:26:15 -0000	1.15
  +++ DiscreteDistribution.java	25 Jul 2004 16:29:24 -0000	1.16
  @@ -51,11 +51,26 @@
       double cumulativeProbability(int x0, int x1) throws MathException;
       
       /**
  -     * For this distribution, X, this method returns the largest x such that P(X &le; x) <= p.
  +     * For this distribution, X, this method returns the largest x such that
  +     * P(X &le; 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 &le; 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 &le; 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;
   }
  
  
  
  1.15      +2 -2      jakarta-commons/math/src/test/org/apache/commons/math/distribution/BinomialDistributionTest.java
  
  Index: BinomialDistributionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/BinomialDistributionTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- BinomialDistributionTest.java	23 Jul 2004 05:22:36 -0000	1.14
  +++ BinomialDistributionTest.java	25 Jul 2004 16:29:25 -0000	1.15
  @@ -69,7 +69,7 @@
       
       /** 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 ---------------------------------
  
  
  
  1.12      +4 -4      jakarta-commons/math/src/test/org/apache/commons/math/distribution/HypergeometricDistributionTest.java
  
  Index: HypergeometricDistributionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/HypergeometricDistributionTest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- HypergeometricDistributionTest.java	11 May 2004 02:12:11 -0000	1.11
  +++ HypergeometricDistributionTest.java	25 Jul 2004 16:29:25 -0000	1.12
  @@ -64,13 +64,13 @@
       
       /** 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 ------------------------------
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org