SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
ExponentialDist.java
1/*
2 * Class: ExponentialDist
3 * Description: exponential 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
45 private double lambda;
46
50 public ExponentialDist() {
51 setLambda(1.0);
52 }
53
58 public ExponentialDist(double lambda) {
59 setLambda(lambda);
60 }
61
62 public double density(double x) {
63 return density(lambda, x);
64 }
65
66 public double cdf(double x) {
67 return cdf(lambda, x);
68 }
69
70 public double barF(double x) {
71 return barF(lambda, x);
72 }
73
74 public double inverseF(double u) {
75 return inverseF(lambda, u);
76 }
77
78 public double getMean() {
79 return ExponentialDist.getMean(lambda);
80 }
81
82 public double getVariance() {
83 return ExponentialDist.getVariance(lambda);
84 }
85
86 public double getStandardDeviation() {
87 return ExponentialDist.getStandardDeviation(lambda);
88 }
89
93 public static double density(double lambda, double x) {
94 if (lambda <= 0)
95 throw new IllegalArgumentException("lambda <= 0");
96 return x < 0 ? 0 : lambda * Math.exp(-lambda * x);
97 }
98
102 public static double cdf(double lambda, double x) {
103 if (lambda <= 0)
104 throw new IllegalArgumentException("lambda <= 0");
105 if (x <= 0.0)
106 return 0.0;
107 double y = lambda * x;
108 if (y >= XBIG)
109 return 1.0;
110 return -Math.expm1(-y);
111 }
112
116 public static double barF(double lambda, double x) {
117 if (lambda <= 0)
118 throw new IllegalArgumentException("lambda <= 0");
119 if (x <= 0.0)
120 return 1.0;
121 if (lambda * x >= XBIGM)
122 return 0.0;
123 return Math.exp(-lambda * x);
124 }
125
129 public static double inverseF(double lambda, double u) {
130 if (lambda <= 0)
131 throw new IllegalArgumentException("lambda <= 0");
132 if (u < 0.0 || u > 1.0)
133 throw new IllegalArgumentException("u not in [0,1]");
134 if (u >= 1.0)
135 return Double.POSITIVE_INFINITY;
136 if (u <= 0.0)
137 return 0.0;
138 return -Math.log1p(-u) / lambda;
139 }
140
154 public static double[] getMLE(double[] x, int n) {
155 if (n <= 0)
156 throw new IllegalArgumentException("n <= 0");
157
158 double parameters[];
159 double sum = 0.0;
160 parameters = new double[1];
161 for (int i = 0; i < n; i++)
162 sum += x[i];
163 parameters[0] = (double) n / sum;
164
165 return parameters;
166 }
167
176 public static ExponentialDist getInstanceFromMLE(double[] x, int n) {
177 double parameters[] = getMLE(x, n);
178 return new ExponentialDist(parameters[0]);
179 }
180
187 public static double getMean(double lambda) {
188 if (lambda <= 0.0)
189 throw new IllegalArgumentException("lambda <= 0");
190
191 return (1 / lambda);
192 }
193
201 public static double getVariance(double lambda) {
202 if (lambda <= 0.0)
203 throw new IllegalArgumentException("lambda <= 0");
204
205 return (1 / (lambda * lambda));
206 }
207
214 public static double getStandardDeviation(double lambda) {
215 if (lambda <= 0.0)
216 throw new IllegalArgumentException("lambda <= 0");
217
218 return (1 / lambda);
219 }
220
224 public double getLambda() {
225 return lambda;
226 }
227
231 public void setLambda(double lambda) {
232 if (lambda <= 0)
233 throw new IllegalArgumentException("lambda <= 0");
234 this.lambda = lambda;
235 supportA = 0.0;
236 }
237
241 public double[] getParams() {
242 double[] retour = { lambda };
243 return retour;
244 }
245
249 public String toString() {
250 return getClass().getSimpleName() + " : lambda = " + lambda;
251 }
252
253}
Classes implementing continuous distributions should inherit from this base class.
double getLambda()
Returns the value of for this object.
double inverseF(double u)
Returns the inverse distribution function .
static double[] getMLE(double[] x, int n)
Estimates the rate parameter of the exponential distribution using the maximum likelihood method,...
double density(double x)
Returns , the density evaluated at .
double getStandardDeviation()
Returns the standard deviation.
double getVariance()
Returns the variance.
static double inverseF(double lambda, double u)
Computes the inverse distribution function.
ExponentialDist(double lambda)
Constructs an ExponentialDist object with rate parameter = lambda.
void setLambda(double lambda)
Sets the value of for this object.
static double density(double lambda, double x)
Computes the density function.
static double barF(double lambda, double x)
Computes the complementary distribution function.
static double getMean(double lambda)
Computes and returns the mean, , of the exponential distribution with rate parameter .
String toString()
Returns a String containing information about the current distribution.
static double getStandardDeviation(double lambda)
Computes and returns the standard deviation of the exponential distribution with rate parameter .
static double getVariance(double lambda)
Computes and returns the variance, , of the exponential distribution with rate parameter.
static double cdf(double lambda, double x)
Computes the distribution function.
double barF(double x)
Returns the complementary distribution function.
double cdf(double x)
Returns the distribution function .
ExponentialDist()
Constructs an ExponentialDist object with rate parameter = 1.
double[] getParams()
Return a table containing the parameters of the current distribution.
static ExponentialDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of an exponential distribution with rate parameter.