1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.distribution.discrete;
23
24 import org.hipparchus.distribution.IntegerDistribution;
25 import org.junit.Assert;
26 import org.junit.Test;
27
28
29
30
31 public class PascalDistributionTest extends IntegerDistributionAbstractTest {
32
33
34 protected double defaultTolerance = 1e-9;
35 @Override
36 public void setUp() {
37 super.setUp();
38 setTolerance(defaultTolerance);
39 }
40
41
42
43
44 @Override
45 public IntegerDistribution makeDistribution() {
46 return new PascalDistribution(10,0.70);
47 }
48
49
50 @Override
51 public int[] makeDensityTestPoints() {
52 return new int[] {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
53 }
54
55
56 @Override
57 public double[] makeDensityTestValues() {
58 return new double[] {0, 0.0282475249, 0.0847425747, 0.139825248255, 0.167790297906, 0.163595540458,
59 0.137420253985, 0.103065190489, 0.070673273478, 0.0450542118422, 0.0270325271053,
60 0.0154085404500, 0.0084046584273};
61 }
62
63
64 @Override
65 public int[] makeCumulativeTestPoints() {
66 return makeDensityTestPoints();
67 }
68
69
70 @Override
71 public double[] makeCumulativeTestValues() {
72 return new double[] {0, 0.0282475249, 0.1129900996, 0.252815347855, 0.420605645761, 0.584201186219,
73 0.721621440204, 0.824686630693, 0.895359904171, 0.940414116013, 0.967446643119,
74 0.982855183569, 0.991259841996};
75 }
76
77
78 @Override
79 public double[] makeInverseCumulativeTestPoints() {
80 return new double[] {0.0, 0.001, 0.010, 0.025, 0.050, 0.100, 0.999,
81 0.990, 0.975, 0.950, 0.900, 1.0};
82 }
83
84
85 @Override
86 public int[] makeInverseCumulativeTestValues() {
87 return new int[] {0, 0, 0, 0, 1, 1, 14, 11, 10, 9, 8, Integer.MAX_VALUE};
88 }
89
90
91
92
93 @Test
94 public void testDegenerate0() {
95 setDistribution(new PascalDistribution(5, 0.0d));
96 setCumulativeTestPoints(new int[] {-1, 0, 1, 5, 10 });
97 setCumulativeTestValues(new double[] {0d, 0d, 0d, 0d, 0d});
98 setDensityTestPoints(new int[] {-1, 0, 1, 10, 11});
99 setDensityTestValues(new double[] {0d, 0d, 0d, 0d, 0d});
100 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
101 setInverseCumulativeTestValues(new int[] {Integer.MAX_VALUE, Integer.MAX_VALUE});
102 verifyDensities();
103 verifyCumulativeProbabilities();
104 verifyInverseCumulativeProbabilities();
105 }
106
107
108 @Test
109 public void testDegenerate1() {
110 setDistribution(new PascalDistribution(5, 1.0d));
111 setCumulativeTestPoints(new int[] {-1, 0, 1, 2, 5, 10 });
112 setCumulativeTestValues(new double[] {0d, 1d, 1d, 1d, 1d, 1d});
113 setDensityTestPoints(new int[] {-1, 0, 1, 2, 5, 10});
114 setDensityTestValues(new double[] {0d, 1d, 0d, 0d, 0d, 0d});
115 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
116 setInverseCumulativeTestValues(new int[] {0, 0});
117 verifyDensities();
118 verifyCumulativeProbabilities();
119 verifyInverseCumulativeProbabilities();
120 }
121
122 @Test
123 public void testMoments() {
124 final double tol = 1e-9;
125 PascalDistribution dist;
126
127 dist = new PascalDistribution(10, 0.5);
128 Assert.assertEquals(dist.getNumericalMean(), ( 10d * 0.5d ) / 0.5d, tol);
129 Assert.assertEquals(dist.getNumericalVariance(), ( 10d * 0.5d ) / (0.5d * 0.5d), tol);
130
131 dist = new PascalDistribution(25, 0.7);
132 Assert.assertEquals(dist.getNumericalMean(), ( 25d * 0.3d ) / 0.7d, tol);
133 Assert.assertEquals(dist.getNumericalVariance(), ( 25d * 0.3d ) / (0.7d * 0.7d), tol);
134 }
135 }