2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.commons.math.distribution;
19
import org.apache.commons.math.MathException;
22
* <code>PoissonDistributionTest</code>
24
* @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
26
public class PoissonDistributionTest extends IntegerDistributionAbstractTest {
29
* Poisson parameter value for the test distribution.
31
private static final double DEFAULT_TEST_POISSON_PARAMETER = 4.0;
37
public PoissonDistributionTest(String name) {
43
* Creates the default discrete distribution instance to use in tests.
46
public IntegerDistribution makeDistribution() {
47
return new PoissonDistributionImpl(DEFAULT_TEST_POISSON_PARAMETER);
51
* Creates the default probability density test input values.
54
public int[] makeDensityTestPoints() {
55
return new int[] { -1, 0, 1, 2, 3, 4, 5, 10, 20};
59
* Creates the default probability density test expected values.
60
* These and all other test values are generated by R, version 1.8.1
63
public double[] makeDensityTestValues() {
64
return new double[] { 0d, 0.0183156388887d, 0.073262555555d,
65
0.14652511111d, 0.195366814813d, 0.195366814813,
66
0.156293451851d, 0.00529247667642d, 8.27746364655e-09};
70
* Creates the default cumulative probability density test input values.
73
public int[] makeCumulativeTestPoints() {
74
return new int[] { -1, 0, 1, 2, 3, 4, 5, 10, 20 };
78
* Creates the default cumulative probability density test expected values.
81
public double[] makeCumulativeTestValues() {
82
return new double[] { 0d, 0.0183156388887d, 0.0915781944437d,
83
0.238103305554d, 0.433470120367d, 0.62883693518,
84
0.78513038703d, 0.99716023388d, 0.999999998077 };
88
* Creates the default inverse cumulative probability test input values.
89
* Increased 3rd and 7th values slightly as computed cumulative
90
* probabilities for corresponding values exceeds the target value (still
94
public double[] makeInverseCumulativeTestPoints() {
95
return new double[] { 0d, 0.018315638889d, 0.0915781944437d,
96
0.238103305554d, 0.433470120367d, 0.62883693518,
97
0.78513038704d, 0.99716023388d, 0.999999998077 };
101
* Creates the default inverse cumulative probability density test expected values.
104
public int[] makeInverseCumulativeTestValues() {
105
return new int[] { -1, 0, 1, 2, 3, 4, 5, 10, 20};
109
* Test the normal approximation of the Poisson distribution by
110
* calculating P(90 ≤ X ≤ 110) for X = Po(100) and
111
* P(9900 ≤ X ≤ 10200) for X = Po(10000)
113
public void testNormalApproximateProbability() throws Exception {
114
PoissonDistribution dist = new PoissonDistributionImpl(100);
115
double result = dist.normalApproximateProbability(110)
116
- dist.normalApproximateProbability(89);
117
assertEquals(0.706281887248, result, 1E-10);
119
result = dist.normalApproximateProbability(10200)
120
- dist.normalApproximateProbability(9899);
121
assertEquals(0.820070051552, result, 1E-10);
125
* Test the degenerate cases of a 0.0 and 1.0 inverse cumulative probability.
128
public void testDegenerateInverseCumulativeProbability() throws Exception {
129
PoissonDistribution dist = new PoissonDistributionImpl(DEFAULT_TEST_POISSON_PARAMETER);
130
assertEquals(Integer.MAX_VALUE, dist.inverseCumulativeProbability(1.0d));
131
assertEquals(-1, dist.inverseCumulativeProbability(0d));
134
public void testMean() {
135
PoissonDistribution dist = new PoissonDistributionImpl(DEFAULT_TEST_POISSON_PARAMETER);
138
fail("negative mean. IllegalArgumentException expected");
139
} catch(IllegalArgumentException ex) {
143
assertEquals(10.0, dist.getMean(), 0.0);
146
public void testLargeMeanCumulativeProbability() {
147
PoissonDistribution dist = new PoissonDistributionImpl(1.0);
149
while (mean <= 10000000.0) {
152
double x = mean * 2.0;
153
double dx = x / 10.0;
156
dist.cumulativeProbability(x);
157
} catch (MathException ex) {
158
fail("mean of " + mean + " and x of " + x + " caused " + ex.getMessage());
167
public void testLargeMeanInverseCumulativeProbability() {
168
PoissonDistribution dist = new PoissonDistributionImpl(1.0);
170
while (mean <= 10000000.0) {
177
dist.inverseCumulativeProbability(p);
178
} catch (MathException ex) {
179
fail("mean of " + mean + " and p of " + p + " caused " + ex.getMessage());
b'\\ No newline at end of file'