commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1206060 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/distribution/ main/java/org/apache/commons/math/random/ main/java/org/apache/commons/math/stat/inference/ test/java/org/apache/commons/math/distribution/ test/j...
Date Fri, 25 Nov 2011 05:17:00 GMT
Author: celestin
Date: Fri Nov 25 05:16:56 2011
New Revision: 1206060

URL: http://svn.apache.org/viewvc?rev=1206060&view=rev
Log:
Merged ChiSquaredDistribution and ChiSquaredDistributionImpl (MATH-711).

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java
      - copied, changed from r1206052, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java
Removed:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.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/ChiSquaredDistribution.java
(from r1206052, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java&r1=1206052&r2=1206060&rev=1206060&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java
Fri Nov 25 05:16:56 2011
@@ -20,13 +20,15 @@ import java.io.Serializable;
 
 
 /**
- * The default implementation of {@link ChiSquaredDistribution}
+ * Implementation of the chi-squared distribution.
  *
+ * @see <a href="http://en.wikipedia.org/wiki/Chi-squared_distribution">Chi-squared
distribution (Wikipedia)</a>
+ * @see <a href="http://mathworld.wolfram.com/Chi-SquaredDistribution.html">Chi-squared
Distribution (MathWorld)</a>
  * @version $Id$
  */
-public class ChiSquaredDistributionImpl
+public class ChiSquaredDistribution
     extends AbstractContinuousDistribution
-    implements ChiSquaredDistribution, Serializable {
+    implements Serializable {
     /**
      * Default inverse cumulative probability accuracy
      * @since 2.1
@@ -44,7 +46,7 @@ public class ChiSquaredDistributionImpl
      *
      * @param degreesOfFreedom Degrees of freedom.
      */
-    public ChiSquaredDistributionImpl(double degreesOfFreedom) {
+    public ChiSquaredDistribution(double degreesOfFreedom) {
         this(degreesOfFreedom, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
     }
 
@@ -58,29 +60,27 @@ public class ChiSquaredDistributionImpl
      * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
      * @since 2.1
      */
-    public ChiSquaredDistributionImpl(double degreesOfFreedom,
+    public ChiSquaredDistribution(double degreesOfFreedom,
                                       double inverseCumAccuracy) {
         gamma = new GammaDistributionImpl(degreesOfFreedom / 2, 2);
         solverAbsoluteAccuracy = inverseCumAccuracy;
     }
 
     /**
-     * {@inheritDoc}
+     * Access the number of degrees of freedom.
+     *
+     * @return the degrees of freedom.
      */
     public double getDegreesOfFreedom() {
         return gamma.getAlpha() * 2.0;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public double density(double x) {
         return gamma.density(x);
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public double cumulativeProbability(double x)  {
         return gamma.cumulativeProbability(x);
     }
@@ -88,8 +88,8 @@ public class ChiSquaredDistributionImpl
     /**
      * {@inheritDoc}
      *
-     * It will return {@code 0} when {@code p = 0} and
-     * {@code Double.POSITIVE_INFINITY} when {@code p = 1}.
+     * Returns {@code 0} when {@code p == 0} and
+     * {@code Double.POSITIVE_INFINITY} when {@code p == 1}.
      */
     @Override
     public double inverseCumulativeProbability(final double p) {
@@ -102,27 +102,13 @@ public class ChiSquaredDistributionImpl
         return super.inverseCumulativeProbability(p);
     }
 
-    /**
-     * 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 the 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) {
         return Double.MIN_VALUE * gamma.getBeta();
     }
 
-    /**
-     * Access the domain value upper 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 upper bound, i.e. {@code P(X < 'upper bound') > p}.
-     */
+    /** {@inheritDoc} */
     @Override
     protected double getDomainUpperBound(double p) {
         // NOTE: chi squared is skewed to the left
@@ -141,14 +127,7 @@ public class ChiSquaredDistributionImpl
         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) {
         // NOTE: chi squared is skewed to the left
@@ -167,13 +146,7 @@ public class ChiSquaredDistributionImpl
         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;
@@ -208,10 +181,7 @@ public class ChiSquaredDistributionImpl
     /**
      * {@inheritDoc}
      *
-     * For <code>k</code> degrees of freedom, the mean is
-     * <code>k</code>
-     *
-     * @return {@inheritDoc}
+     * For {@code k} degrees of freedom, the mean is {@code k}.
      */
     @Override
     protected double calculateNumericalMean() {
@@ -221,8 +191,7 @@ public class ChiSquaredDistributionImpl
     /**
      * {@inheritDoc}
      *
-     * For <code>k</code> degrees of freedom, the variance is
-     * <code>2 * k</code>
+     * For {@code k} degrees of freedom, the variance is {@code 2 * k}.
      *
      * @return {@inheritDoc}
      */
@@ -231,17 +200,13 @@ public class ChiSquaredDistributionImpl
         return 2*getDegreesOfFreedom();
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     @Override
     public boolean isSupportLowerBoundInclusive() {
         return true;
     }
 
-    /**
-     * {@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=1206060&r1=1206059&r2=1206060&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 05:16:56 2011
@@ -27,7 +27,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.CauchyDistribution;
-import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
+import org.apache.commons.math.distribution.ChiSquaredDistribution;
 import org.apache.commons.math.distribution.ContinuousDistribution;
 import org.apache.commons.math.distribution.FDistributionImpl;
 import org.apache.commons.math.distribution.HypergeometricDistributionImpl;
@@ -641,7 +641,7 @@ public class RandomDataImpl implements R
     }
 
     /**
-     * Generates a random value from the {@link ChiSquaredDistributionImpl ChiSquare Distribution}.
+     * Generates a random value from the {@link ChiSquaredDistribution ChiSquare Distribution}.
      * This implementation uses {@link #nextInversionDeviate(ContinuousDistribution) inversion}
      * to generate random values.
      *
@@ -650,7 +650,7 @@ public class RandomDataImpl implements R
      * @since 2.2
      */
     public double nextChiSquare(double df) {
-        return nextInversionDeviate(new ChiSquaredDistributionImpl(df));
+        return nextInversionDeviate(new ChiSquaredDistribution(df));
     }
 
     /**

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java?rev=1206060&r1=1206059&r2=1206060&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
Fri Nov 25 05:16:56 2011
@@ -22,7 +22,6 @@ import org.apache.commons.math.exception
 import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.exception.MathIllegalArgumentException;
 import org.apache.commons.math.distribution.ChiSquaredDistribution;
-import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
 import org.apache.commons.math.exception.util.LocalizedFormats;
 import org.apache.commons.math.util.FastMath;
 import org.apache.commons.math.util.MathUtils;
@@ -102,7 +101,7 @@ public class ChiSquareTestImpl implement
     public double chiSquareTest(double[] expected, long[] observed)
         throws MathException {
         ChiSquaredDistribution distribution =
-            new ChiSquaredDistributionImpl(expected.length - 1.0);
+            new ChiSquaredDistribution(expected.length - 1.0);
         return 1.0 - distribution.cumulativeProbability(
             chiSquare(expected, observed));
     }
@@ -176,7 +175,8 @@ public class ChiSquareTestImpl implement
     throws MathException {
         checkArray(counts);
         double df = ((double) counts.length -1) * ((double) counts[0].length - 1);
-        ChiSquaredDistribution distribution = new ChiSquaredDistributionImpl(df);
+        ChiSquaredDistribution distribution;
+        distribution = new ChiSquaredDistribution(df);
         return 1 - distribution.cumulativeProbability(chiSquare(counts));
     }
 
@@ -270,8 +270,8 @@ public class ChiSquareTestImpl implement
      */
     public double chiSquareTestDataSetsComparison(long[] observed1, long[] observed2)
         throws MathException {
-        ChiSquaredDistribution distribution =
-            new ChiSquaredDistributionImpl((double) observed1.length - 1);
+        ChiSquaredDistribution distribution;
+        distribution = new ChiSquaredDistribution((double) observed1.length - 1);
         return 1 - distribution.cumulativeProbability(
                 chiSquareDataSetsComparison(observed1, observed2));
     }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java?rev=1206060&r1=1206059&r2=1206060&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java
Fri Nov 25 05:16:56 2011
@@ -34,7 +34,7 @@ public class ChiSquareDistributionTest e
     /** Creates the default continuous distribution instance to use in tests. */
     @Override
     public ChiSquaredDistribution makeDistribution() {
-        return new ChiSquaredDistributionImpl(5.0);
+        return new ChiSquaredDistribution(5.0);
     }
 
     /** Creates the default cumulative probability distribution test input values */
@@ -84,7 +84,7 @@ public class ChiSquareDistributionTest e
 
     @Test
     public void testSmallDf() throws Exception {
-        setDistribution(new ChiSquaredDistributionImpl(0.1d));
+        setDistribution(new ChiSquaredDistribution(0.1d));
         setTolerance(1E-4);
         // quantiles computed using R version 1.8.1 (linux version)
         setCumulativeTestPoints(new double[] {1.168926E-60, 1.168926E-40, 1.063132E-32,
@@ -116,7 +116,7 @@ public class ChiSquareDistributionTest e
     }
 
     private void checkDensity(double df, double[] x, double[] expected) {
-        ChiSquaredDistribution d = new ChiSquaredDistributionImpl(df);
+        ChiSquaredDistribution d = new ChiSquaredDistribution(df);
         for (int i = 0; i < x.length; i++) {
             Assert.assertEquals(expected[i], d.density(x[i]), 1e-5);
         }
@@ -126,12 +126,12 @@ public class ChiSquareDistributionTest e
     public void testMoments() {
         final double tol = 1e-9;
         ChiSquaredDistribution dist;
-        
-        dist = new ChiSquaredDistributionImpl(1500);
+
+        dist = new ChiSquaredDistribution(1500);
         Assert.assertEquals(dist.getNumericalMean(), 1500, tol);
-        Assert.assertEquals(dist.getNumericalVariance(), 3000, tol); 
-        
-        dist = new ChiSquaredDistributionImpl(1.12);
+        Assert.assertEquals(dist.getNumericalVariance(), 3000, tol);
+
+        dist = new ChiSquaredDistribution(1.12);
         Assert.assertEquals(dist.getNumericalMean(), 1.12, tol);
         Assert.assertEquals(dist.getNumericalVariance(), 2.24, 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=1206060&r1=1206059&r2=1206060&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 05:16:56 2011
@@ -29,7 +29,7 @@ import org.apache.commons.math.distribut
 import org.apache.commons.math.distribution.BinomialDistribution;
 import org.apache.commons.math.distribution.BinomialDistributionTest;
 import org.apache.commons.math.distribution.CauchyDistribution;
-import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
+import org.apache.commons.math.distribution.ChiSquaredDistribution;
 import org.apache.commons.math.distribution.ExponentialDistributionImpl;
 import org.apache.commons.math.distribution.FDistributionImpl;
 import org.apache.commons.math.distribution.GammaDistributionImpl;
@@ -884,7 +884,7 @@ public class RandomDataTest {
 
     @Test
     public void testNextChiSquare() throws Exception {
-        double[] quartiles = TestUtils.getDistributionQuartiles(new ChiSquaredDistributionImpl(12));
+        double[] quartiles = TestUtils.getDistributionQuartiles(new ChiSquaredDistribution(12));
         long[] counts = new long[4];
         randomData.reSeed(1000);
         for (int i = 0; i < 1000; i++) {



Mime
View raw message