SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
ParetoDist.java
1/*
2 * Class: ParetoDist
3 * Description: Pareto 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
47public class ParetoDist extends ContinuousDistribution {
48 private double alpha;
49 private double beta;
50
55 public ParetoDist(double alpha) {
56 setParams(alpha, 1.0);
57 }
58
63 public ParetoDist(double alpha, double beta) {
64 setParams(alpha, beta);
65 }
66
67 public double density(double x) {
68 return density(alpha, beta, x);
69 }
70
71 public double cdf(double x) {
72 return cdf(alpha, beta, x);
73 }
74
75 public double barF(double x) {
76 return barF(alpha, beta, x);
77 }
78
79 public double inverseF(double u) {
80 return inverseF(alpha, beta, u);
81 }
82
83 public double getMean() {
84 return ParetoDist.getMean(alpha, beta);
85 }
86
87 public double getVariance() {
88 return ParetoDist.getVariance(alpha, beta);
89 }
90
91 public double getStandardDeviation() {
92 return ParetoDist.getStandardDeviation(alpha, beta);
93 }
94
98 public static double density(double alpha, double beta, double x) {
99 if (alpha <= 0.0)
100 throw new IllegalArgumentException("alpha <= 0");
101 if (beta <= 0.0)
102 throw new IllegalArgumentException("beta <= 0");
103
104 return x < beta ? 0 : alpha * Math.pow(beta / x, alpha) / x;
105 }
106
110 public static double cdf(double alpha, double beta, double x) {
111 if (alpha <= 0.0)
112 throw new IllegalArgumentException("alpha <= 0");
113 if (beta <= 0.0)
114 throw new IllegalArgumentException("beta <= 0");
115 if (x <= beta)
116 return 0.0;
117 return 1.0 - Math.pow(beta / x, alpha);
118 }
119
123 public static double barF(double alpha, double beta, double x) {
124 if (alpha <= 0)
125 throw new IllegalArgumentException("c <= 0");
126 if (beta <= 0.0)
127 throw new IllegalArgumentException("beta <= 0");
128 if (x <= beta)
129 return 1.0;
130 return Math.pow(beta / x, alpha);
131 }
132
136 public static double inverseF(double alpha, double beta, double u) {
137 if (alpha <= 0)
138 throw new IllegalArgumentException("c <= 0");
139 if (beta <= 0.0)
140 throw new IllegalArgumentException("beta <= 0");
141
142 if (u < 0.0 || u > 1.0)
143 throw new IllegalArgumentException("u not in [0,1]");
144
145 if (u <= 0.0)
146 return beta;
147
148 double t;
149 t = -Math.log1p(-u);
150 if ((u >= 1.0) || t / Math.log(10) >= alpha * Num.DBL_MAX_10_EXP)
151 return Double.POSITIVE_INFINITY;
152
153 return beta / Math.pow(1 - u, 1.0 / alpha);
154 }
155
173 public static double[] getMLE(double[] x, int n) {
174 if (n <= 0)
175 throw new IllegalArgumentException("n <= 0");
176
177 double[] parameters = new double[2];
178 parameters[1] = Double.POSITIVE_INFINITY;
179 for (int i = 0; i < n; i++) {
180 if (x[i] < parameters[1])
181 parameters[1] = x[i];
182 }
183
184 double sum = 0.0;
185 for (int i = 0; i < n; i++) {
186 if (x[i] > 0.0)
187 sum += Math.log(x[i] / parameters[1]);
188 else
189 sum -= 709.0;
190 }
191 parameters[0] = n / sum;
192 return parameters;
193 }
194
204 public static ParetoDist getInstanceFromMLE(double[] x, int n) {
205 double parameters[] = getMLE(x, n);
206 return new ParetoDist(parameters[0], parameters[1]);
207 }
208
215 public static double getMean(double alpha, double beta) {
216 if (alpha <= 1.0)
217 throw new IllegalArgumentException("alpha <= 1");
218 if (beta <= 0.0)
219 throw new IllegalArgumentException("beta <= 0");
220
221 return ((alpha * beta) / (alpha - 1.0));
222 }
223
232 public static double getVariance(double alpha, double beta) {
233 if (alpha <= 2)
234 throw new IllegalArgumentException("alpha <= 2");
235 if (beta <= 0.0)
236 throw new IllegalArgumentException("beta <= 0");
237
238 return ((alpha * beta * beta) / ((alpha - 2.0) * (alpha - 1.0) * (alpha - 1.0)));
239 }
240
247 public static double getStandardDeviation(double alpha, double beta) {
248 return Math.sqrt(ParetoDist.getVariance(alpha, beta));
249 }
250
254 public double getAlpha() {
255 return alpha;
256 }
257
261 public double getBeta() {
262 return beta;
263 }
264
268 public void setParams(double alpha, double beta) {
269 if (alpha <= 0.0)
270 throw new IllegalArgumentException("alpha <= 0");
271 if (beta <= 0.0)
272 throw new IllegalArgumentException("beta <= 0");
273
274 this.alpha = alpha;
275 this.beta = beta;
276 supportA = beta;
277 }
278
283 public double[] getParams() {
284 double[] retour = { alpha, beta };
285 return retour;
286 }
287
291 public String toString() {
292 return getClass().getSimpleName() + " : alpha = " + alpha + ", beta = " + beta;
293 }
294
295}
Classes implementing continuous distributions should inherit from this base class.
static double barF(double alpha, double beta, double x)
Computes the complementary distribution function.
double getStandardDeviation()
Returns the standard deviation.
double getAlpha()
Returns the parameter .
double barF(double x)
Returns the complementary distribution function.
static ParetoDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of a Pareto distribution with parameters.
double density(double x)
Returns , the density evaluated at .
double cdf(double x)
Returns the distribution function .
static double inverseF(double alpha, double beta, double u)
Computes the inverse of the distribution function.
double inverseF(double u)
Returns the inverse distribution function .
double getVariance()
Returns the variance.
static double[] getMLE(double[] x, int n)
Estimates the parameters of the Pareto distribution using the maximum likelihood method,...
static double getMean(double alpha, double beta)
Computes and returns the mean of the Pareto distribution with parameters and.
static double cdf(double alpha, double beta, double x)
Computes the distribution function.
double getMean()
Returns the mean.
ParetoDist(double alpha, double beta)
Constructs a ParetoDist object with parameters alpha and beta.
void setParams(double alpha, double beta)
Sets the parameter and for this object.
static double getStandardDeviation(double alpha, double beta)
Computes and returns the standard deviation of the Pareto distribution with parameters and .
ParetoDist(double alpha)
Constructs a ParetoDist object with parameters alpha and .
static double density(double alpha, double beta, double x)
Computes the density function.
static double getVariance(double alpha, double beta)
Computes and returns the variance.
String toString()
Returns a String containing information about the current distribution.
double[] getParams()
Return a table containing the parameters of the current distribution.
double getBeta()
Returns the parameter .
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static final int DBL_MAX_10_EXP
Largest int such that is representable (approximately) as a double.
Definition Num.java:108