/* *
* Title:
* Description:
* Copyright: Copyright (c)
* Company:
* @author
* @version 1.0
*/
package umontreal.iro.lecuyer.probdist;
/**
* Extends the class {@link GammaDist} for the special case
* of the Erlang distribution with
* shape parameter k > 0 and scale parameter
* λ > 0.
* This distribution is a special case of the gamma distribution
* for which the shape parameter k = α is an integer.
*
*/
public class ErlangDist extends GammaDist {
/**
* Constructs a ErlangDist object with parameters
* k = k and λ = 1.
*
*/
public ErlangDist (int k) {
super (k);
}
/**
* Constructs a ErlangDist object with parameters
* k = k and λ = lambda.
*
*/
public ErlangDist (int k, double lambda) {
super (k, lambda);
}
/**
* Computes the density function.
*
*/
public static double density (int k, double lambda, double x) {
return density ((double)k, lambda, x);
}
/**
* Computes the distribution function using
* the gamma distribution function.
*
*/
public static double cdf (int k, double lambda, int d, double x) {
return cdf ((double)k, d, lambda*x);
}
/**
* Computes the complementary distribution function.
*
*/
public static double barF (int k, double lambda, int d, double x) {
return barF ((double)k, d, lambda*x);
}
/**
* Returns the inverse distribution function.
*
*/
public static double inverseF (int k, double lambda, int d, double u) {
return inverseF ((double)k, lambda, d, u);
}
/**
* Estimates the parameters
* (k, λ) of the Erlang 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: [k, λ].
*
* @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(k),
* hat(λ)]
*
*/
public static double[] getMLE (double[] x, int n) {
double parameters[] = GammaDist.getMLE (x, n);
parameters[0] = Math.round (parameters[0]);
return parameters;
}
/**
* Creates a new instance of an Erlang distribution with parameters k 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 ErlangDist getInstanceFromMLE (double[] x, int n) {
double parameters[] = getMLE (x, n);
return new ErlangDist ((int) parameters[0], parameters[1]);
}
/**
* Computes and returns the mean,
* E[X] = k/λ,
* of the Erlang distribution with parameters k and λ.
*
* @return the mean of the Erlang distribution
* E[X] = k/λ
*
*/
public static double getMean (int k, double lambda) {
if (k <= 0)
throw new IllegalArgumentException ("k <= 0");
if (lambda <= 0.0)
throw new IllegalArgumentException ("lambda <= 0");
return (k / lambda);
}
/**
* Computes and returns the variance,
* Var[X] = k/λ2,
* of the Erlang distribution with parameters k and λ.
*
* @return the variance of the Erlang distribution
* Var[X] = k/λ2
*
*/
public static double getVariance (int k, double lambda) {
if (k <= 0)
throw new IllegalArgumentException ("k <= 0");
if (lambda <= 0.0)
throw new IllegalArgumentException ("lambda <= 0");
return (k / (lambda * lambda));
}
/**
* Computes and returns the standard deviation of the Erlang
* distribution with parameters k and λ.
*
* @return the standard deviation of the Erlang distribution
*
*/
public static double getStandardDeviation (int k, double lambda) {
if (k <= 0)
throw new IllegalArgumentException ("k <= 0");
if (lambda <= 0.0)
throw new IllegalArgumentException ("lambda <= 0");
return (Math.sqrt (k) / lambda);
}
/**
* Returns the parameter k for this object.
*
*/
public int getK() {
return (int) getAlpha();
}
/**
* Sets the parameters k and λ of the distribution for this
* object. Non-static methods are computed with a rough target of
* d decimal digits of precision.
*
*/
public void setParams (int k, double lambda, int d) {
setParams (k, lambda, d);
}
/**
* Return a table containing parameters of the current distribution.
* This table is put in regular order: [k, λ].
*
*
*/
public double[] getParams () {
return super.getParams();
}
public String toString () {
return getClass().getSimpleName() + " : k = " + (int)super.getAlpha() + ", lambda = " + super.getLambda();
}
}
Ads help maintain this website.