1 16 package org.apache.commons.math.distribution; 17 18 23 public class PoissonDistributionTest extends IntegerDistributionAbstractTest { 24 25 28 private static final double DEFAULT_TEST_POISSON_PARAMETER = 4.0; 29 30 34 public PoissonDistributionTest(String name) { 35 super(name); 36 setTolerance(1e-12); 37 } 38 39 42 public IntegerDistribution makeDistribution() { 43 return DistributionFactory.newInstance().createPoissonDistribution 44 (DEFAULT_TEST_POISSON_PARAMETER); 45 } 46 47 50 public int[] makeDensityTestPoints() { 51 return new int[] { -1, 0, 1, 2, 3, 4, 5, 10, 20}; 52 } 53 54 58 public double[] makeDensityTestValues() { 59 return new double[] { 0d, 0.0183156388887d, 0.073262555555d, 60 0.14652511111d, 0.195366814813d, 0.195366814813, 61 0.156293451851d, 0.00529247667642d, 8.27746364655e-09}; 62 } 63 64 67 public int[] makeCumulativeTestPoints() { 68 return new int[] { -1, 0, 1, 2, 3, 4, 5, 10, 20 }; 69 } 70 71 74 public double[] makeCumulativeTestValues() { 75 return new double[] { 0d, 0.0183156388887d, 0.0915781944437d, 76 0.238103305554d, 0.433470120367d, 0.62883693518, 77 0.78513038703d, 0.99716023388d, 0.999999998077 }; 78 } 79 80 86 public double[] makeInverseCumulativeTestPoints() { 87 return new double[] { 0d, 0.018315638889d, 0.0915781944437d, 88 0.238103305554d, 0.433470120367d, 0.62883693518, 89 0.78513038704d, 0.99716023388d, 0.999999998077 }; 90 } 91 92 95 public int[] makeInverseCumulativeTestValues() { 96 return new int[] { -1, 0, 1, 2, 3, 4, 5, 10, 20}; 97 } 98 99 104 public void testNormalApproximateProbability() throws Exception { 105 PoissonDistribution dist = DistributionFactory.newInstance().createPoissonDistribution(100); 106 double result = dist.normalApproximateProbability(110) 107 - dist.normalApproximateProbability(89); 108 assertEquals(0.706281887248, result, 1E-10); 109 dist.setMean(10000); 110 result = dist.normalApproximateProbability(10200) 111 - dist.normalApproximateProbability(9899); 112 assertEquals(0.820070051552, result, 1E-10); 113 } 114 115 119 public void testDegenerateInverseCumulativeProbability() throws Exception { 120 PoissonDistribution dist = DistributionFactory.newInstance().createPoissonDistribution(DEFAULT_TEST_POISSON_PARAMETER); 121 assertEquals(Integer.MAX_VALUE, dist.inverseCumulativeProbability(1.0d)); 122 assertEquals(-1, dist.inverseCumulativeProbability(0d)); 123 } 124 125 public void testMean() { 126 PoissonDistribution dist = DistributionFactory.newInstance().createPoissonDistribution(DEFAULT_TEST_POISSON_PARAMETER); 127 try { 128 dist.setMean(-1); 129 fail("negative mean. IllegalArgumentException expected"); 130 } catch(IllegalArgumentException ex) { 131 } 132 133 dist.setMean(10.0); 134 assertEquals(10.0, dist.getMean(), 0.0); 135 } 136 } | Popular Tags |