SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
PowerDist.java
1/*
2 * Class: PowerDist
3 * Description: power distribution
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.probdist;
26
27import umontreal.ssj.util.Num;
28
46public class PowerDist extends ContinuousDistribution {
47 private double a;
48 private double b;
49 private double c;
50
55 public PowerDist(double a, double b, double c) {
56 setParams(a, b, c);
57 }
58
63 public PowerDist(double b, double c) {
64 setParams(0.0, b, c);
65 }
66
71 public PowerDist(double c) {
72 setParams(0.0, 1.0, c);
73 }
74
75 public double density(double x) {
76 return density(a, b, c, x);
77 }
78
79 public double cdf(double x) {
80 return cdf(a, b, c, x);
81 }
82
83 public double barF(double x) {
84 return barF(a, b, c, x);
85 }
86
87 public double inverseF(double u) {
88 return inverseF(a, b, c, u);
89 }
90
91 public double getMean() {
92 return PowerDist.getMean(a, b, c);
93 }
94
95 public double getVariance() {
96 return PowerDist.getVariance(a, b, c);
97 }
98
99 public double getStandardDeviation() {
100 return PowerDist.getStandardDeviation(a, b, c);
101 }
102
113 public static double density(double a, double b, double c, double x) {
114 if (c <= 0.0)
115 throw new IllegalArgumentException("c <= 0");
116 if (x <= a)
117 return 0.0;
118 if (x >= b)
119 return 0.0;
120 double z = (x - a) / (b - a);
121 return c * Math.pow(z, c - 1.0) / (b - a);
122 }
123
134 public static double cdf(double a, double b, double c, double x) {
135 if (c <= 0.0)
136 throw new IllegalArgumentException("c <= 0");
137 if (x <= a)
138 return 0.0;
139 if (x >= b)
140 return 1.0;
141 return Math.pow((x - a) / (b - a), c);
142 }
143
153 public static double barF(double a, double b, double c, double x) {
154 if (c <= 0.0)
155 throw new IllegalArgumentException("c <= 0");
156 if (x <= a)
157 return 1.0;
158 if (x >= b)
159 return 0.0;
160 return 1.0 - Math.pow((x - a) / (b - a), c);
161 }
162
172 public static double inverseF(double a, double b, double c, double u) {
173 if (c <= 0.0)
174 throw new IllegalArgumentException("c <= 0");
175 if (u < 0.0 || u > 1.0)
176 throw new IllegalArgumentException("u not in [0, 1]");
177 if (u == 0.0)
178 return a;
179 if (u == 1.0)
180 return b;
181
182 return a + (b - a) * Math.pow(u, 1.0 / c);
183 }
184
202 public static double[] getMLE(double[] x, int n, double a, double b) {
203 if (n <= 0)
204 throw new IllegalArgumentException("n <= 0");
205
206 double d = b - a;
207 double somme = 0;
208 for (int i = 0; i < n; ++i)
209 somme += Math.log((x[i] - a) / d);
210
211 double[] parametres = new double[1];
212 parametres[0] = -1.0 / (somme / n);
213 return parametres;
214 }
215
227 public static PowerDist getInstanceFromMLE(double[] x, int n, double a, double b) {
228 double parameters[] = getMLE(x, n, a, b);
229 return new PowerDist(a, b, parameters[0]);
230 }
231
241 public static double getMean(double a, double b, double c) {
242 return a + (b - a) * c / (c + 1.0);
243 }
244
254 public static double getVariance(double a, double b, double c) {
255 return (b - a) * (b - a) * c / ((c + 1.0) * (c + 1.0) * (c + 2.0));
256 }
257
264 public static double getStandardDeviation(double a, double b, double c) {
265 return Math.sqrt(PowerDist.getVariance(a, b, c));
266 }
267
273 public double getA() {
274 return a;
275 }
276
282 public double getB() {
283 return b;
284 }
285
291 public double getC() {
292 return c;
293 }
294
302 public void setParams(double a, double b, double c) {
303 this.a = a;
304 this.b = b;
305 this.c = c;
306 }
307
314 public double[] getParams() {
315 double[] retour = { a, b, c };
316 return retour;
317 }
318
324 public String toString() {
325 return getClass().getSimpleName() + " : a = " + a + " : b = " + b + " : c = " + c;
326 }
327
328}
Classes implementing continuous distributions should inherit from this base class.
static double barF(double a, double b, double c, double x)
Computes the complementary distribution function.
static double getVariance(double a, double b, double c)
Computes and returns the variance of the power distribution with parameters , and.
PowerDist(double c)
Constructs a PowerDist object with parameters , and c.
static double cdf(double a, double b, double c, double x)
Computes the distribution function ( Fpower ).
double getA()
Returns the parameter .
static PowerDist getInstanceFromMLE(double[] x, int n, double a, double b)
Creates a new instance of a power distribution with parameters.
static double getMean(double a, double b, double c)
Returns the mean of the power distribution with parameters , and .
static double density(double a, double b, double c, double x)
Computes the density function ( fpower ).
String toString()
Returns a String containing information about the current distribution.
double getMean()
Returns the mean.
double inverseF(double u)
Returns the inverse distribution function .
double getStandardDeviation()
Returns the standard deviation.
double getC()
Returns the parameter .
double getB()
Returns the parameter .
PowerDist(double a, double b, double c)
Constructs a PowerDist object with parameters a, b and c.
double cdf(double x)
Returns the distribution function .
void setParams(double a, double b, double c)
Sets the parameters , and for this object.
double density(double x)
Returns , the density evaluated at .
static double getStandardDeviation(double a, double b, double c)
Computes and returns the standard deviation of the power distribution with parameters ,...
PowerDist(double b, double c)
Constructs a PowerDist object with parameters , b and c.
static double[] getMLE(double[] x, int n, double a, double b)
Estimates the parameter of the power distribution from the.
static double inverseF(double a, double b, double c, double u)
Computes the inverse of the distribution function.
double[] getParams()
Return a table containing the parameters of the current distribution.
double getVariance()
Returns the variance.
double barF(double x)
Returns the complementary distribution function.