You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2010/09/26 01:06:34 UTC

svn commit: r1001331 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/distribution/ test/java/org/apache/commons/math/distribution/

Author: erans
Date: Sat Sep 25 23:06:34 2010
New Revision: 1001331

URL: http://svn.apache.org/viewvc?rev=1001331&view=rev
Log:
MATH-349
Removed deprecated methods.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java?rev=1001331&r1=1001330&r2=1001331&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistribution.java Sat Sep 25 23:06:34 2010
@@ -32,7 +32,6 @@ import org.apache.commons.math.MathExcep
  * @version $Revision$ $Date$
  */
 public interface PoissonDistribution extends IntegerDistribution {
-
     /**
      * Get the mean for the distribution.
      *
@@ -41,18 +40,6 @@ public interface PoissonDistribution ext
     double getMean();
 
     /**
-     * Set the mean for the distribution.
-     * The parameter value must be positive; otherwise an
-     * <code>IllegalArgument</code> is thrown.
-     *
-     * @param p the mean
-     * @throws IllegalArgumentException if p &le; 0
-     * @deprecated as of v2.1
-     */
-    @Deprecated
-    void setMean(double p);
-
-    /**
      * Calculates the Poisson distribution function using a normal approximation.
      *
      * @param x the upper bound, inclusive
@@ -60,5 +47,4 @@ public interface PoissonDistribution ext
      * @throws MathException if an error occurs computing the normal approximation
      */
     double normalApproximateProbability(int x) throws MathException;
-
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java?rev=1001331&r1=1001330&r2=1001331&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java Sat Sep 25 23:06:34 2010
@@ -19,7 +19,7 @@ package org.apache.commons.math.distribu
 import java.io.Serializable;
 
 import org.apache.commons.math.MathException;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
 import org.apache.commons.math.special.Gamma;
 import org.apache.commons.math.util.MathUtils;
@@ -77,7 +77,7 @@ public class PoissonDistributionImpl ext
      * @throws IllegalArgumentException if p &le; 0
      */
     public PoissonDistributionImpl(double p) {
-        this(p, new NormalDistributionImpl());
+        this(p, DEFAULT_EPSILON, DEFAULT_MAX_ITERATIONS);
     }
 
     /**
@@ -90,7 +90,11 @@ public class PoissonDistributionImpl ext
      * @since 2.1
      */
     public PoissonDistributionImpl(double p, double epsilon, int maxIterations) {
-        setMean(p);
+        if (p <= 0) {
+            throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, p);
+        }
+        mean = p;
+        normal = new NormalDistributionImpl(p, FastMath.sqrt(p));
         this.epsilon = epsilon;
         this.maxIterations = maxIterations;
     }
@@ -103,8 +107,7 @@ public class PoissonDistributionImpl ext
      * @since 2.1
      */
     public PoissonDistributionImpl(double p, double epsilon) {
-        setMean(p);
-        this.epsilon = epsilon;
+        this(p, epsilon, DEFAULT_MAX_ITERATIONS);
     }
 
     /**
@@ -115,26 +118,7 @@ public class PoissonDistributionImpl ext
      * @since 2.1
      */
     public PoissonDistributionImpl(double p, int maxIterations) {
-        setMean(p);
-        this.maxIterations = maxIterations;
-    }
-
-
-    /**
-     * Create a new Poisson distribution with the given the mean. The mean value
-     * must be positive; otherwise an <code>IllegalArgument</code> is thrown.
-     *
-     * @param p the Poisson mean
-     * @param z a normal distribution used to compute normal approximations.
-     * @throws IllegalArgumentException if p &le; 0
-     * @since 1.2
-     * @deprecated as of 2.1 (to avoid possibly inconsistent state, the
-     * "NormalDistribution" will be instantiated internally)
-     */
-    @Deprecated
-    public PoissonDistributionImpl(double p, NormalDistribution z) {
-        super();
-        setNormalAndMeanInternal(z, p);
+        this(p, DEFAULT_EPSILON, maxIterations);
     }
 
     /**
@@ -147,38 +131,6 @@ public class PoissonDistributionImpl ext
     }
 
     /**
-     * Set the Poisson mean for the distribution. The mean value must be
-     * positive; otherwise an <code>IllegalArgument</code> is thrown.
-     *
-     * @param p the Poisson mean value
-     * @throws IllegalArgumentException if p &le; 0
-     * @deprecated as of 2.1 (class will become immutable in 3.0)
-     */
-    @Deprecated
-    public void setMean(double p) {
-        setNormalAndMeanInternal(normal, p);
-    }
-    /**
-     * Set the Poisson mean for the distribution. The mean value must be
-     * positive; otherwise an <code>IllegalArgument</code> is thrown.
-     *
-     * @param z the new distribution
-     * @param p the Poisson mean value
-     * @throws IllegalArgumentException if p &le; 0
-     */
-    private void setNormalAndMeanInternal(NormalDistribution z,
-                                          double p) {
-        if (p <= 0) {
-            throw MathRuntimeException.createIllegalArgumentException(
-                    LocalizedFormats.NOT_POSITIVE_POISSON_MEAN, p);
-        }
-        mean = p;
-        normal = z;
-        normal.setMean(p);
-        normal.setStandardDeviation(FastMath.sqrt(p));
-    }
-
-    /**
      * The probability mass function P(X = x) for a Poisson distribution.
      *
      * @param x the value at which the probability density function is
@@ -286,18 +238,4 @@ public class PoissonDistributionImpl ext
     protected int getDomainUpperBound(double p) {
         return Integer.MAX_VALUE;
     }
-
-    /**
-     * Modify the normal distribution used to compute normal approximations. The
-     * caller is responsible for insuring the normal distribution has the proper
-     * parameter settings.
-     *
-     * @param value the new distribution
-     * @since 1.2
-     * @deprecated as of 2.1 (class will become immutable in 3.0)
-     */
-    @Deprecated
-    public void setNormal(NormalDistribution value) {
-        setNormalAndMeanInternal(value, mean);
-    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java?rev=1001331&r1=1001330&r2=1001331&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java Sat Sep 25 23:06:34 2010
@@ -18,6 +18,7 @@ package org.apache.commons.math.distribu
 
 import org.apache.commons.math.MathException;
 import org.apache.commons.math.util.FastMath;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
 
 /**
  * <code>PoissonDistributionTest</code>
@@ -116,7 +117,8 @@ public class PoissonDistributionTest ext
         double result = dist.normalApproximateProbability(110)
                 - dist.normalApproximateProbability(89);
         assertEquals(0.706281887248, result, 1E-10);
-        dist.setMean(10000);
+
+        dist = new PoissonDistributionImpl(10000);
         result = dist.normalApproximateProbability(10200)
         - dist.normalApproximateProbability(9899);
         assertEquals(0.820070051552, result, 1E-10);
@@ -133,22 +135,22 @@ public class PoissonDistributionTest ext
     }
 
     public void testMean() {
-        PoissonDistribution dist = new PoissonDistributionImpl(DEFAULT_TEST_POISSON_PARAMETER);
+        PoissonDistribution dist;
         try {
-            dist.setMean(-1);
-            fail("negative mean.  IllegalArgumentException expected");
-        } catch(IllegalArgumentException ex) {
+            dist = new PoissonDistributionImpl(-1);
+            fail("negative mean: NotStrictlyPositiveException expected");
+        } catch(NotStrictlyPositiveException ex) {
+            // Expected.
         }
 
-        dist.setMean(10.0);
+        dist = new PoissonDistributionImpl(10.0);
         assertEquals(10.0, dist.getMean(), 0.0);
     }
 
     public void testLargeMeanCumulativeProbability() {
-        PoissonDistribution dist = new PoissonDistributionImpl(1.0);
         double mean = 1.0;
         while (mean <= 10000000.0) {
-            dist.setMean(mean);
+            PoissonDistribution dist = new PoissonDistributionImpl(mean);
 
             double x = mean * 2.0;
             double dx = x / 10.0;
@@ -177,13 +179,13 @@ public class PoissonDistributionTest ext
      * JIRA: MATH-282
      */
     public void testCumulativeProbabilitySpecial() throws Exception {
-        PoissonDistribution dist = new PoissonDistributionImpl(1.0);
-        dist.setMean(9120);
+        PoissonDistribution dist;
+        dist = new PoissonDistributionImpl(9120);
         checkProbability(dist, 9075);
         checkProbability(dist, 9102);
-        dist.setMean(5058);
+        dist = new PoissonDistributionImpl(5058);
         checkProbability(dist, 5044);
-        dist.setMean(6986);
+        dist = new PoissonDistributionImpl(6986);
         checkProbability(dist, 6950);
     }
 
@@ -196,10 +198,9 @@ public class PoissonDistributionTest ext
     }
 
     public void testLargeMeanInverseCumulativeProbability() throws Exception {
-        PoissonDistribution dist = new PoissonDistributionImpl(1.0);
         double mean = 1.0;
         while (mean <= 100000.0) { // Extended test value: 1E7.  Reduced to limit run time.
-            dist.setMean(mean);
+            PoissonDistribution dist = new PoissonDistributionImpl(mean);
             double p = 0.1;
             double dp = p;
             while (p < .99) {