1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.hipparchus.distribution.discrete;
24
25 import org.hipparchus.distribution.IntegerDistribution;
26 import org.hipparchus.exception.MathIllegalArgumentException;
27 import org.hipparchus.util.FastMath;
28 import org.junit.Assert;
29 import org.junit.Test;
30
31
32
33
34 public class ZipfDistributionTest extends IntegerDistributionAbstractTest {
35
36
37
38
39 public ZipfDistributionTest() {
40 setTolerance(1e-12);
41 }
42
43 @Test(expected=MathIllegalArgumentException.class)
44 public void testPreconditions1() {
45 new ZipfDistribution(0, 1);
46 }
47
48 @Test(expected=MathIllegalArgumentException.class)
49 public void testPreconditions2() {
50 new ZipfDistribution(1, 0);
51 }
52
53
54
55
56 @Override
57 public IntegerDistribution makeDistribution() {
58 return new ZipfDistribution(10, 1);
59 }
60
61
62 @Override
63 public int[] makeDensityTestPoints() {
64 return new int[] {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
65 }
66
67
68
69
70
71 @Override
72 public double[] makeDensityTestValues() {
73 return new double[] {0d, 0d, 0.341417152147, 0.170708576074, 0.113805717382, 0.0853542880369, 0.0682834304295,
74 0.0569028586912, 0.0487738788782, 0.0426771440184, 0.0379352391275, 0.0341417152147, 0};
75 }
76
77
78
79
80
81 @Override
82 public double[] makeLogDensityTestValues() {
83 return new double[] {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY,
84 -1.07465022926458, -1.76779740982453, -2.17326251793269, -2.46094459038447,
85 -2.68408814169868, -2.86640969849264, -3.0205603783199, -3.15409177094442,
86 -3.2718748066008, -3.37723532225863, Double.NEGATIVE_INFINITY};
87 }
88
89
90 @Override
91 public int[] makeCumulativeTestPoints() {
92 return makeDensityTestPoints();
93 }
94
95
96 @Override
97 public double[] makeCumulativeTestValues() {
98 return new double[] {0, 0, 0.341417152147, 0.512125728221, 0.625931445604, 0.71128573364,
99 0.77956916407, 0.836472022761, 0.885245901639, 0.927923045658, 0.965858284785, 1d, 1d};
100 }
101
102
103 @Override
104 public double[] makeInverseCumulativeTestPoints() {
105 return new double[] {0d, 0.001d, 0.010d, 0.025d, 0.050d, 0.3413d, 0.3415d, 0.999d,
106 0.990d, 0.975d, 0.950d, 0.900d, 1d};
107 }
108
109
110 @Override
111 public int[] makeInverseCumulativeTestValues() {
112 return new int[] {1, 1, 1, 1, 1, 1, 2, 10, 10, 10, 9, 8, 10};
113 }
114
115 @Test
116 public void testMoments() {
117 final double tol = 1e-9;
118 ZipfDistribution dist;
119
120 dist = new ZipfDistribution(2, 0.5);
121 Assert.assertEquals(dist.getNumericalMean(), FastMath.sqrt(2), tol);
122 Assert.assertEquals(dist.getNumericalVariance(), 0.24264068711928521, tol);
123 }
124
125 }