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

Small error in PoissonDistribution.nextPoisson() algorithm

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2
    • Fix Version/s: 3.3
    • Labels:
      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

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              srowen Sean Owen
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: