Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-1056

Small error in PoissonDistribution.nextPoisson() algorithm

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.2
    • 3.3
    • None
    • None

    Description

      Here's a tiny bug I noticed via static inspection, since it flagged the integer division. PoissonDistribution.java:325 says:

      final double a1 = FastMath.sqrt(FastMath.PI * twolpd) * FastMath.exp(1 / 8 * lambda);
      

      The "1 / 8 * lambda" is evidently incorrect, since this will always evaluate to 0. I rechecked the original algorithm (http://luc.devroye.org/devroye-poisson.pdf) and it should instead be:

      final double a1 = FastMath.sqrt(FastMath.PI * twolpd) * FastMath.exp(1 / (8 * lambda));
      

      (lambda is a double so there is no int division issue.) This matches a later expression.

      I'm not sure how to evaluate the effect of the bug. Better to be correct of course; it may never have made much practical difference.

      Attachments

        1. MATH-1056.patch
          1 kB
          Sean R. Owen

        Activity

          People

            Unassigned Unassigned
            srowen Sean R. Owen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: