You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by br...@apache.org on 2007/06/07 15:55:37 UTC
svn commit: r545184 -
/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
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 ≤ 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: svn commit: r545184 - /jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
Posted by Phil Steitz <ph...@gmail.com>.
On 6/7/07, Martin van den Bemt <ml...@mvdb.net> wrote:
> If the intention is to have a NullPointerException when null is passed, declare it and throw it
> specifically (that way you are in control of the exception). I think every undocumented nullpointer
> exception is a bug.
I would prefer throwing IllegalArgumentException to NPE in this case,
since there is no null dereference. I would also consider making this
a no-op (i.e., leave the NormalDistribution alone if null is passed to
this method). I am fine leaving as is, however.
Phil
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: svn commit: r545184 - /jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
Posted by Martin van den Bemt <ml...@mvdb.net>.
If the intention is to have a NullPointerException when null is passed, declare it and throw it
specifically (that way you are in control of the exception). I think every undocumented nullpointer
exception is a bug.
Mvgr,
Martin
Luc Maisonobe wrote:
> brentworden@apache.org wrote:
>
>> + /**
>> + * 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;
>> }
>
> Should we check for null parameters here and throw a NPE ourselves or
> simply allow null parameters and let the JVM throw the NPE when the
> distribution is used ?
>
> I am fine with the current choice of letting the JVM handle this by
> itself, I only wondered what others think about this.
>
> Luc
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: svn commit: r545184 - /jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
Posted by Luc Maisonobe <Lu...@free.fr>.
brentworden@apache.org wrote:
> + /**
> + * 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;
> }
Should we check for null parameters here and throw a NPE ourselves or
simply allow null parameters and let the JVM throw the NPE when the
distribution is used ?
I am fine with the current choice of letting the JVM handle this by
itself, I only wondered what others think about this.
Luc
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org