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.continuous;
23
24 import org.hipparchus.exception.LocalizedCoreFormats;
25 import org.hipparchus.exception.MathIllegalArgumentException;
26 import org.hipparchus.util.FastMath;
27 import org.hipparchus.util.MathUtils;
28
29
30
31
32
33
34
35 public class GumbelDistribution extends AbstractRealDistribution {
36
37
38 private static final long serialVersionUID = 20141003L;
39
40
41
42
43
44
45 private static final double EULER = FastMath.PI / (2 * FastMath.E);
46
47
48 private final double mu;
49
50 private final double beta;
51
52
53
54
55
56
57
58
59 public GumbelDistribution(double mu, double beta)
60 throws MathIllegalArgumentException {
61 if (beta <= 0) {
62 throw new MathIllegalArgumentException(LocalizedCoreFormats.SCALE, beta);
63 }
64
65 this.beta = beta;
66 this.mu = mu;
67 }
68
69
70
71
72
73
74 public double getLocation() {
75 return mu;
76 }
77
78
79
80
81
82
83 public double getScale() {
84 return beta;
85 }
86
87
88 @Override
89 public double density(double x) {
90 final double z = (x - mu) / beta;
91 final double t = FastMath.exp(-z);
92 return FastMath.exp(-z - t) / beta;
93 }
94
95
96 @Override
97 public double cumulativeProbability(double x) {
98 final double z = (x - mu) / beta;
99 return FastMath.exp(-FastMath.exp(-z));
100 }
101
102
103 @Override
104 public double inverseCumulativeProbability(double p) throws MathIllegalArgumentException {
105 MathUtils.checkRangeInclusive(p, 0, 1);
106
107 if (p == 0) {
108 return Double.NEGATIVE_INFINITY;
109 } else if (p == 1) {
110 return Double.POSITIVE_INFINITY;
111 }
112 return mu - FastMath.log(-FastMath.log(p)) * beta;
113 }
114
115
116 @Override
117 public double getNumericalMean() {
118 return mu + EULER * beta;
119 }
120
121
122 @Override
123 public double getNumericalVariance() {
124 return (MathUtils.PI_SQUARED) / 6.0 * (beta * beta);
125 }
126
127
128 @Override
129 public double getSupportLowerBound() {
130 return Double.NEGATIVE_INFINITY;
131 }
132
133
134 @Override
135 public double getSupportUpperBound() {
136 return Double.POSITIVE_INFINITY;
137 }
138
139
140 @Override
141 public boolean isSupportConnected() {
142 return true;
143 }
144
145 }