/* *
* Title:
* Description:
* Copyright: Copyright (c)
* Company:
* @author
* @version 1.0
*/
package umontreal.iro.lecuyer.probdist;
import umontreal.iro.lecuyer.util.Num;
import umontreal.iro.lecuyer.util.RootFinder;
import umontreal.iro.lecuyer.functions.MathFunction;
@Deprecated
/**
* This class has been replaced by {@link GumbelDist}.
*
*
* Extends the class {@link ContinuousDistribution} for
* the extreme value (or Gumbel) distribution, with location parameter
* α and scale parameter
* λ > 0.
* It has density
*
*
*
* f (x) = λe-λ(x-α)e-e-λ(x-α), for - ∞ < x < ∞.
*
* distribution function
*
*
*
* F(x) = e-e-λ(x-α) for - ∞ < x < ∞,
*
* and inverse distribution function
*
*
*
* F-1(u) = - ln(- ln(u))/λ + α, for 0 <= u <= 1.
*
*
*/
public class ExtremeValueDist extends ContinuousDistribution {
private double alpha;
private double lambda;
private static class Function implements MathFunction {
protected int n;
protected double mean;
protected double[] x;
public Function (double[] x, int n, double mean) {
this.n = n;
this.mean = mean;
this.x = new double[n];
System.arraycopy(x, 0, this.x, 0, n);
}
public double evaluate (double lambda) {
if (lambda <= 0.0) return 1.0e200;
double exp = 0.0;
double sumXiExp = 0.0;
double sumExp = 0.0;
for (int i = 0; i < n; i++)
{
exp = Math.exp (-x[i] * lambda);
sumExp += exp;
sumXiExp += x[i] * exp;
}
return ((mean - 1.0 / lambda) * sumExp - sumXiExp);
}
}
/**
* THIS CLASS HAS BEEN REPLACED BY {@link GumbelDist}.
* Constructs a ExtremeValueDist object with parameters
* α = 0 and λ = 1.
*
*/
public ExtremeValueDist() {
setParams (0.0, 1.0);
}
/**
* THIS CLASS HAS BEEN REPLACED BY {@link GumbelDist}.
* Constructs a ExtremeValueDist object with parameters
* α = alpha and λ = lambda.
*
*/
public ExtremeValueDist (double alpha, double lambda) {
setParams (alpha, lambda);
}
public double density (double x) {
return density (alpha, lambda, x);
}
public double cdf (double x) {
return cdf (alpha, lambda, x);
}
public double barF (double x) {
return barF (alpha, lambda, x);
}
public double inverseF (double u) {
return inverseF (alpha, lambda, u);
}
public double getMean() {
return ExtremeValueDist.getMean (alpha, lambda);
}
public double getVariance() {
return ExtremeValueDist.getVariance (alpha, lambda);
}
public double getStandardDeviation() {
return ExtremeValueDist.getStandardDeviation (alpha, lambda);
}
/**
* Computes the density function.
*
*/
public static double density (double alpha, double lambda, double x) {
if (lambda <= 0)
throw new IllegalArgumentException ("lambda <= 0");
final double z = lambda*(x - alpha);
if (z <= -10.0)
return 0.0;
double t = Math.exp (-z);
return lambda * t * Math.exp (-t);
}
/**
* THIS CLASS HAS BEEN REPLACED BY {@link GumbelDist}.
* Computes the distribution function.
*
*/
public static double cdf (double alpha, double lambda, double x) {
if (lambda <= 0)
throw new IllegalArgumentException ("lambda <= 0");
final double z = lambda*(x - alpha);
if (z <= -10.0)
return 0.0;
if (z >= XBIG)
return 1.0;
return Math.exp (-Math.exp (-z));
}
/**
* Computes the complementary distribution function.
*
*/
public static double barF (double alpha, double lambda, double x) {
if (lambda <= 0)
throw new IllegalArgumentException ("lambda <= 0");
final double z = lambda*(x - alpha);
if (z <= -10.0)
return 1.0;
if (z >= XBIGM)
return 0.0;
return -Math.expm1 (-Math.exp (-z));
}
/**
* Computes the inverse distribution function.
*
*/
public static double inverseF (double alpha, double lambda, double u) {
if (u < 0.0 || u > 1.0)
throw new IllegalArgumentException ("u not in [0, 1]");
if (lambda <= 0)
throw new IllegalArgumentException ("lambda <= 0");
if (u >= 1.0)
return Double.POSITIVE_INFINITY;
if (u <= 0.0)
return Double.NEGATIVE_INFINITY;
return -Math.log (-Math.log (u))/lambda+alpha;
}
/**
* Estimates the parameters
* (α, λ) of the extreme value distribution
* using the maximum likelihood method, from the n observations
* x[i],
* i = 0, 1,…, n - 1. The estimates are returned in a two-element
* array, in regular order: [α, λ].
*
* @param x the list of observations used to evaluate parameters
*
* @param n the number of observations used to evaluate parameters
*
* @return returns the parameters [
* hat(α),
* hat(λ)]
*
*/
public static double[] getMLE (double[] x, int n) {
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
double parameters[] = new double[2];
double sum = 0.0;
for (int i = 0; i < n; i++)
sum += x[i];
double mean = sum / (double) n;
sum = 0.0;
for (int i = 0; i < n; i++)
sum += (x[i] - mean) * (x[i] - mean);
double variance = sum / ((double) n - 1.0);
double lambda0 = Math.PI / Math.sqrt (6 * variance);
Function f = new Function (x, n, mean);
double a;
if ((a = lambda0 - 10.0) < 0)
a = 1e-15;
parameters[1] = RootFinder.brentDekker (a, lambda0 + 10.0, f, 1e-7);
double sumExp = 0.0;
for (int i = 0; i < n; i++)
sumExp += Math.exp (- x[i] * parameters[1]);
parameters[0] = - Math.log (sumExp / (double) n) / parameters[1];
return parameters;
}
/**
* Same as {@link #getMLE getMLE}.
*
*/
@Deprecated
public static double[] getMaximumLikelihoodEstimate (double[] x, int n) {
return getMLE(x, n);
}
/**
* Creates a new instance of an extreme value distribution with parameters α and
* λ estimated using the maximum likelihood method based on the n observations
* x[i],
* i = 0, 1,…, n - 1.
*
* @param x the list of observations to use to evaluate parameters
*
* @param n the number of observations to use to evaluate parameters
*
*
*/
public static ExtremeValueDist getInstanceFromMLE (double[] x, int n) {
double parameters[] = getMLE (x, n);
return new ExtremeValueDist (parameters[0], parameters[1]);
}
/**
* Computes and returns the mean,
* E[X] = α + γ/λ,
* of the extreme value distribution with parameters α and λ,
* where
* γ = 0.5772156649 is the Euler-Mascheroni constant.
*
* @return the mean of the Extreme Value distribution
* E[X] = α + γ/λ
*
*/
public static double getMean (double alpha, double lambda) {
if (lambda <= 0.0)
throw new IllegalArgumentException ("lambda <= 0");
return (alpha + Num.EULER / lambda);
}
/**
* Computes and returns the variance,
* Var[X] = π2/(6λ2),
* of the extreme value distribution with parameters α and λ.
*
* @return the variance of the extreme value distribution
* Var[X] = 1/6π21/λ2
*
*/
public static double getVariance (double alpha, double lambda) {
if (lambda <= 0.0)
throw new IllegalArgumentException ("lambda <= 0");
return ((1.0 / 6.0 * Math.PI * Math.PI) * (1.0 / (lambda * lambda)));
}
/**
* Computes and returns the standard deviation
* of the extreme value distribution with parameters α and λ.
*
* @return the standard deviation of the extreme value distribution
*
*/
public static double getStandardDeviation (double alpha, double lambda) {
if (lambda <= 0.0)
throw new IllegalArgumentException ("lambda <= 0");
return (Math.sqrt(1.0 / 6.0) * Math.PI / lambda);
}
/**
* Returns the parameter α of this object.
*
*/
public double getAlpha() {
return alpha;
}
/**
* Returns the parameter λ of this object.
*
*/
public double getLambda() {
return lambda;
}
/**
* Sets the parameters α and λ of this object.
*
*/
public void setParams (double alpha, double lambda) {
if (lambda <= 0)
throw new IllegalArgumentException ("lambda <= 0");
this.alpha = alpha;
this.lambda = lambda;
}
/**
* Return a table containing the parameters of the current distribution.
* This table is put in regular order: [α, λ].
*
*
*/
public double[] getParams () {
double[] retour = {alpha, lambda};
return retour;
}
public String toString () {
return getClass().getSimpleName() + " : alpha = " + alpha + ", lambda = " + lambda;
}
}
Ads help maintain this website.