commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1206451 - 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 Sat, 26 Nov 2011 14:58:08 GMT
Author: celestin
Date: Sat Nov 26 14:58:07 2011
New Revision: 1206451

URL: http://svn.apache.org/viewvc?rev=1206451&view=rev
Log:
Merged ZipfDistribution and ZipfDistributionImpl (MATH-711).

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistribution.java
      - copied, changed from r1206052, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java
Removed:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.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/ZipfDistributionTest.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/ZipfDistribution.java
(from r1206052, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistribution.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistribution.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java&r1=1206052&r2=1206451&rev=1206451&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ZipfDistribution.java
Sat Nov 26 14:58:07 2011
@@ -24,12 +24,13 @@ import org.apache.commons.math.exception
 import org.apache.commons.math.util.FastMath;
 
 /**
- * Implementation for the {@link ZipfDistribution}.
+ * Implementation of the Zipf distribution.
  *
+ * @see <a href="http://mathworld.wolfram.com/ZipfDistribution.html">Zipf distribution
(MathWorld)</a>
  * @version $Id$
  */
-public class ZipfDistributionImpl extends AbstractIntegerDistribution
-    implements ZipfDistribution, Serializable {
+public class ZipfDistribution extends AbstractIntegerDistribution
+    implements Serializable {
     /** Serializable version identifier. */
     private static final long serialVersionUID = -140627372283420404L;
     /** Number of elements. */
@@ -46,8 +47,8 @@ public class ZipfDistributionImpl extend
      * @exception NotStrictlyPositiveException if {@code numberOfElements <= 0}
      * or {@code exponent <= 0}.
      */
-    public ZipfDistributionImpl(final int numberOfElements,
-                                final double exponent) {
+    public ZipfDistribution(final int numberOfElements, final double exponent)
+        throws NotStrictlyPositiveException {
         if (numberOfElements <= 0) {
             throw new NotStrictlyPositiveException(LocalizedFormats.DIMENSION,
                                                    numberOfElements);
@@ -62,25 +63,24 @@ public class ZipfDistributionImpl extend
     }
 
     /**
-     * {@inheritDoc}
+     * Get the number of elements (e.g. corpus size) for the distribution.
+     *
+     * @return the number of elements
      */
     public int getNumberOfElements() {
         return numberOfElements;
     }
 
     /**
-     * {@inheritDoc}
+     * Get the exponent characterizing the distribution.
+     *
+     * @return the exponent
      */
     public double getExponent() {
         return exponent;
     }
 
-    /**
-     * The probability mass function {@code P(X = x)} for a Zipf distribution.
-     *
-     * @param x Value at which the probability density function is evaluated.
-     * @return the value of the probability mass function at {@code x}.
-     */
+    /** {@inheritDoc} */
     public double probability(final int x) {
         if (x <= 0 || x > numberOfElements) {
             return 0.0;
@@ -89,13 +89,7 @@ public class ZipfDistributionImpl extend
         return (1.0 / FastMath.pow(x, exponent)) / generalizedHarmonic(numberOfElements,
exponent);
     }
 
-    /**
-     * The probability distribution function {@code P(X <= x)} for a
-     * Zipf distribution.
-     *
-     * @param x Value at which the PDF is evaluated.
-     * @return Zipf distribution function evaluated at {@code x}.
-     */
+    /** {@inheritDoc} */
     @Override
     public double cumulativeProbability(final int x) {
         if (x <= 0) {
@@ -107,25 +101,13 @@ public class ZipfDistributionImpl extend
         return generalizedHarmonic(x, exponent) / generalizedHarmonic(numberOfElements, exponent);
     }
 
-    /**
-     * 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(final double p) {
         return 0;
     }
 
-    /**
-     * 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(final double p) {
         return numberOfElements;
@@ -163,7 +145,7 @@ public class ZipfDistributionImpl extend
     /**
      * {@inheritDoc}
      *
-     * The upper bound of the support is the number of elements
+     * The upper bound of the support is the number of elements.
      *
      * @return upper bound of the support
      */
@@ -175,14 +157,12 @@ public class ZipfDistributionImpl extend
     /**
      * {@inheritDoc}
      *
-     * For number of elements N and exponent s, the mean is
-     * <code>Hs1 / Hs</code> where
+     * For number of elements {@code N} and exponent {@code s}, the mean is
+     * {@code Hs1 / Hs}, where
      * <ul>
-     *  <li><code>Hs1 = generalizedHarmonic(N, s - 1)</code></li>
-     *  <li><code>Hs = generalizedHarmonic(N, s)</code></li>
+     *  <li>{@code Hs1 = generalizedHarmonic(N, s - 1)},</li>
+     *  <li>{@code Hs = generalizedHarmonic(N, s)}.</li>
      * </ul>
-     *
-     * @return {@inheritDoc}
      */
     @Override
     protected double calculateNumericalMean() {
@@ -198,15 +178,13 @@ public class ZipfDistributionImpl extend
     /**
      * {@inheritDoc}
      *
-     * For number of elements N and exponent s, the mean is
-     * <code>(Hs2 / Hs) - (Hs1^2 / Hs^2)</code> where
+     * For number of elements {@code N} and exponent {@code s}, the mean is
+     * {@code (Hs2 / Hs) - (Hs1^2 / Hs^2)}, where
      * <ul>
-     *  <li><code>Hs2 = generalizedHarmonic(N, s - 2)</code></li>
-     *  <li><code>Hs1 = generalizedHarmonic(N, s - 1)</code></li>
-     *  <li><code>Hs = generalizedHarmonic(N, s)</code></li>
+     *  <li>{@code Hs2 = generalizedHarmonic(N, s - 2)},</li>
+     *  <li>{@code Hs1 = generalizedHarmonic(N, s - 1)},</li>
+     *  <li>{@code Hs = generalizedHarmonic(N, s)}.</li>
      * </ul>
-     *
-     * @return {@inheritDoc}
      */
     @Override
     protected double calculateNumericalVariance() {

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=1206451&r1=1206450&r2=1206451&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
Sat Nov 26 14:58:07 2011
@@ -35,7 +35,7 @@ import org.apache.commons.math.distribut
 import org.apache.commons.math.distribution.PascalDistribution;
 import org.apache.commons.math.distribution.TDistribution;
 import org.apache.commons.math.distribution.WeibullDistribution;
-import org.apache.commons.math.distribution.ZipfDistributionImpl;
+import org.apache.commons.math.distribution.ZipfDistribution;
 import org.apache.commons.math.exception.MathInternalError;
 import org.apache.commons.math.exception.NotStrictlyPositiveException;
 import org.apache.commons.math.exception.NumberIsTooLargeException;
@@ -811,7 +811,7 @@ public class RandomDataImpl implements R
     }
 
     /**
-     * Generates a random value from the {@link ZipfDistributionImpl Zipf Distribution}.
+     * Generates a random value from the {@link ZipfDistribution Zipf Distribution}.
      * This implementation uses {@link #nextInversionDeviate(IntegerDistribution) inversion}
      * to generate random values.
      *
@@ -821,7 +821,7 @@ public class RandomDataImpl implements R
      * @since 2.2
      */
     public int nextZipf(int numberOfElements, double exponent) {
-        return nextInversionDeviate(new ZipfDistributionImpl(numberOfElements, exponent));
+        return nextInversionDeviate(new ZipfDistribution(numberOfElements, exponent));
     }
 
     /**

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java?rev=1206451&r1=1206450&r2=1206451&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java
Sat Nov 26 14:58:07 2011
@@ -34,12 +34,12 @@ public class ZipfDistributionTest extend
 
     @Test(expected=NotStrictlyPositiveException.class)
     public void testPreconditions1() {
-        new ZipfDistributionImpl(0, 1);
+        new ZipfDistribution(0, 1);
     }
 
     @Test(expected=NotStrictlyPositiveException.class)
     public void testPreconditions2() {
-        new ZipfDistributionImpl(1, 0);
+        new ZipfDistribution(1, 0);
     }
 
     //-------------- Implementations for abstract methods -----------------------
@@ -47,7 +47,7 @@ public class ZipfDistributionTest extend
     /** Creates the default discrete distribution instance to use in tests. */
     @Override
     public IntegerDistribution makeDistribution() {
-        return new ZipfDistributionImpl(10, 1);
+        return new ZipfDistribution(10, 1);
     }
 
     /** Creates the default probability density test input values */
@@ -93,9 +93,9 @@ public class ZipfDistributionTest extend
     public void testMoments() {
         final double tol = 1e-9;
         ZipfDistribution dist;
-        
-        dist = new ZipfDistributionImpl(2, 0.5);
+
+        dist = new ZipfDistribution(2, 0.5);
         Assert.assertEquals(dist.getNumericalMean(), FastMath.sqrt(2), tol);
-        Assert.assertEquals(dist.getNumericalVariance(), 0.24264068711928521, tol); 
+        Assert.assertEquals(dist.getNumericalVariance(), 0.24264068711928521, 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=1206451&r1=1206450&r2=1206451&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
Sat Nov 26 14:58:07 2011
@@ -41,7 +41,7 @@ import org.apache.commons.math.distribut
 import org.apache.commons.math.distribution.PoissonDistribution;
 import org.apache.commons.math.distribution.TDistribution;
 import org.apache.commons.math.distribution.WeibullDistribution;
-import org.apache.commons.math.distribution.ZipfDistributionImpl;
+import org.apache.commons.math.distribution.ZipfDistribution;
 import org.apache.commons.math.distribution.ZipfDistributionTest;
 import org.apache.commons.math.stat.Frequency;
 import org.apache.commons.math.stat.descriptive.SummaryStatistics;
@@ -1040,7 +1040,7 @@ public class RandomDataTest {
         double[] densityValues = testInstance.makeDensityTestValues();
         int sampleSize = 1000;
         int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
-        ZipfDistributionImpl distribution = (ZipfDistributionImpl) testInstance.makeDistribution();
+        ZipfDistribution distribution = (ZipfDistribution) testInstance.makeDistribution();
         double[] expectedCounts = new double[length];
         long[] observedCounts = new long[length];
         for (int i = 0; i < length; i++) {



Mime
View raw message