SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
ExtremeValueDist.java
1/*
2 * Class: ExtremeValueDist
3 * Description: Gumbel distribution
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.probdist;
26
27import umontreal.ssj.util.Num;
28import umontreal.ssj.util.RootFinder;
29import umontreal.ssj.functions.MathFunction;
30
50@Deprecated
52 private double alpha;
53 private double lambda;
54
55 private static class Function implements MathFunction {
56 protected int n;
57 protected double mean;
58 protected double[] x;
59
60 public Function(double[] x, int n, double mean) {
61 this.n = n;
62 this.mean = mean;
63 this.x = new double[n];
64
65 System.arraycopy(x, 0, this.x, 0, n);
66 }
67
68 public double evaluate(double lambda) {
69 if (lambda <= 0.0)
70 return 1.0e200;
71 double exp = 0.0;
72 double sumXiExp = 0.0;
73 double sumExp = 0.0;
74
75 for (int i = 0; i < n; i++) {
76 exp = Math.exp(-x[i] * lambda);
77 sumExp += exp;
78 sumXiExp += x[i] * exp;
79 }
80
81 return ((mean - 1.0 / lambda) * sumExp - sumXiExp);
82 }
83 }
84
91 setParams(0.0, 1.0);
92 }
93
99 public ExtremeValueDist(double alpha, double lambda) {
100 setParams(alpha, lambda);
101 }
102
103 public double density(double x) {
104 return density(alpha, lambda, x);
105 }
106
107 public double cdf(double x) {
108 return cdf(alpha, lambda, x);
109 }
110
111 public double barF(double x) {
112 return barF(alpha, lambda, x);
113 }
114
115 public double inverseF(double u) {
116 return inverseF(alpha, lambda, u);
117 }
118
119 public double getMean() {
120 return ExtremeValueDist.getMean(alpha, lambda);
121 }
122
123 public double getVariance() {
124 return ExtremeValueDist.getVariance(alpha, lambda);
125 }
126
127 public double getStandardDeviation() {
128 return ExtremeValueDist.getStandardDeviation(alpha, lambda);
129 }
130
134 public static double density(double alpha, double lambda, double x) {
135 if (lambda <= 0)
136 throw new IllegalArgumentException("lambda <= 0");
137 final double z = lambda * (x - alpha);
138 if (z <= -10.0)
139 return 0.0;
140 double t = Math.exp(-z);
141 return lambda * t * Math.exp(-t);
142 }
143
148 public static double cdf(double alpha, double lambda, double x) {
149 if (lambda <= 0)
150 throw new IllegalArgumentException("lambda <= 0");
151 final double z = lambda * (x - alpha);
152 if (z <= -10.0)
153 return 0.0;
154 if (z >= XBIG)
155 return 1.0;
156 return Math.exp(-Math.exp(-z));
157 }
158
162 public static double barF(double alpha, double lambda, double x) {
163 if (lambda <= 0)
164 throw new IllegalArgumentException("lambda <= 0");
165 final double z = lambda * (x - alpha);
166 if (z <= -10.0)
167 return 1.0;
168 if (z >= XBIGM)
169 return 0.0;
170 return -Math.expm1(-Math.exp(-z));
171 }
172
176 public static double inverseF(double alpha, double lambda, double u) {
177 if (u < 0.0 || u > 1.0)
178 throw new IllegalArgumentException("u not in [0, 1]");
179 if (lambda <= 0)
180 throw new IllegalArgumentException("lambda <= 0");
181 if (u >= 1.0)
182 return Double.POSITIVE_INFINITY;
183 if (u <= 0.0)
184 return Double.NEGATIVE_INFINITY;
185
186 return -Math.log(-Math.log(u)) / lambda + alpha;
187 }
188
209 public static double[] getMLE(double[] x, int n) {
210 if (n <= 0)
211 throw new IllegalArgumentException("n <= 0");
212
213 double parameters[] = new double[2];
214
215 double sum = 0.0;
216 for (int i = 0; i < n; i++)
217 sum += x[i];
218 double mean = sum / (double) n;
219
220 sum = 0.0;
221 for (int i = 0; i < n; i++)
222 sum += (x[i] - mean) * (x[i] - mean);
223 double variance = sum / ((double) n - 1.0);
224
225 double lambda0 = Math.PI / Math.sqrt(6 * variance);
226
227 Function f = new Function(x, n, mean);
228
229 double a;
230 if ((a = lambda0 - 10.0) < 0)
231 a = 1e-15;
232 parameters[1] = RootFinder.brentDekker(a, lambda0 + 10.0, f, 1e-7);
233
234 double sumExp = 0.0;
235 for (int i = 0; i < n; i++)
236 sumExp += Math.exp(-x[i] * parameters[1]);
237 parameters[0] = -Math.log(sumExp / (double) n) / parameters[1];
238
239 return parameters;
240 }
241
245 @Deprecated
246 public static double[] getMaximumLikelihoodEstimate(double[] x, int n) {
247 return getMLE(x, n);
248 }
249
259 public static ExtremeValueDist getInstanceFromMLE(double[] x, int n) {
260 double parameters[] = getMLE(x, n);
261 return new ExtremeValueDist(parameters[0], parameters[1]);
262 }
263
272 public static double getMean(double alpha, double lambda) {
273 if (lambda <= 0.0)
274 throw new IllegalArgumentException("lambda <= 0");
275
276 return (alpha + Num.EULER / lambda);
277 }
278
287 public static double getVariance(double alpha, double lambda) {
288 if (lambda <= 0.0)
289 throw new IllegalArgumentException("lambda <= 0");
290
291 return ((1.0 / 6.0 * Math.PI * Math.PI) * (1.0 / (lambda * lambda)));
292 }
293
300 public static double getStandardDeviation(double alpha, double lambda) {
301 if (lambda <= 0.0)
302 throw new IllegalArgumentException("lambda <= 0");
303
304 return (Math.sqrt(1.0 / 6.0) * Math.PI / lambda);
305 }
306
310 public double getAlpha() {
311 return alpha;
312 }
313
317 public double getLambda() {
318 return lambda;
319 }
320
324 public void setParams(double alpha, double lambda) {
325 if (lambda <= 0)
326 throw new IllegalArgumentException("lambda <= 0");
327 this.alpha = alpha;
328 this.lambda = lambda;
329 }
330
335 public double[] getParams() {
336 double[] retour = { alpha, lambda };
337 return retour;
338 }
339
343 public String toString() {
344 return getClass().getSimpleName() + " : alpha = " + alpha + ", lambda = " + lambda;
345 }
346
347}
Classes implementing continuous distributions should inherit from this base class.
static double inverseF(double alpha, double lambda, double u)
Computes the inverse distribution function.
static double getVariance(double alpha, double lambda)
Computes and returns the variance, , of the extreme value distribution with parameters and .
static double getMean(double alpha, double lambda)
Computes and returns the mean, , of the extreme value distribution with parameters and ,...
double barF(double x)
Returns the complementary distribution function.
static double[] getMaximumLikelihoodEstimate(double[] x, int n)
Same as getMLE.
double cdf(double x)
Returns the distribution function .
static ExtremeValueDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of an extreme value distribution with parameters and estimated using the max...
double getVariance()
Returns the variance.
String toString()
Returns a String containing information about the current distribution.
double getAlpha()
Returns the parameter of this object.
double[] getParams()
Return a table containing the parameters of the current distribution.
double inverseF(double u)
Returns the inverse distribution function .
static double[] getMLE(double[] x, int n)
Estimates the parameters of the extreme value distribution using the maximum likelihood method,...
ExtremeValueDist()
THIS CLASS HAS BEEN REPLACED BY GumbelDist .
static double getStandardDeviation(double alpha, double lambda)
Computes and returns the standard deviation of the extreme value distribution with parameters and .
static double density(double alpha, double lambda, double x)
Computes the density function.
double getStandardDeviation()
Returns the standard deviation.
double getLambda()
Returns the parameter of this object.
ExtremeValueDist(double alpha, double lambda)
THIS CLASS HAS BEEN REPLACED BY GumbelDist .
void setParams(double alpha, double lambda)
Sets the parameters and of this object.
static double barF(double alpha, double lambda, double x)
Computes the complementary distribution function.
double density(double x)
Returns , the density evaluated at .
static double cdf(double alpha, double lambda, double x)
THIS CLASS HAS BEEN REPLACED BY GumbelDist .
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static final double EULER
The Euler-Mascheroni constant.
Definition Num.java:133
This class provides numerical methods to solve non-linear equations.
static double brentDekker(double a, double b, MathFunction f, double tol)
Computes a root of the function in f using the Brent-Dekker method.
This interface should be implemented by classes which represent univariate mathematical functions.