commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1206053 - 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 Fri, 25 Nov 2011 04:09:07 GMT
Author: celestin
Date: Fri Nov 25 04:09:05 2011
New Revision: 1206053

URL: http://svn.apache.org/viewvc?rev=1206053&view=rev
Log:
Merged CauchyDistribution and CauchyDistributionImpl (MATH-711).

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistribution.java
      - copied, changed from r1206052, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java
Removed:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.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/CauchyDistributionTest.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/CauchyDistribution.java
(from r1206052, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistribution.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistribution.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java&r1=1206052&r2=1206053&rev=1206053&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistribution.java
Fri Nov 25 04:09:05 2011
@@ -25,14 +25,15 @@ import org.apache.commons.math.exception
 import org.apache.commons.math.util.FastMath;
 
 /**
- * Default implementation of
- * {@link org.apache.commons.math.distribution.CauchyDistribution}.
+ * Implementation of the Cauchy distribution.
  *
- * @since 1.1
+ * @see <a href="http://en.wikipedia.org/wiki/Cauchy_distribution">Cauchy distribution
(Wikipedia)</a>
+ * @see <a href="http://mathworld.wolfram.com/CauchyDistribution.html">Cauchy Distribution
(MathWorld)</a>
+ * @since 1.1 (changed to concrete class in 3.0)
  * @version $Id$
  */
-public class CauchyDistributionImpl extends AbstractContinuousDistribution
-    implements CauchyDistribution, Serializable {
+public class CauchyDistribution extends AbstractContinuousDistribution
+    implements Serializable {
     /**
      * Default inverse cumulative probability accuracy.
      * @since 2.1
@@ -48,35 +49,35 @@ public class CauchyDistributionImpl exte
     private final double solverAbsoluteAccuracy;
 
     /**
-     * Creates cauchy distribution with the medain equal to zero and scale
+     * Creates a Cauchy distribution with the median equal to zero and scale
      * equal to one.
      */
-    public CauchyDistributionImpl() {
+    public CauchyDistribution() {
         this(0, 1);
     }
 
     /**
-     * Create a cauchy distribution using the given median and scale.
+     * Creates a Cauchy distribution using the given median and scale.
      *
      * @param median Median for this distribution.
      * @param scale Scale parameter for this distribution.
      */
-    public CauchyDistributionImpl(double median, double scale) {
+    public CauchyDistribution(double median, double scale) {
         this(median, scale, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
     }
 
     /**
-     * Create a cauchy distribution using the given median and scale.
+     * Creates a Cauchy distribution using the given median and scale.
      *
      * @param median Median for this distribution.
      * @param scale Scale parameter for this distribution.
      * @param inverseCumAccuracy Maximum absolute error in inverse
      * cumulative probability estimates
      * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
-     * @throws NotStrictlyPositiveException if {@code s <= 0}.
+     * @throws NotStrictlyPositiveException if {@code scale <= 0}.
      * @since 2.1
      */
-    public CauchyDistributionImpl(double median, double scale,
+    public CauchyDistribution(double median, double scale,
                                   double inverseCumAccuracy) {
         if (scale <= 0) {
             throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale);
@@ -86,30 +87,30 @@ public class CauchyDistributionImpl exte
         solverAbsoluteAccuracy = inverseCumAccuracy;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public double cumulativeProbability(double x) {
         return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI);
     }
 
     /**
-     * {@inheritDoc}
+     * Access the median.
+     *
+     * @return the median for this distribution.
      */
     public double getMedian() {
         return median;
     }
 
     /**
-     * {@inheritDoc}
+     * Access the scale parameter.
+     *
+     * @return the scale parameter for this distribution.
      */
     public double getScale() {
         return scale;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public double density(double x) {
         final double dev = x - median;
         return (1 / FastMath.PI) * (scale / (dev * dev + scale * scale));
@@ -118,8 +119,8 @@ public class CauchyDistributionImpl exte
     /**
      * {@inheritDoc}
      *
-     * It will return {@code Double.NEGATIVE_INFINITY} when {@code p = 0}
-     * and {@code Double.POSITIVE_INFINITY} when {@code p = 1}.
+     * Returns {@code Double.NEGATIVE_INFINITY} when {@code p == 0}
+     * and {@code Double.POSITIVE_INFINITY} when {@code p == 1}.
      */
     @Override
     public double inverseCumulativeProbability(double p) throws OutOfRangeException {
@@ -136,14 +137,7 @@ public class CauchyDistributionImpl exte
         return ret;
     }
 
-    /**
-     * Access the domain value lower bound, based on {@code p}, used to
-     * bracket a CDF root.  This method is used by
-     * {@link #inverseCumulativeProbability(double)} to find critical values.
-     *
-     * @param p Desired probability for the critical value.
-     * @return domain value lower bound, i.e. {@code P(X < 'lower bound') < p}.
-     */
+    /** {@inheritDoc} */
     @Override
     protected double getDomainLowerBound(double p) {
         double ret;
@@ -157,14 +151,7 @@ public class CauchyDistributionImpl exte
         return ret;
     }
 
-    /**
-     * Access the domain value upper bound, based on <code>p</code>, used to
-     * bracket a CDF root.  This method is used by
-     * {@link #inverseCumulativeProbability(double)} to find critical values.
-     *
-     * @param p Desired probability for the critical value.
-     * @return domain value lower bound, i.e. {@code P(X < 'upper bound') > p}.
-     */
+    /** {@inheritDoc} */
     @Override
     protected double getDomainUpperBound(double p) {
         double ret;
@@ -178,14 +165,7 @@ public class CauchyDistributionImpl exte
         return ret;
     }
 
-    /**
-     * Access the initial domain value, based on {@code p}, used to
-     * bracket a CDF root.  This method is used by
-     * {@link #inverseCumulativeProbability(double)} to find critical values.
-     *
-     * @param p Desired probability for the critical value.
-     * @return the initial domain value.
-     */
+    /** {@inheritDoc} */
     @Override
     protected double getInitialDomain(double p) {
         double ret;
@@ -201,13 +181,7 @@ public class CauchyDistributionImpl exte
         return ret;
     }
 
-    /**
-     * Return the absolute accuracy setting of the solver used to estimate
-     * inverse cumulative probabilities.
-     *
-     * @return the solver absolute accuracy
-     * @since 2.1
-     */
+    /** {@inheritDoc} */
     @Override
     protected double getSolverAbsoluteAccuracy() {
         return solverAbsoluteAccuracy;
@@ -263,17 +237,13 @@ public class CauchyDistributionImpl exte
         return Double.NaN;
     }
 
-    /**
-     * {@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=1206053&r1=1206052&r2=1206053&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
Fri Nov 25 04:09:05 2011
@@ -26,7 +26,7 @@ import java.util.Collection;
 
 import org.apache.commons.math.distribution.BetaDistribution;
 import org.apache.commons.math.distribution.BinomialDistribution;
-import org.apache.commons.math.distribution.CauchyDistributionImpl;
+import org.apache.commons.math.distribution.CauchyDistribution;
 import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
 import org.apache.commons.math.distribution.ContinuousDistribution;
 import org.apache.commons.math.distribution.FDistributionImpl;
@@ -627,7 +627,7 @@ public class RandomDataImpl implements R
     }
 
     /**
-     * Generates a random value from the {@link CauchyDistributionImpl Cauchy Distribution}.
+     * Generates a random value from the {@link CauchyDistribution Cauchy Distribution}.
      * This implementation uses {@link #nextInversionDeviate(ContinuousDistribution) inversion}
      * to generate random values.
      *
@@ -637,7 +637,7 @@ public class RandomDataImpl implements R
      * @since 2.2
      */
     public double nextCauchy(double median, double scale) {
-        return nextInversionDeviate(new CauchyDistributionImpl(median, scale));
+        return nextInversionDeviate(new CauchyDistribution(median, scale));
     }
 
     /**

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java?rev=1206053&r1=1206052&r2=1206053&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java
Fri Nov 25 04:09:05 2011
@@ -43,7 +43,7 @@ public class CauchyDistributionTest exte
     /** Creates the default continuous distribution instance to use in tests. */
     @Override
     public CauchyDistribution makeDistribution() {
-        return new CauchyDistributionImpl(1.2, 2.1);
+        return new CauchyDistribution(1.2, 2.1);
     }
 
     /** Creates the default cumulative probability distribution test input values */
@@ -93,13 +93,13 @@ public class CauchyDistributionTest exte
     @Test
     public void testPreconditions() {
         try {
-            new CauchyDistributionImpl(0, 0);
+            new CauchyDistribution(0, 0);
             Assert.fail("Cannot have zero scale");
         } catch (NotStrictlyPositiveException ex) {
             // Expected.
         }
         try {
-            new CauchyDistributionImpl(0, -1);
+            new CauchyDistribution(0, -1);
             Assert.fail("Cannot have negative scale");
         } catch (NotStrictlyPositiveException ex) {
             // Expected.
@@ -109,12 +109,12 @@ public class CauchyDistributionTest exte
     @Test
     public void testMoments() {
         CauchyDistribution dist;
-        
-        dist = new CauchyDistributionImpl(10.2, 0.15);        
+
+        dist = new CauchyDistribution(10.2, 0.15);
         Assert.assertTrue(Double.isNaN(dist.getNumericalMean()));
         Assert.assertTrue(Double.isNaN(dist.getNumericalVariance()));
-        
-        dist = new CauchyDistributionImpl(23.12, 2.12);
+
+        dist = new CauchyDistribution(23.12, 2.12);
         Assert.assertTrue(Double.isNaN(dist.getNumericalMean()));
         Assert.assertTrue(Double.isNaN(dist.getNumericalVariance()));
     }

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=1206053&r1=1206052&r2=1206053&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
Fri Nov 25 04:09:05 2011
@@ -28,7 +28,7 @@ import org.apache.commons.math.TestUtils
 import org.apache.commons.math.distribution.BetaDistribution;
 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.CauchyDistribution;
 import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
 import org.apache.commons.math.distribution.ExponentialDistributionImpl;
 import org.apache.commons.math.distribution.FDistributionImpl;
@@ -872,7 +872,7 @@ public class RandomDataTest {
 
     @Test
     public void testNextCauchy() throws Exception {
-        double[] quartiles = TestUtils.getDistributionQuartiles(new CauchyDistributionImpl(1.2,
2.1));
+        double[] quartiles = TestUtils.getDistributionQuartiles(new CauchyDistribution(1.2,
2.1));
         long[] counts = new long[4];
         randomData.reSeed(1000);
         for (int i = 0; i < 1000; i++) {



Mime
View raw message