commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1205963 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/distribution/ main/java/org/apache/commons/math/random/ test/java/org/apache/commons/math/distribution/ test/java/org/apache/commons/math/random/
Date Thu, 24 Nov 2011 19:37:36 GMT
Author: celestin
Date: Thu Nov 24 19:37:34 2011
New Revision: 1205963

URL: http://svn.apache.org/viewvc?rev=1205963&view=rev
Log:
Merged BinomialDistribution and BinomialDistributionImpl (MATH-711).

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java
      - copied, changed from r1205957, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
Removed:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java

Copied: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java
(from r1205957, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java&r1=1205957&r2=1205963&rev=1205963&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistribution.java
Thu Nov 24 19:37:34 2011
@@ -25,12 +25,14 @@ import org.apache.commons.math.special.B
 import org.apache.commons.math.util.FastMath;
 
 /**
- * The default implementation of {@link BinomialDistribution}.
+ * Implementation of the binomial distribution.
  *
+ * @see <a href="http://en.wikipedia.org/wiki/Binomial_distribution">Binomial distribution
(Wikipedia)</a>
+ * @see <a href="http://mathworld.wolfram.com/BinomialDistribution.html">Binomial Distribution
(MathWorld)</a>
  * @version $Id$
  */
-public class BinomialDistributionImpl extends AbstractIntegerDistribution
-        implements BinomialDistribution, Serializable {
+public class BinomialDistribution extends AbstractIntegerDistribution
+        implements Serializable {
     /** Serializable version identifier. */
     private static final long serialVersionUID = 6751309484392813623L;
     /** The number of trials. */
@@ -47,7 +49,7 @@ public class BinomialDistributionImpl ex
      * @throws NotPositiveException if {@code trials < 0}.
      * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
      */
-    public BinomialDistributionImpl(int trials, double p) {
+    public BinomialDistribution(int trials, double p) {
         if (trials < 0) {
             throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                            trials);
@@ -61,50 +63,36 @@ public class BinomialDistributionImpl ex
     }
 
     /**
-     * {@inheritDoc}
+     * Access the number of trials for this distribution.
+     *
+     * @return the number of trials.
      */
     public int getNumberOfTrials() {
         return numberOfTrials;
     }
 
     /**
-     * {@inheritDoc}
+     * Access the probability of success for this distribution.
+     *
+     * @return the probability of success.
      */
     public double getProbabilityOfSuccess() {
         return probabilityOfSuccess;
     }
 
-    /**
-     * Access the domain value lower bound, based on {@code p}, used to
-     * bracket a PDF root.
-     *
-     * @param p Desired probability for the critical value.
-     * @return the domain value lower bound, i.e. {@code P(X < 'lower bound') < p}.
-     */
+    /** {@inheritDoc} */
     @Override
     protected int getDomainLowerBound(double p) {
         return -1;
     }
 
-    /**
-     * Access the domain value upper bound, based on {@code p}, used to
-     * bracket a PDF root.
-     *
-     * @param p Desired probability for the critical value
-     * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
-     */
+    /** {@inheritDoc} */
     @Override
     protected int getDomainUpperBound(double p) {
         return numberOfTrials;
     }
 
-    /**
-     * For this distribution, {@code X}, this method returns {@code P(X <= x)}.
-     *
-     * @param x Value at which the PDF is evaluated.
-     * @return PDF for this distribution.
-     * due to convergence or other numerical errors.
-     */
+    /** {@inheritDoc} */
     @Override
     public double cumulativeProbability(int x) {
         double ret;
@@ -119,12 +107,7 @@ public class BinomialDistributionImpl ex
         return ret;
     }
 
-    /**
-     * For this distribution, {@code X}, this method returns {@code P(X = x)}.
-     *
-     * @param x Value at which the PMF is evaluated.
-     * @return PMF for this distribution.
-     */
+    /** {@inheritDoc} */
     public double probability(int x) {
         double ret;
         if (x < 0 || x > numberOfTrials) {
@@ -138,13 +121,10 @@ public class BinomialDistributionImpl ex
     }
 
     /**
-     * For this distribution, {@code X}, this method returns the largest
-     * {@code x}, such that {@code P(X < x) p}.
-     * It will return -1 when p = 0 and {@code Integer.MAX_VALUE} when p = 1.
+     * {@inheritDoc}
      *
-     * @param p Desired probability.
-     * @return the largest {@code x} such that {@code P(X < x) <= p}.
-     * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
+     * This implementation return -1 when {@code p == 0} and
+     * {@code Integer.MAX_VALUE} when {@code p == 1}.
      */
     @Override
     public int inverseCumulativeProbability(final double p) {
@@ -188,29 +168,23 @@ public class BinomialDistributionImpl ex
     /**
      * {@inheritDoc}
      *
-     * For <code>n</code> number of trials and
-     * probability parameter <code>p</code>, the mean is
-     * <code>n * p</code>
-     *
-     * @return {@inheritDoc}
+     * For {@code n} trials and probability parameter {@code p}, the mean is
+     * {@code n * p}.
      */
     @Override
     protected double calculateNumericalMean() {
-        return (double)getNumberOfTrials() * getProbabilityOfSuccess();
+        return getNumberOfTrials() * getProbabilityOfSuccess();
     }
 
     /**
      * {@inheritDoc}
      *
-     * For <code>n</code> number of trials and
-     * probability parameter <code>p</code>, the variance is
-     * <code>n * p * (1 - p)</code>
-     *
-     * @return {@inheritDoc}
+     * For {@code n} trials and probability parameter {@code p}, the variance is
+     * {@code n * p * (1 - p)}.
      */
     @Override
     protected double calculateNumericalVariance() {
         final double p = getProbabilityOfSuccess();
-        return (double)getNumberOfTrials() * p * (1 - p);
+        return getNumberOfTrials() * p * (1 - p);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java?rev=1205963&r1=1205962&r2=1205963&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
Thu Nov 24 19:37:34 2011
@@ -25,7 +25,7 @@ import java.security.SecureRandom;
 import java.util.Collection;
 
 import org.apache.commons.math.distribution.BetaDistribution;
-import org.apache.commons.math.distribution.BinomialDistributionImpl;
+import org.apache.commons.math.distribution.BinomialDistribution;
 import org.apache.commons.math.distribution.CauchyDistributionImpl;
 import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
 import org.apache.commons.math.distribution.ContinuousDistribution;
@@ -613,7 +613,7 @@ public class RandomDataImpl implements R
     }
 
     /**
-     * Generates a random value from the {@link BinomialDistributionImpl Binomial Distribution}.
+     * Generates a random value from the {@link BinomialDistribution Binomial Distribution}.
      * This implementation uses {@link #nextInversionDeviate(ContinuousDistribution) inversion}
      * to generate random values.
      *
@@ -623,7 +623,7 @@ public class RandomDataImpl implements R
      * @since 2.2
      */
     public int nextBinomial(int numberOfTrials, double probabilityOfSuccess) {
-        return nextInversionDeviate(new BinomialDistributionImpl(numberOfTrials, probabilityOfSuccess));
+        return nextInversionDeviate(new BinomialDistribution(numberOfTrials, probabilityOfSuccess));
     }
 
     /**

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java?rev=1205963&r1=1205962&r2=1205963&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java
Thu Nov 24 19:37:34 2011
@@ -31,7 +31,7 @@ public class BinomialDistributionTest ex
     /** Creates the default discrete distribution instance to use in tests. */
     @Override
     public IntegerDistribution makeDistribution() {
-        return new BinomialDistributionImpl(10, 0.70);
+        return new BinomialDistribution(10, 0.70);
     }
 
     /** Creates the default probability density test input values */
@@ -82,7 +82,7 @@ public class BinomialDistributionTest ex
     /** Test degenerate case p = 0 */
     @Test
     public void testDegenerate0() throws Exception {
-        setDistribution(new BinomialDistributionImpl(5, 0.0d));
+        setDistribution(new BinomialDistribution(5, 0.0d));
         setCumulativeTestPoints(new int[] { -1, 0, 1, 5, 10 });
         setCumulativeTestValues(new double[] { 0d, 1d, 1d, 1d, 1d });
         setDensityTestPoints(new int[] { -1, 0, 1, 10, 11 });
@@ -97,7 +97,7 @@ public class BinomialDistributionTest ex
     /** Test degenerate case p = 1 */
     @Test
     public void testDegenerate1() throws Exception {
-        setDistribution(new BinomialDistributionImpl(5, 1.0d));
+        setDistribution(new BinomialDistribution(5, 1.0d));
         setCumulativeTestPoints(new int[] { -1, 0, 1, 2, 5, 10 });
         setCumulativeTestValues(new double[] { 0d, 0d, 0d, 0d, 1d, 1d });
         setDensityTestPoints(new int[] { -1, 0, 1, 2, 5, 10 });
@@ -113,12 +113,12 @@ public class BinomialDistributionTest ex
     public void testMoments() {
         final double tol = 1e-9;
         BinomialDistribution dist;
-        
-        dist = new BinomialDistributionImpl(10, 0.5);
+
+        dist = new BinomialDistribution(10, 0.5);
         Assert.assertEquals(dist.getNumericalMean(), 10d * 0.5d, tol);
-        Assert.assertEquals(dist.getNumericalVariance(), 10d * 0.5d * 0.5d, tol); 
-        
-        dist = new BinomialDistributionImpl(30, 0.3);
+        Assert.assertEquals(dist.getNumericalVariance(), 10d * 0.5d * 0.5d, tol);
+
+        dist = new BinomialDistribution(30, 0.3);
         Assert.assertEquals(dist.getNumericalMean(), 30d * 0.3d, tol);
         Assert.assertEquals(dist.getNumericalVariance(), 30d * 0.3d * (1d - 0.3d), tol);
     }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java?rev=1205963&r1=1205962&r2=1205963&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java
Thu Nov 24 19:37:34 2011
@@ -26,7 +26,7 @@ import org.apache.commons.math.Retry;
 import org.apache.commons.math.RetryRunner;
 import org.apache.commons.math.TestUtils;
 import org.apache.commons.math.distribution.BetaDistribution;
-import org.apache.commons.math.distribution.BinomialDistributionImpl;
+import org.apache.commons.math.distribution.BinomialDistribution;
 import org.apache.commons.math.distribution.BinomialDistributionTest;
 import org.apache.commons.math.distribution.CauchyDistributionImpl;
 import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
@@ -963,7 +963,7 @@ public class RandomDataTest {
         double[] densityValues = testInstance.makeDensityTestValues();
         int sampleSize = 1000;
         int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
-        BinomialDistributionImpl distribution = (BinomialDistributionImpl) testInstance.makeDistribution();
+        BinomialDistribution distribution = (BinomialDistribution) testInstance.makeDistribution();
         double[] expectedCounts = new double[length];
         long[] observedCounts = new long[length];
         for (int i = 0; i < length; i++) {



Mime
View raw message