PoissonDistribution extends AbstractIntegerDistribution { public double cumulativeProbability(int x) { if (x < 0) { return 0; } if (x == Integer.MAX_VALUE) { return 1; } return Gamma.regularizedGammaQ((double) x + 1, mean, epsilon, maxIterations); } PoissonDistribution(double p);  PoissonDistribution(double p, double epsilon, int maxIterations);  PoissonDistribution(RandomGenerator rng,
                               double p,
                               double epsilon,
                               int maxIterations);  PoissonDistribution(double p, double epsilon);  PoissonDistribution(double p, int maxIterations); double getMean(); double probability(int x); @Override double logProbability(int x); double cumulativeProbability(int x); double normalApproximateProbability(int x); double getNumericalMean(); double getNumericalVariance(); int getSupportLowerBound(); int getSupportUpperBound(); boolean isSupportConnected(); @Override int sample(); static final int DEFAULT_MAX_ITERATIONS; static final double DEFAULT_EPSILON; }
@Test public void testLargeMeanCumulativeProbability() { double mean = 1.0; while (mean <= 10000000.0) { PoissonDistribution dist = new PoissonDistribution(mean); double x = mean * 2.0; double dx = x / 10.0; double p = Double.NaN; double sigma = FastMath.sqrt(mean); while (x >= 0) { try { p = dist.cumulativeProbability((int) x); Assert.assertFalse("NaN cumulative probability returned for mean = " + mean + " x = " + x,Double.isNaN(p)); if (x > mean - 2 * sigma) { Assert.assertTrue("Zero cum probaility returned for mean = " + mean + " x = " + x, p > 0); } } catch (Exception ex) { Assert.fail("mean of " + mean + " and x of " + x + " caused " + ex.getMessage()); } x -= dx; } mean *= 10.0; } }
@Test public void testLargeMeanInverseCumulativeProbability() { double mean = 1.0; while (mean <= 100000.0) { PoissonDistribution dist = new PoissonDistribution(mean); double p = 0.1; double dp = p; while (p < .99) { try { int ret = dist.inverseCumulativeProbability(p); Assert.assertTrue(p <= dist.cumulativeProbability(ret)); Assert.assertTrue(p > dist.cumulativeProbability(ret - 1)); } catch (Exception ex) { Assert.fail("mean of " + mean + " and p of " + p + " caused " + ex.getMessage()); } p += dp; } mean *= 10.0; } }