25package umontreal.ssj.probdist;
27import umontreal.ssj.util.*;
29import umontreal.ssj.functions.MathFunction;
57 private static class Optim
implements Lmder_fcn {
61 public Optim(
double[] x,
int n) {
66 public void fcn(
int m,
int n,
double[] par,
double[] fvec,
double[][] fjac,
int iflag[]) {
67 if (par[1] <= 0.0 || par[2] <= 0.0) {
68 final double BIG = 1.0e100;
75 double sum1, sum2, sumb, sum4, sum5;
77 double alpha = par[1];
82 sum1 = sum2 = sumb = sum4 = sum5 = 0;
83 for (
int i = 0; i < n; i++) {
84 z = (x[i] - mu) / beta;
86 v = Math.pow(z, -alpha);
95 fvec[3] = (alpha + 1) * sum1 - alpha * sum2;
96 fvec[1] = n / alpha + sum5 - sum4;
98 }
else if (iflag[1] == 2) {
99 throw new IllegalArgumentException(
"iflag = 2");
108 private double delta;
112 public Function(
double[] y,
int n,
double delta) {
116 double xmin = Double.MAX_VALUE;
117 for (
int i = 0; i < n; i++) {
118 if ((y[i] < xmin) && (y[i] > delta))
124 public double evaluate(
double alpha) {
128 double sum1 = 0, sum2 = 0, sum3 = 0;
129 for (
int i = 0; i < n; i++) {
132 v = Math.log(x[i] - delta);
133 w = Math.pow(dif / (x[i] - delta), alpha);
141 return 1 / alpha + sum3 / sum2 - sum1;
162 return density(alpha, beta, delta, x);
165 public double cdf(
double x) {
166 return cdf(alpha, beta, delta, x);
170 return barF(alpha, beta, delta, x);
174 return inverseF(alpha, beta, delta, u);
178 return getMean(alpha, beta, delta);
192 public static double density(
double alpha,
double beta,
double delta,
double x) {
194 throw new IllegalArgumentException(
"beta <= 0");
196 throw new IllegalArgumentException(
"alpha <= 0");
197 final double z = (x - delta) / beta;
200 double t = Math.pow(z, -alpha);
201 return alpha * t * Math.exp(-t) / (z * beta);
207 public static double cdf(
double alpha,
double beta,
double delta,
double x) {
209 throw new IllegalArgumentException(
"beta <= 0");
211 throw new IllegalArgumentException(
"alpha <= 0");
212 final double z = (x - delta) / beta;
215 double t = Math.pow(z, -alpha);
222 public static double barF(
double alpha,
double beta,
double delta,
double x) {
224 throw new IllegalArgumentException(
"beta <= 0");
226 throw new IllegalArgumentException(
"alpha <= 0");
227 final double z = (x - delta) / beta;
230 double t = Math.pow(z, -alpha);
231 return -Math.expm1(-t);
237 public static double inverseF(
double alpha,
double beta,
double delta,
double u) {
238 if (u < 0.0 || u > 1.0)
239 throw new IllegalArgumentException(
"u not in [0, 1]");
241 throw new IllegalArgumentException(
"beta <= 0");
243 throw new IllegalArgumentException(
"alpha <= 0");
245 return Double.POSITIVE_INFINITY;
248 double t = Math.pow(-Math.log(u), 1.0 / alpha);
249 if (t <= Double.MIN_NORMAL)
250 return Double.MAX_VALUE;
251 return delta + beta / t;
275 public static double[]
getMLE(
double[] x,
int n,
double delta) {
277 throw new IllegalArgumentException(
"n <= 1");
279 Function func =
new Function(x, n, delta);
283 double par[] =
new double[2];
285 par[1] = func.dif * Math.pow(func.sumxi, -1.0 / alpha);
300 double par[] =
getMLE(x, n, delta);
310 public static double getMean(
double alpha,
double beta,
double delta) {
312 throw new IllegalArgumentException(
"beta <= 0");
314 throw new IllegalArgumentException(
"alpha <= 1");
316 return delta + beta * Math.exp(t);
325 public static double getVariance(
double alpha,
double beta,
double delta) {
327 throw new IllegalArgumentException(
"beta <= 0");
329 throw new IllegalArgumentException(
"alpha <= 2");
331 double mu = Math.exp(t);
332 double v = Math.exp(
Num.
lnGamma(1.0 - 2.0 / alpha));
333 return beta * beta * (v - mu * mu);
371 public void setParams(
double alpha,
double beta,
double delta) {
373 throw new IllegalArgumentException(
"beta <= 0");
375 throw new IllegalArgumentException(
"alpha <= 0");
386 double[] retour = { alpha, beta, delta };
394 return getClass().getSimpleName() +
" : alpha = " + alpha +
", beta = " + beta +
", delta = " + delta;
Classes implementing continuous distributions should inherit from this base class.
double inverseF(double u)
Returns the inverse distribution function .
String toString()
Returns a String containing information about the current distribution.
double cdf(double x)
Returns the distribution function .
static FrechetDist getInstanceFromMLE(double[] x, int n, double delta)
Given delta, creates a new instance of a Fréchet distribution with parameters and.
static double getMean(double alpha, double beta, double delta)
Returns the mean of the Fréchet distribution with parameters , and .
double[] getParams()
Return an array containing the parameters of the current object in regular order: [ ,...
static double inverseF(double alpha, double beta, double delta, double u)
Computes and returns the inverse distribution function.
FrechetDist(double alpha, double beta, double delta)
Constructs a FrechetDist object with parameters = alpha, = beta and = delta.
FrechetDist(double alpha)
Constructor for the standard Fréchet distribution with parameters = 1 and = 0.
void setParams(double alpha, double beta, double delta)
Sets the parameters , and of this object.
double barF(double x)
Returns the complementary distribution function.
static double cdf(double alpha, double beta, double delta, double x)
Computes and returns the distribution function.
double getStandardDeviation()
Returns the standard deviation.
double getBeta()
Returns the parameter of this object.
static double density(double alpha, double beta, double delta, double x)
Computes and returns the density function.
static double getStandardDeviation(double alpha, double beta, double delta)
Returns the standard deviation of the Fréchet distribution with parameters , and .
double density(double x)
Returns , the density evaluated at .
double getVariance()
Returns the variance.
double getAlpha()
Returns the parameter of this object.
double getMean()
Returns the mean.
static double[] getMLE(double[] x, int n, double delta)
Given delta, estimates the parameters of the Fréchet distribution using the maximum likelihood meth...
double getDelta()
Returns the parameter of this object.
static double barF(double alpha, double beta, double delta, double x)
Computes and returns the complementary distribution function .
static double getVariance(double alpha, double beta, double delta)
Returns the variance of the Fréchet distribution with parameters , and .
This class provides various constants and methods to compute numerical quantities such as factorials,...
static double lnGamma(double x)
Returns the natural logarithm of the gamma function evaluated at x.
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.