psteitz     2004/07/22 22:22:36

  Modified:    math/src/java/org/apache/commons/math/distribution
                        BinomialDistributionImpl.java
               math/src/test/org/apache/commons/math/distribution
                        BinomialDistributionTest.java
  Log:
  Changed implementation to return correct inverse probabilities for p=0,1 (per 
discussion on commons-dev).
  
  Revision  Changes    Path
  1.17      +24 -1     
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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- BinomialDistributionImpl.java     23 Jun 2004 16:26:15 -0000      1.16
  +++ BinomialDistributionImpl.java     23 Jul 2004 05:22:36 -0000      1.17
  @@ -158,4 +158,27 @@
           }
           return ret;
       }
  +    
  +    /**
  +     * For this distribution, X, this method returns the largest x, such
  +     * that P(X &le; x) &le; <code>p</code>.
  +     *
  +     * @param p the desired probability
  +     * @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 < 0 or p > 1
  +     */
  +    public int inverseCumulativeProbability(final double p) throws MathException {
  +        // handle extreme values explicitly
  +        if (p == 0) {
  +            return 0;
  +        } 
  +        if (p == 1) {
  +            return Integer.MAX_VALUE; 
  +        }
  +        
  +        // use default bisection impl
  +        return super.inverseCumulativeProbability(p);
  +    }
   }
  
  
  
  1.14      +4 -4      
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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- BinomialDistributionTest.java     11 May 2004 02:11:15 -0000      1.13
  +++ BinomialDistributionTest.java     23 Jul 2004 05:22:36 -0000      1.14
  @@ -63,13 +63,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[] {0, 0.001d, 0.010d, 0.025d, 0.050d, 0.100d, 0.999d,
  +                0.990d, 0.975d, 0.950d, 0.900d,1}; 
           }
       
       /** Creates the default inverse cumulative probability density test expected 
values */
       public int[] makeInverseCumulativeTestValues() {
  -        return new int[] {1, 2, 3, 4, 4, 9, 9, 9, 8, 8};
  +        return new int[] {0,1, 2, 3, 4, 4, 9, 9, 9, 8, 8, Integer.MAX_VALUE};
       }
   
       //----------------- Additional test cases ---------------------------------
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to