You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Sébastien Brisard <se...@m4x.org> on 2011/12/05 09:21:25 UTC

Re: [math] Inconsistencies (bugs) in PascalDistribution?

Hi Mikkel,
>
> No, you are more than welcome to do the patch and I'll review it :-). Thanks!
>
> Cheers, Mikkel.
>
I've committed a correction (r1210359). Could you please review it and
post your comments on the JIRA ticket (MATH-715).
Thanks a lot!
Sébastien


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Inconsistencies (bugs) in PascalDistribution?

Posted by Mikkel Meyer Andersen <mi...@mikl.dk>.
2011/12/5 Sébastien Brisard <se...@m4x.org>:
> Hi Mikkel,
>> It seems like only the test was changed in r1210359 (svn diff -r
>> 1210359). This does _not_ correspond to the log (svn log -r 1210359).
>
> Here is an excerpt of the email sent automatically when I committed
> revision 1210359
>
> ==========BEGIN EXCERPT==========
> Author: celestin
> Date: Mon Dec  5 08:15:38 2011
> New Revision: 1210359
>
> URL: http://svn.apache.org/viewvc?rev=1210359&view=rev
> Log:
> - Corrected expressions for mean and variance in
> distribution.PascalDistribution (MATH-715).
> - Made javadoc more explicit
> - Restored SVN properties to various files in package distribution.
>
> ....................
>
> Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java?rev=1210359&r1=1210358&r2=1210359&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
> (original)
> +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
> Mon Dec  5 08:15:38 2011
> @@ -31,10 +31,25 @@ import org.apache.commons.math.util.Fast
>  * </p>
>  * <p>
>  * There are various ways to express the probability mass and distribution
> - * functions for the Pascal distribution.  The convention employed by the
> - * library is to express these functions in terms of the number of failures in
> - * a Bernoulli experiment
> - * (see <a href="http://en.wikipedia.org/wiki/Negative_binomial_distribution#Waiting_time_in_a_Bernoulli_process">Waiting
> Time in a Bernoulli Process</a>).
> + * functions for the Pascal distribution. The present implementation represents
> + * the distribution of the number of failures before {@code r} successes occur.
> + * This is the convention adopted in e.g.
> + * <a href="http://mathworld.wolfram.com/NegativeBinomialDistribution.html">MathWorld</a>,
> + * but <em>not</em> in
> + * <a href="http://en.wikipedia.org/wiki/Negative_binomial_distribution">Wikipedia</a>.
> + * </p>
> + * <p>
> + * For a random variable {@code X} whose values are distributed
> according to this
> + * distribution, the probability mass function is given by<br/>
> + * {@code P(X = k) = C(k + r - 1, r - 1) * p^r * (1 - p)^k,}<br/>
> + * where {@code r} is the number of successes, {@code p} is the probability of
> + * success, and {@code X} is the total number of failures. {@code C(n, k)} is
> + * the binomial coefficient ({@code n} choose {@code k}). The mean and variance
> + * of {@code X} are<br/>
> + * {@code E(X) = (1 - p) * r / p, var(X) = (1 - p) * r / p^2.}<br/>
> + * Finally, the cumulative distribution function is given by<br/>
> + * {@code P(X <= k) = I(p, r, k + 1)},
> + * where I is the regularized incomplete Beta function.
>  * </p>
>  *
>  * @see <a href="http://en.wikipedia.org/wiki/Negative_binomial_distribution">
> @@ -159,25 +174,24 @@ public class PascalDistribution extends
>     * {@inheritDoc}
>     *
>     * For number of successes {@code r} and probability of success {@code p},
> -     * the mean is {@code (r * p) / (1 - p)}.
> +     * the mean is {@code r * (1 - p) / p}.
>     */
>    public double getNumericalMean() {
>        final double p = getProbabilityOfSuccess();
>        final double r = getNumberOfSuccesses();
> -        return (r * p) / (1 - p);
> +        return (r * (1 - p)) / p;
>    }
>
>    /**
>     * {@inheritDoc}
>     *
>     * For number of successes {@code r} and probability of success {@code p},
> -     * the variance is {@code (r * p) / (1 - p)^2}.
> +     * the variance is {@code r * (1 - p) / p^2}.
>     */
>    public double getNumericalVariance() {
>        final double p = getProbabilityOfSuccess();
>        final double r = getNumberOfSuccesses();
> -        final double pInv = 1 - p;
> -        return (r * p) / (pInv * pInv);
> +        return r * (1 - p) / (p * p);
>    }
>
> ==========END EXCERPT==========
>
> It seems to me that everything (?) is OK?
>
>>
>> It seems like the changes was done in r1210358. Is that true?
>>
> I don't think so (see extract below).
>
> ==========BEGIN EXCERPT==========
>
> Author: sgoeschl
> Date: Mon Dec  5 08:02:46 2011
> New Revision: 1210358
>
> URL: http://svn.apache.org/viewvc?rev=1210358&view=rev
> Log:
> [maven-release-plugin] prepare for next development iteration
>
> Modified:
>   commons/proper/email/trunk/pom.xml
>
> ==========END EXCERPT==========
>
> I don't really understand what is happening. I hope I didn't mess up
> anything this morning. Please keep me posted.
> Sébastien
>
Hi,

Now I looked it through and it looks good to me - and also the SVN
behaves fine again (it could also be mine that acted weird).

Thanks again for fixing this.

Cheers, Mikkel.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Inconsistencies (bugs) in PascalDistribution?

Posted by Sébastien Brisard <se...@m4x.org>.
Hi Mikkel,
> It seems like only the test was changed in r1210359 (svn diff -r
> 1210359). This does _not_ correspond to the log (svn log -r 1210359).

Here is an excerpt of the email sent automatically when I committed
revision 1210359

==========BEGIN EXCERPT==========
Author: celestin
Date: Mon Dec  5 08:15:38 2011
New Revision: 1210359

URL: http://svn.apache.org/viewvc?rev=1210359&view=rev
Log:
- Corrected expressions for mean and variance in
distribution.PascalDistribution (MATH-715).
- Made javadoc more explicit
- Restored SVN properties to various files in package distribution.

....................

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java?rev=1210359&r1=1210358&r2=1210359&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PascalDistribution.java
Mon Dec  5 08:15:38 2011
@@ -31,10 +31,25 @@ import org.apache.commons.math.util.Fast
 * </p>
 * <p>
 * There are various ways to express the probability mass and distribution
- * functions for the Pascal distribution.  The convention employed by the
- * library is to express these functions in terms of the number of failures in
- * a Bernoulli experiment
- * (see <a href="http://en.wikipedia.org/wiki/Negative_binomial_distribution#Waiting_time_in_a_Bernoulli_process">Waiting
Time in a Bernoulli Process</a>).
+ * functions for the Pascal distribution. The present implementation represents
+ * the distribution of the number of failures before {@code r} successes occur.
+ * This is the convention adopted in e.g.
+ * <a href="http://mathworld.wolfram.com/NegativeBinomialDistribution.html">MathWorld</a>,
+ * but <em>not</em> in
+ * <a href="http://en.wikipedia.org/wiki/Negative_binomial_distribution">Wikipedia</a>.
+ * </p>
+ * <p>
+ * For a random variable {@code X} whose values are distributed
according to this
+ * distribution, the probability mass function is given by<br/>
+ * {@code P(X = k) = C(k + r - 1, r - 1) * p^r * (1 - p)^k,}<br/>
+ * where {@code r} is the number of successes, {@code p} is the probability of
+ * success, and {@code X} is the total number of failures. {@code C(n, k)} is
+ * the binomial coefficient ({@code n} choose {@code k}). The mean and variance
+ * of {@code X} are<br/>
+ * {@code E(X) = (1 - p) * r / p, var(X) = (1 - p) * r / p^2.}<br/>
+ * Finally, the cumulative distribution function is given by<br/>
+ * {@code P(X <= k) = I(p, r, k + 1)},
+ * where I is the regularized incomplete Beta function.
 * </p>
 *
 * @see <a href="http://en.wikipedia.org/wiki/Negative_binomial_distribution">
@@ -159,25 +174,24 @@ public class PascalDistribution extends
     * {@inheritDoc}
     *
     * For number of successes {@code r} and probability of success {@code p},
-     * the mean is {@code (r * p) / (1 - p)}.
+     * the mean is {@code r * (1 - p) / p}.
     */
    public double getNumericalMean() {
        final double p = getProbabilityOfSuccess();
        final double r = getNumberOfSuccesses();
-        return (r * p) / (1 - p);
+        return (r * (1 - p)) / p;
    }

    /**
     * {@inheritDoc}
     *
     * For number of successes {@code r} and probability of success {@code p},
-     * the variance is {@code (r * p) / (1 - p)^2}.
+     * the variance is {@code r * (1 - p) / p^2}.
     */
    public double getNumericalVariance() {
        final double p = getProbabilityOfSuccess();
        final double r = getNumberOfSuccesses();
-        final double pInv = 1 - p;
-        return (r * p) / (pInv * pInv);
+        return r * (1 - p) / (p * p);
    }

==========END EXCERPT==========

It seems to me that everything (?) is OK?

>
> It seems like the changes was done in r1210358. Is that true?
>
I don't think so (see extract below).

==========BEGIN EXCERPT==========

Author: sgoeschl
Date: Mon Dec  5 08:02:46 2011
New Revision: 1210358

URL: http://svn.apache.org/viewvc?rev=1210358&view=rev
Log:
[maven-release-plugin] prepare for next development iteration

Modified:
   commons/proper/email/trunk/pom.xml

==========END EXCERPT==========

I don't really understand what is happening. I hope I didn't mess up
anything this morning. Please keep me posted.
Sébastien


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Inconsistencies (bugs) in PascalDistribution?

Posted by Sébastien Brisard <se...@m4x.org>.
Hi Mikkel,
>
> This is not to bash, but merely to try to
> stress the importance of keeping a stringent svn history.
>
> Cheers, Mikkel.
>
Thanks for pointing that out. I have run into numerous problems with
SVN this morning, and, although I'm sure I've committed with a log
(it's actually still recorded in eclipse), I would not be surprised if
this log had gone. I will correct that immediately. Thanks again,
Sébastien


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Inconsistencies (bugs) in PascalDistribution?

Posted by Mikkel Meyer Andersen <mi...@mikl.dk>.
2011/12/5 Sébastien Brisard <se...@m4x.org>:
> Hi Mikkel,
>>
>> No, you are more than welcome to do the patch and I'll review it :-). Thanks!
>>
>> Cheers, Mikkel.
>>
> I've committed a correction (r1210359). Could you please review it and
> post your comments on the JIRA ticket (MATH-715).
> Thanks a lot!
> Sébastien
>
Dear Sébastien,

It seems like only the test was changed in r1210359 (svn diff -r
1210359). This does _not_ correspond to the log (svn log -r 1210359).
It seems like the changes was done in r1210358. Is that true? svn log
is empty for r1210358. This is not to bash, but merely to try to
stress the importance of keeping a stringent svn history.

Cheers, Mikkel.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org