commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1205739 - 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 07:07:34 GMT
Author: celestin
Date: Thu Nov 24 07:07:32 2011
New Revision: 1205739

URL: http://svn.apache.org/viewvc?rev=1205739&view=rev
Log:
Merged BetaDistribution and BetaDistributionImpl (MATH-711).

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistribution.java
      - copied, changed from r1205734, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java
Removed:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.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/BetaDistributionTest.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/BetaDistribution.java
(from r1205734, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistribution.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistribution.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java&r1=1205734&r2=1205739&rev=1205739&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistribution.java
Thu Nov 24 07:07:32 2011
@@ -24,18 +24,12 @@ import org.apache.commons.math.util.Fast
 
 /**
  * Implements the Beta distribution.
- * <p>
- * References:
- * <ul>
- * <li><a href="http://en.wikipedia.org/wiki/Beta_distribution">
- * Beta distribution</a></li>
- * </ul>
- * </p>
+ *
+ * @see <a href="http://en.wikipedia.org/wiki/Beta_distribution">Beta distribution</a>
  * @version $Id$
- * @since 2.0
+ * @since 2.0 (changed to concrete class in 3.0)
  */
-public class BetaDistributionImpl
-    extends AbstractContinuousDistribution implements BetaDistribution {
+public class BetaDistribution extends AbstractContinuousDistribution {
     /**
      * Default inverse cumulative probability accuracy.
      * @since 2.1
@@ -64,7 +58,7 @@ public class BetaDistributionImpl
      * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
      * @since 2.1
      */
-    public BetaDistributionImpl(double alpha, double beta, double inverseCumAccuracy) {
+    public BetaDistribution(double alpha, double beta, double inverseCumAccuracy) {
         this.alpha = alpha;
         this.beta = beta;
         z = Double.NaN;
@@ -77,32 +71,36 @@ public class BetaDistributionImpl
      * @param alpha First shape parameter (must be positive).
      * @param beta Second shape parameter (must be positive).
      */
-    public BetaDistributionImpl(double alpha, double beta) {
+    public BetaDistribution(double alpha, double beta) {
         this(alpha, beta, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Access the first shape parameter, {@code alpha}.
+     *
+     * @return the first shape parameter.
+     */
     public double getAlpha() {
         return alpha;
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Access the second shape parameter, {@code beta}.
+     *
+     * @return the second shape parameter.
+     */
     public double getBeta() {
         return beta;
     }
 
-    /**
-     * Recompute the normalization factor.
-     */
+    /** Recompute the normalization factor. */
     private void recomputeZ() {
         if (Double.isNaN(z)) {
             z = Gamma.logGamma(alpha) + Gamma.logGamma(beta) - Gamma.logGamma(alpha + beta);
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public double density(double x) {
         recomputeZ();
         if (x < 0 || x > 1) {
@@ -204,11 +202,8 @@ public class BetaDistributionImpl
     /**
      * {@inheritDoc}
      *
-     * For first shape parameter <code>s1</code> and
-     * second shape parameter <code>s2</code>, the mean is
-     * <code>s1 / (s1 + s2)</code>
-     *
-     * @return {@inheritDoc}
+     * For first shape parameter {@code alpha} and second shape parameter {@code beta}, the
+     * mean is {@code alpha / (alpha + beta)}.
      */
     @Override
     protected double calculateNumericalMean() {
@@ -219,12 +214,9 @@ public class BetaDistributionImpl
     /**
      * {@inheritDoc}
      *
-     * For first shape parameter <code>s1</code> and
-     * second shape parameter <code>s2</code>,
-     * the variance is
-     * <code>[ s1 * s2 ] / [ (s1 + s2)^2 * (s1 + s2 + 1) ]</code>
-     *
-     * @return {@inheritDoc}
+     * For first shape parameter {@code alpha} and second shape parameter
+     * {@code beta}, the variance is
+     * {@code (alpha * beta) / [(alpha + beta)^2 * (alpha + beta + 1)]}.
      */
     @Override
     protected double calculateNumericalVariance() {
@@ -234,17 +226,13 @@ public class BetaDistributionImpl
         return (a * b) / ((alphabetasum * alphabetasum) * (alphabetasum + 1));
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     @Override
     public boolean isSupportLowerBoundInclusive() {
         return false;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     @Override
     public boolean isSupportUpperBoundInclusive() {
         return false;

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=1205739&r1=1205738&r2=1205739&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 07:07:32 2011
@@ -24,7 +24,7 @@ import java.security.NoSuchProviderExcep
 import java.security.SecureRandom;
 import java.util.Collection;
 
-import org.apache.commons.math.distribution.BetaDistributionImpl;
+import org.apache.commons.math.distribution.BetaDistribution;
 import org.apache.commons.math.distribution.BinomialDistributionImpl;
 import org.apache.commons.math.distribution.CauchyDistributionImpl;
 import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
@@ -599,7 +599,7 @@ public class RandomDataImpl implements R
     }
 
     /**
-     * Generates a random value from the {@link BetaDistributionImpl Beta Distribution}.
+     * Generates a random value from the {@link BetaDistribution Beta Distribution}.
      * This implementation uses {@link #nextInversionDeviate(ContinuousDistribution) inversion}
      * to generate random values.
      *
@@ -609,7 +609,7 @@ public class RandomDataImpl implements R
      * @since 2.2
      */
     public double nextBeta(double alpha, double beta) {
-        return nextInversionDeviate(new BetaDistributionImpl(alpha, beta));
+        return nextInversionDeviate(new BetaDistribution(alpha, beta));
     }
 
     /**

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java?rev=1205739&r1=1205738&r2=1205739&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java
Thu Nov 24 07:07:32 2011
@@ -141,7 +141,7 @@ public class BetaDistributionTest {
     }
 
     private void checkCumulative(double alpha, double beta, double[] x, double[] cumes) {
-        BetaDistribution d = new BetaDistributionImpl(alpha, beta);
+        BetaDistribution d = new BetaDistribution(alpha, beta);
         for (int i = 0; i < x.length; i++) {
             Assert.assertEquals(cumes[i], d.cumulativeProbability(x[i]), 1e-8);
         }
@@ -283,7 +283,7 @@ public class BetaDistributionTest {
     }
 
     private void checkDensity(double alpha, double beta, double[] x, double[] expected) {
-        BetaDistribution d = new BetaDistributionImpl(alpha, beta);
+        BetaDistribution d = new BetaDistribution(alpha, beta);
         for (int i = 0; i < x.length; i++) {
             Assert.assertEquals(String.format("density at x=%.1f for alpha=%.1f, beta=%.1f",
x[i], alpha, beta), expected[i], d.density(x[i]), 1e-5);
         }
@@ -293,13 +293,13 @@ public class BetaDistributionTest {
     public void testMoments() {
         final double tol = 1e-9;
         BetaDistribution dist;
-        
-        dist = new BetaDistributionImpl(1, 1);
+
+        dist = new BetaDistribution(1, 1);
         Assert.assertEquals(dist.getNumericalMean(), 0.5, tol);
-        Assert.assertEquals(dist.getNumericalVariance(), 1.0 / 12.0, tol); 
-        
-        dist = new BetaDistributionImpl(2, 5);
+        Assert.assertEquals(dist.getNumericalVariance(), 1.0 / 12.0, tol);
+
+        dist = new BetaDistribution(2, 5);
         Assert.assertEquals(dist.getNumericalMean(), 2.0 / 7.0, tol);
-        Assert.assertEquals(dist.getNumericalVariance(), 10.0 / (49.0 * 8.0), tol); 
+        Assert.assertEquals(dist.getNumericalVariance(), 10.0 / (49.0 * 8.0), 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=1205739&r1=1205738&r2=1205739&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 07:07:32 2011
@@ -25,7 +25,7 @@ import java.util.List;
 import org.apache.commons.math.Retry;
 import org.apache.commons.math.RetryRunner;
 import org.apache.commons.math.TestUtils;
-import org.apache.commons.math.distribution.BetaDistributionImpl;
+import org.apache.commons.math.distribution.BetaDistribution;
 import org.apache.commons.math.distribution.BinomialDistributionImpl;
 import org.apache.commons.math.distribution.BinomialDistributionTest;
 import org.apache.commons.math.distribution.CauchyDistributionImpl;
@@ -846,7 +846,7 @@ public class RandomDataTest {
         }
         // Reseed again so the inversion generator gets the same sequence
         randomData.reSeed(100);
-        BetaDistributionImpl betaDistribution = new BetaDistributionImpl(2, 4);
+        BetaDistribution betaDistribution = new BetaDistribution(2, 4);
         /*
          *  Generate a sequence of deviates using inversion - the distribution function
          *  evaluated at the random value from the distribution should match the uniform
@@ -860,7 +860,7 @@ public class RandomDataTest {
 
     @Test
     public void testNextBeta() throws Exception {
-        double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistributionImpl(2,5));
+        double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5));
         long[] counts = new long[4];
         randomData.reSeed(1000);
         for (int i = 0; i < 1000; i++) {



Mime
View raw message