Author: brentworden
Date: Thu Jun  7 06:55:36 2007
New Revision: 545184

URL: http://svn.apache.org/viewvc?view=rev&rev=545184
Log:
Removed dependency on DistributionFactory.  Added settable normal distribution 
field.

Modified:
    
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java

Modified: 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java?view=diff&rev=545184&r1=545183&r2=545184
==============================================================================
--- 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
 (original)
+++ 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
 Thu Jun  7 06:55:36 2007
@@ -33,6 +33,8 @@
     /** Serializable version identifier */
     private static final long serialVersionUID = -3349935121172596109L;
     
+    private NormalDistribution normal;
+    
     /**
      * Holds the Poisson mean for the distribution.
      */
@@ -47,7 +49,22 @@
      * @throws IllegalArgumentException if p ≤ 0
      */
     public PoissonDistributionImpl(double p) {
+        this(p, new NormalDistributionImpl());
+    }
+
+    /**
+     * 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
+     */
+    public PoissonDistributionImpl(double p, NormalDistribution z) {
         super();
+        setNormal(z);
         setMean(p);
     }
 
@@ -74,6 +91,8 @@
                     "The Poisson mean must be positive");
         }
         this.mean = p;
+        normal.setMean(p);
+        normal.setStandardDeviation(Math.sqrt(p));
     }
 
     /**
@@ -122,10 +141,6 @@
      * @throws MathException if an error occurs computing the normal 
approximation
      */
     public double normalApproximateProbability(int x) throws MathException {
-        NormalDistribution normal = DistributionFactory.newInstance()
-                .createNormalDistribution(getMean(),
-                        Math.sqrt(getMean()));
-
         // calculate the probability using half-correction
         return normal.cumulativeProbability(x + 0.5);
     }
@@ -152,6 +167,17 @@
      */
     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
+     */
+    public void setNormal(NormalDistribution value) {
+        normal = value;
     }
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to