25package umontreal.ssj.probdist;
27import umontreal.ssj.util.Num;
28import umontreal.ssj.util.RootFinder;
29import umontreal.ssj.functions.MathFunction;
50 private static class FunctionPlus
implements MathFunction {
53 protected double mean;
57 public FunctionPlus(
double[] y,
int n,
double mean,
double minx) {
64 public double evaluate(
double lam) {
71 for (
int i = 0; i < n; i++) {
72 tem = Math.exp(-(x[i] - minx) * lam);
77 return (mean - 1 / lam) * sum1 - sum2;
81 private static class FunctionMinus
implements MathFunction {
84 protected double mean;
86 protected double xmax;
88 public FunctionMinus(
double[] y,
int n,
double mean,
double xmax) {
95 public double evaluate(
double lam) {
102 for (
int i = 0; i < n; i++) {
103 tem = Math.exp((xmax - x[i]) * lam);
108 return (mean - 1 / lam) * sum1 - sum2;
130 return density(beta, delta, x);
133 public double cdf(
double x) {
134 return cdf(beta, delta, x);
138 return barF(beta, delta, x);
154 return GumbelDist.getStandardDeviation(beta, delta);
160 public static double density(
double beta,
double delta,
double x) {
162 throw new IllegalArgumentException(
"beta = 0");
163 final double z = (x - delta) / beta;
166 double t = Math.exp(-z);
167 return t * Math.exp(-t) / Math.abs(beta);
173 public static double cdf(
double beta,
double delta,
double x) {
175 throw new IllegalArgumentException(
"beta = 0");
176 final double z = (x - delta) / beta;
180 return Math.exp(-Math.exp(-z));
184 return -Math.expm1(-Math.exp(-z));
191 public static double barF(
double beta,
double delta,
double x) {
193 throw new IllegalArgumentException(
"beta = 0");
194 final double z = (x - delta) / beta;
198 return -Math.expm1(-Math.exp(-z));
202 return Math.exp(-Math.exp(-z));
209 public static double inverseF(
double beta,
double delta,
double u) {
210 if (u < 0.0 || u > 1.0)
211 throw new IllegalArgumentException(
"u not in [0, 1]");
213 throw new IllegalArgumentException(
"beta = 0");
215 return Double.POSITIVE_INFINITY;
217 return Double.NEGATIVE_INFINITY;
219 return delta - Math.log(-Math.log(u)) * beta;
221 return delta - Math.log(-Math.log1p(-u)) * beta;
243 public static double[]
getMLE(
double[] x,
int n) {
245 throw new IllegalArgumentException(
"n <= 1");
247 double par[] =
new double[2];
249 double xmin = Double.MAX_VALUE;
251 for (i = 0; i < n; i++) {
256 double mean = sum / (double) n;
259 for (i = 0; i < n; i++)
260 sum += (x[i] - mean) * (x[i] - mean);
261 double variance = sum / (n - 1.0);
263 FunctionPlus func =
new FunctionPlus(x, n, mean, xmin);
265 double lam = 1.0 / (0.7797 * Math.sqrt(variance));
266 final double EPS = 0.02;
267 double a = (1.0 - EPS) * lam - 5.0;
270 double b = (1.0 + EPS) * lam + 5.0;
275 for (i = 0; i < n; i++)
276 sum += Math.exp(-(x[i] - xmin) * lam);
277 par[1] = xmin - Math.log(sum / n) / lam;
291 throw new IllegalArgumentException(
"n <= 1");
294 double par[] =
new double[2];
295 double xmax = -Double.MAX_VALUE;
297 for (i = 0; i < n; i++) {
302 double mean = sum / (double) n;
305 for (i = 0; i < n; i++)
306 sum += (x[i] - mean) * (x[i] - mean);
307 double variance = sum / (n - 1.0);
309 FunctionMinus func =
new FunctionMinus(x, n, mean, xmax);
311 double lam = -1.0 / (0.7797 * Math.sqrt(variance));
312 final double EPS = 0.02;
313 double a = (1.0 + EPS) * lam - 2.0;
314 double b = (1.0 - EPS) * lam + 2.0;
321 for (i = 0; i < n; i++)
322 sum += Math.exp((xmax - x[i]) * lam);
324 par[1] = xmax - Math.log(sum / n) / lam;
339 double parameters[] =
getMLE(x, n);
340 return new GumbelDist(parameters[0], parameters[1]);
351 return new GumbelDist(parameters[0], parameters[1]);
362 public static double getMean(
double beta,
double delta) {
364 throw new IllegalArgumentException(
"beta = 0");
378 throw new IllegalArgumentException(
"beta = 0");
380 return Math.PI * Math.PI * beta * beta / 6.0;
391 throw new IllegalArgumentException(
"beta = 0");
415 throw new IllegalArgumentException(
"beta = 0");
425 double[] retour = { beta, delta };
433 return getClass().getSimpleName() +
" : beta = " + beta +
", delta = " + delta;
Classes implementing continuous distributions should inherit from this base class.
GumbelDist(double beta, double delta)
Constructs a GumbelDist object with parameters = beta and = delta.
double density(double x)
Returns , the density evaluated at .
String toString()
Returns a String containing information about the current distribution.
double getMean()
Returns the mean.
static GumbelDist getInstanceFromMLEmin(double[] x, int n)
Similar to getInstanceFromMLE, but for the case .
GumbelDist()
Constructor for the standard Gumbel distribution with parameters.
void setParams(double beta, double delta)
Sets the parameters and of this object.
double getBeta()
Returns the parameter of this object.
static double[] getMLEmin(double[] x, int n)
Similar to getMLE, but for the case .
static double[] getMLE(double[] x, int n)
Estimates the parameters of the Gumbel distribution, assuming that , and using the maximum likelihoo...
static double barF(double beta, double delta, double x)
Computes and returns the complementary distribution function .
static double cdf(double beta, double delta, double x)
Computes and returns the distribution function.
double getDelta()
Returns the parameter of this object.
double getVariance()
Returns the variance.
double cdf(double x)
Returns the distribution function .
static double inverseF(double beta, double delta, double u)
Computes and returns the inverse distribution function.
double[] getParams()
Return a table containing the parameters of the current distribution.
static GumbelDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of an Gumbel distribution with parameters.
double getStandardDeviation()
Returns the standard deviation.
static double getStandardDeviation(double beta, double delta)
Returns the standard deviation of the Gumbel distribution with parameters and .
static double getVariance(double beta, double delta)
Returns the variance of the Gumbel distribution with parameters and.
static double getMean(double beta, double delta)
Returns the mean, , of the Gumbel distribution with parameters and , where.
double barF(double x)
Returns the complementary distribution function.
double inverseF(double u)
Returns the inverse distribution function .
static double density(double beta, double delta, double x)
Computes and returns the density function.
static final double EULER
The Euler-Mascheroni constant.
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.