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/24 23:41:37 UTC

cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/distribution FDistributionTest.java GammaDistributionTest.java NormalDistributionTest.java TDistributionTest.java

psteitz     2004/07/24 14:41:37

  Modified:    math/src/java/org/apache/commons/math/distribution
                        ExponentialDistributionImpl.java
                        FDistributionImpl.java GammaDistributionImpl.java
                        NormalDistributionImpl.java TDistributionImpl.java
               math/src/test/org/apache/commons/math/distribution
                        FDistributionTest.java GammaDistributionTest.java
                        NormalDistributionTest.java TDistributionTest.java
  Log:
  Changed inverseCumulativeProbability to return correct values for p=0,1 as discussed on commons-dev.
  
  Revision  Changes    Path
  1.19      +4 -2      jakarta-commons/math/src/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java
  
  Index: ExponentialDistributionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ExponentialDistributionImpl.java	23 Jun 2004 16:26:15 -0000	1.18
  +++ ExponentialDistributionImpl.java	24 Jul 2004 21:41:36 -0000	1.19
  @@ -90,7 +90,9 @@
       /**
        * For this distribution, X, this method returns the critical point x, such
        * that P(X &lt; x) = <code>p</code>.
  -     *
  +     * <p>
  +     * Returns 0 for p=0 and <code>Double.POSITIVE_INFINITY</code> for p=1.
  +     * 
        * @param p the desired probability
        * @return x, such that P(X &lt; x) = <code>p</code>
        * @throws MathException if the inverse cumulative probability can not be
  
  
  
  1.19      +25 -1     jakarta-commons/math/src/java/org/apache/commons/math/distribution/FDistributionImpl.java
  
  Index: FDistributionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/FDistributionImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- FDistributionImpl.java	23 Jun 2004 16:26:15 -0000	1.18
  +++ FDistributionImpl.java	24 Jul 2004 21:41:36 -0000	1.19
  @@ -80,6 +80,30 @@
           }
           return ret;
       }
  +    
  +    /**
  +     * For this distribution, X, this method returns the critical point x, such
  +     * that P(X &lt; x) = <code>p</code>.
  +     * <p>
  +     * Returns 0 for p=0 and <code>Double.POSITIVE_INFINITY</code> for p=1.
  +     *
  +     * @param p the desired probability
  +     * @return x, such that P(X &lt; x) = <code>p</code>
  +     * @throws MathException if the inverse cumulative probability can not be
  +     *         computed due to convergence or other numerical errors.
  +     * @throws IllegalArgumentException if <code>p</code> is not a valid
  +     *         probability.
  +     */
  +    public double inverseCumulativeProbability(final double p) 
  +        throws MathException {
  +        if (p == 0) {
  +            return 0d;
  +        }
  +        if (p == 1) {
  +            return Double.POSITIVE_INFINITY;
  +        }
  +        return super.inverseCumulativeProbability(p);
  +    }
           
       /**
        * Access the domain value lower bound, based on <code>p</code>, used to
  
  
  
  1.22      +25 -1     jakarta-commons/math/src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java
  
  Index: GammaDistributionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- GammaDistributionImpl.java	23 Jun 2004 16:26:15 -0000	1.21
  +++ GammaDistributionImpl.java	24 Jul 2004 21:41:36 -0000	1.22
  @@ -78,6 +78,30 @@
       }
       
       /**
  +     * For this distribution, X, this method returns the critical point x, such
  +     * that P(X &lt; x) = <code>p</code>.
  +     * <p>
  +     * Returns 0 for p=0 and <code>Double.POSITIVE_INFINITY</code> for p=1.
  +     *
  +     * @param p the desired probability
  +     * @return x, such that P(X &lt; x) = <code>p</code>
  +     * @throws MathException if the inverse cumulative probability can not be
  +     *         computed due to convergence or other numerical errors.
  +     * @throws IllegalArgumentException if <code>p</code> is not a valid
  +     *         probability.
  +     */
  +    public double inverseCumulativeProbability(final double p) 
  +    throws MathException {
  +        if (p == 0) {
  +            return 0d;
  +        }
  +        if (p == 1) {
  +            return Double.POSITIVE_INFINITY;
  +        }
  +        return super.inverseCumulativeProbability(p);
  +    }
  +    
  +    /**
        * Modify the shape parameter, alpha.
        * @param alpha the new shape parameter.
        * @throws IllegalArgumentException if <code>alpha</code> is not positive.
  
  
  
  1.13      +26 -1     jakarta-commons/math/src/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
  
  Index: NormalDistributionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/NormalDistributionImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- NormalDistributionImpl.java	23 Jun 2004 16:26:15 -0000	1.12
  +++ NormalDistributionImpl.java	24 Jul 2004 21:41:36 -0000	1.13
  @@ -105,6 +105,31 @@
           return 0.5 * (1.0 + Erf.erf((x - mean) /
                   (standardDeviation * Math.sqrt(2.0))));
   	}
  +    
  +    /**
  +     * For this distribution, X, this method returns the critical point x, such
  +     * that P(X &lt; x) = <code>p</code>.
  +     * <p>
  +     * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and 
  +     * <code>Double.POSITIVE_INFINITY</code> for p=1.
  +     *
  +     * @param p the desired probability
  +     * @return x, such that P(X &lt; x) = <code>p</code>
  +     * @throws MathException if the inverse cumulative probability can not be
  +     *         computed due to convergence or other numerical errors.
  +     * @throws IllegalArgumentException if <code>p</code> is not a valid
  +     *         probability.
  +     */
  +    public double inverseCumulativeProbability(final double p) 
  +    throws MathException {
  +        if (p == 0) {
  +            return Double.NEGATIVE_INFINITY;
  +        }
  +        if (p == 1) {
  +            return Double.POSITIVE_INFINITY;
  +        }
  +        return super.inverseCumulativeProbability(p);
  +    }
   	
   	/**
   	 * Access the domain value lower bound, based on <code>p</code>, used to
  
  
  
  1.19      +26 -1     jakarta-commons/math/src/java/org/apache/commons/math/distribution/TDistributionImpl.java
  
  Index: TDistributionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/TDistributionImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- TDistributionImpl.java	23 Jun 2004 16:26:15 -0000	1.18
  +++ TDistributionImpl.java	24 Jul 2004 21:41:36 -0000	1.19
  @@ -90,6 +90,31 @@
   
           return ret;
       }
  +    
  +    /**
  +     * For this distribution, X, this method returns the critical point x, such
  +     * that P(X &lt; x) = <code>p</code>.
  +     * <p>
  +     * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and 
  +     * <code>Double.POSITIVE_INFINITY</code> for p=1.
  +     *
  +     * @param p the desired probability
  +     * @return x, such that P(X &lt; x) = <code>p</code>
  +     * @throws MathException if the inverse cumulative probability can not be
  +     *         computed due to convergence or other numerical errors.
  +     * @throws IllegalArgumentException if <code>p</code> is not a valid
  +     *         probability.
  +     */
  +    public double inverseCumulativeProbability(final double p) 
  +    throws MathException {
  +        if (p == 0) {
  +            return Double.NEGATIVE_INFINITY;
  +        }
  +        if (p == 1) {
  +            return Double.POSITIVE_INFINITY;
  +        }
  +        return super.inverseCumulativeProbability(p);
  +    }
   
       /**
        * Access the domain value lower bound, based on <code>p</code>, used to
  
  
  
  1.16      +3 -4      jakarta-commons/math/src/test/org/apache/commons/math/distribution/FDistributionTest.java
  
  Index: FDistributionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/FDistributionTest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- FDistributionTest.java	10 Jun 2004 18:27:47 -0000	1.15
  +++ FDistributionTest.java	24 Jul 2004 21:41:37 -0000	1.16
  @@ -69,9 +69,8 @@
       }
   
       public void testInverseCumulativeProbabilityExtremes() throws Exception {
  -        //TODO: decide what to do about p = 1.  This currently blows up the solver.
  -        setInverseCumulativeTestPoints(new double[] {0});
  -        setInverseCumulativeTestValues(new double[] {0});
  +        setInverseCumulativeTestPoints(new double[] {0, 1});
  +        setInverseCumulativeTestValues(new double[] {0, Double.POSITIVE_INFINITY});
           verifyInverseCumulativeProbabilities();
       }
       
  
  
  
  1.18      +7 -1      jakarta-commons/math/src/test/org/apache/commons/math/distribution/GammaDistributionTest.java
  
  Index: GammaDistributionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/GammaDistributionTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- GammaDistributionTest.java	31 May 2004 00:55:22 -0000	1.17
  +++ GammaDistributionTest.java	24 Jul 2004 21:41:37 -0000	1.18
  @@ -111,4 +111,10 @@
           double actual = distribution.inverseCumulativeProbability(p);
           assertEquals("critical value for " + p, expected, actual, 10e-4);
       }
  +    
  +    public void testInverseCumulativeProbabilityExtremes() throws Exception {
  +        setInverseCumulativeTestPoints(new double[] {0, 1});
  +        setInverseCumulativeTestValues(new double[] {0, Double.POSITIVE_INFINITY});
  +        verifyInverseCumulativeProbabilities();
  +    }
   }
  
  
  
  1.8       +8 -1      jakarta-commons/math/src/test/org/apache/commons/math/distribution/NormalDistributionTest.java
  
  Index: NormalDistributionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/NormalDistributionTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NormalDistributionTest.java	30 May 2004 05:54:43 -0000	1.7
  +++ NormalDistributionTest.java	24 Jul 2004 21:41:37 -0000	1.8
  @@ -86,6 +86,13 @@
           verifyQuantiles();
       }
       
  +    public void testInverseCumulativeProbabilityExtremes() throws Exception {
  +        setInverseCumulativeTestPoints(new double[] {0, 1});
  +        setInverseCumulativeTestValues(
  +                new double[] {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY});
  +        verifyInverseCumulativeProbabilities();
  +    }
  +    
       public void testGetMean() {
           NormalDistribution distribution = (NormalDistribution) getDistribution();
           assertEquals(2.1, distribution.getMean(), 0);
  
  
  
  1.15      +8 -1      jakarta-commons/math/src/test/org/apache/commons/math/distribution/TDistributionTest.java
  
  Index: TDistributionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/TDistributionTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TDistributionTest.java	30 May 2004 22:13:35 -0000	1.14
  +++ TDistributionTest.java	24 Jul 2004 21:41:37 -0000	1.15
  @@ -83,6 +83,13 @@
           verifyInverseCumulativeProbabilities();
       }
       
  +    public void testInverseCumulativeProbabilityExtremes() throws Exception {
  +        setInverseCumulativeTestPoints(new double[] {0, 1});
  +        setInverseCumulativeTestValues(
  +                new double[] {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY});
  +        verifyInverseCumulativeProbabilities();
  +    }
  +    
       public void testDfAccessors() {
           TDistribution distribution = (TDistribution) getDistribution();
           assertEquals(5d, distribution.getDegreesOfFreedom(), Double.MIN_VALUE);
  
  
  

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