25package umontreal.ssj.probdist;
27import umontreal.ssj.util.Num;
28import umontreal.ssj.util.RootFinder;
29import umontreal.ssj.functions.MathFunction;
53 private double lambda;
57 protected double mean;
60 public Function(
double[] x,
int n,
double mean) {
63 this.x =
new double[n];
65 System.arraycopy(x, 0, this.x, 0, n);
68 public double evaluate(
double lambda) {
72 double sumXiExp = 0.0;
75 for (
int i = 0; i < n; i++) {
76 exp = Math.exp(-x[i] * lambda);
78 sumXiExp += x[i] * exp;
81 return ((mean - 1.0 / lambda) * sumExp - sumXiExp);
104 return density(alpha, lambda, x);
107 public double cdf(
double x) {
108 return cdf(alpha, lambda, x);
112 return barF(alpha, lambda, x);
134 public static double density(
double alpha,
double lambda,
double x) {
136 throw new IllegalArgumentException(
"lambda <= 0");
137 final double z = lambda * (x - alpha);
140 double t = Math.exp(-z);
141 return lambda * t * Math.exp(-t);
148 public static double cdf(
double alpha,
double lambda,
double x) {
150 throw new IllegalArgumentException(
"lambda <= 0");
151 final double z = lambda * (x - alpha);
156 return Math.exp(-Math.exp(-z));
162 public static double barF(
double alpha,
double lambda,
double x) {
164 throw new IllegalArgumentException(
"lambda <= 0");
165 final double z = lambda * (x - alpha);
170 return -Math.expm1(-Math.exp(-z));
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]");
180 throw new IllegalArgumentException(
"lambda <= 0");
182 return Double.POSITIVE_INFINITY;
184 return Double.NEGATIVE_INFINITY;
186 return -Math.log(-Math.log(u)) / lambda + alpha;
209 public static double[]
getMLE(
double[] x,
int n) {
211 throw new IllegalArgumentException(
"n <= 0");
213 double parameters[] =
new double[2];
216 for (
int i = 0; i < n; i++)
218 double mean = sum / (double) n;
221 for (
int i = 0; i < n; i++)
222 sum += (x[i] - mean) * (x[i] - mean);
223 double variance = sum / ((double) n - 1.0);
225 double lambda0 = Math.PI / Math.sqrt(6 * variance);
227 Function f =
new Function(x, n, mean);
230 if ((a = lambda0 - 10.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];
260 double parameters[] =
getMLE(x, n);
272 public static double getMean(
double alpha,
double lambda) {
274 throw new IllegalArgumentException(
"lambda <= 0");
276 return (alpha +
Num.
EULER / lambda);
289 throw new IllegalArgumentException(
"lambda <= 0");
291 return ((1.0 / 6.0 * Math.PI * Math.PI) * (1.0 / (lambda * lambda)));
302 throw new IllegalArgumentException(
"lambda <= 0");
304 return (Math.sqrt(1.0 / 6.0) * Math.PI / lambda);
326 throw new IllegalArgumentException(
"lambda <= 0");
328 this.lambda = lambda;
336 double[] retour = { alpha, lambda };
344 return getClass().getSimpleName() +
" : alpha = " + alpha +
", lambda = " + lambda;
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 getMean()
Returns the mean.
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,...
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.