/* *
 * Title:        

* Description:

* Copyright: Copyright (c)

* Company:

* @author * @version 1.0 */ package umontreal.iro.lecuyer.probdist; import umontreal.iro.lecuyer.util.Num; /** * Extends the class {@link ContinuousDistribution} for * the power distribution with shape parameter * c > 0, over the interval [a, b], where a < b. * It has density *

*

*
* f (x) = c(x - a)c-1/(b - a)c *

* for a < x < b, and 0 elsewhere. It has distribution function *

*

*
* F(x) = (x - a)c/(b - a)c        for a <= x <= b, *

* with F(x) = 0 for x <= a and F(x) = 1 for x >= b. * */ public class PowerDist extends ContinuousDistribution { private double a; private double b; private double c; /** * Constructs a PowerDist object with parameters * a = a, b = b and c = c. * */ public PowerDist (double a, double b, double c) { setParams (a, b, c); } /** * Constructs a PowerDist object with parameters * a = 0, b = b and c = c. * */ public PowerDist (double b, double c) { setParams (0.0, b, c); } /** * Constructs a PowerDist object with parameters * a = 0, b = 1 and c = c. * */ public PowerDist (double c) { setParams (0.0, 1.0, c); } public double density (double x) { return density (a, b, c, x); } public double cdf (double x) { return cdf (a, b, c, x); } public double barF (double x) { return barF (a, b, c, x); } public double inverseF (double u) { return inverseF (a, b, c, u); } public double getMean() { return PowerDist.getMean (a, b, c); } public double getVariance() { return PowerDist.getVariance (a, b, c); } public double getStandardDeviation() { return PowerDist.getStandardDeviation (a, b, c); } /** * Computes the density function. * * @param a left limit of interval * * @param b right limit of interval * * @param c shape parameter * * @param x the value at which the density is evaluated * * @return returns the density function * */ public static double density (double a, double b, double c, double x) { if (c <= 0.0) throw new IllegalArgumentException ("c <= 0"); if (x <= a) return 0.0; if (x >= b) return 0.0; double z = (x-a)/(b-a); return c*Math.pow(z, c-1.0) / (b-a); } /** * Computes the distribution function. * * @param a left limit of interval * * @param b right limit of interval * * @param c shape parameter * * @param x the value at which the distribution is evaluated * * @return returns the distribution function * */ public static double cdf (double a, double b, double c, double x) { if (c <= 0.0) throw new IllegalArgumentException ("c <= 0"); if (x <= a) return 0.0; if (x >= b) return 1.0; return Math.pow((x-a)/(b-a), c); } /** * Computes the complementary distribution function. * * @param a left limit of interval * * @param b right limit of interval * * @param c shape parameter * * @param x the value at which the complementary distribution is evaluated * * @return returns the complementary distribution function * */ public static double barF (double a, double b, double c, double x) { if (c <= 0.0) throw new IllegalArgumentException ("c <= 0"); if (x <= a) return 1.0; if (x >= b) return 0.0; return 1.0 - Math.pow((x-a)/(b-a),c); } /** * Computes the inverse of the distribution function. * * @param a left limit of interval * * @param b right limit of interval * * @param c shape parameter * * @param u the value at which the inverse distribution is evaluated * * @return returns the inverse of the distribution function * */ public static double inverseF (double a, double b, double c, double u) { if (c <= 0.0) throw new IllegalArgumentException ("c <= 0"); if (u < 0.0 || u > 1.0) throw new IllegalArgumentException ("u not in [0, 1]"); if (u == 0.0) return a; if (u == 1.0) return b; return a + (b-a) * Math.pow(u,1.0/c); } /** * Estimates the parameter c of the power distribution from the n * observations x[i], * i = 0, 1,…, n - 1, using the maximum * likelihood method and assuming that a and b are known. * The estimate is returned in a one-element array: [c]. * * @param x the list of observations to use to evaluate parameters * * @param n the number of observations to use to evaluate parameters * * @param a left limit of interval * * @param b right limit of interval * * @return returns the shape parameter [hat(c)] * */ public static double[] getMLE (double[] x, int n, double a, double b) { if (n <= 0) throw new IllegalArgumentException ("n <= 0"); double d = b - a; double somme = 0; for (int i = 0 ; i < n ; ++i) somme += Math.log((x[i] - a)/d); double [] parametres = new double [1]; parametres[0] = -1.0 / (somme/n); return parametres; } /** * Creates a new instance of a power distribution with parameters a and b, * with c estimated using the maximum likelihood method based on the * n observations x[i], * i = 0,…, n - 1. * * @param x the list of observations to use to evaluate parameters * * @param n the number of observations to use to evaluate parameters * * @param a left limit of interval * * @param b right limit of interval * * */ public static PowerDist getInstanceFromMLE (double[] x, int n, double a, double b) { double parameters[] = getMLE (x, n, a, b); return new PowerDist (a, b, parameters[0]); } /** * Returns the mean * a + (b - a)c/(c + 1) of the power distribution * with parameters a, b and c. * * @param a left limit of interval * * @param b right limit of interval * * @param c shape parameter * * @return returns the mean * */ public static double getMean (double a, double b, double c) { return a + (b-a) * c / (c+1.0); } /** * Computes and returns the variance * (b - a)2c/[(c + 1)2(c + 2)] * of the power distribution with parameters a, b and c. * * @param a left limit of interval * * @param b right limit of interval * * @param c shape parameter * * @return returns the variance * */ public static double getVariance (double a, double b, double c) { return (b-a)*(b-a)*c / ((c+1.0)*(c+1.0)*(c+2.0)); } /** * Computes and returns the standard deviation * of the power distribution with parameters a, b and c. * * @return the standard deviation of the power distribution * */ public static double getStandardDeviation (double a, double b, double c) { return Math.sqrt (PowerDist.getVariance (a, b, c)); } /** * Returns the parameter a. * * @return the left limit of interval a * */ public double getA() { return a; } /** * Returns the parameter b. * * @return the right limit of interval b * */ public double getB() { return b; } /** * Returns the parameter c. * * @return the shape parameter c * */ public double getC() { return c; } /** * Sets the parameters a, b and c for this object. * * @param a left limit of interval * * @param b right limit of interval * * @param c shape parameter * * */ public void setParams (double a, double b, double c) { this.a = a; this.b = b; this.c = c; } /** * Return a table containing the parameters of the current distribution. * This table is put in regular order: [a, b, c]. * * @return [a, b,c] * * */ public double[] getParams () { double[] retour = {a, b, c}; return retour; } public String toString () { return getClass().getSimpleName() + " : a = " + a + " : b = " + b + " : c = " + c; } }

Ads help maintain this website.