SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
InverseGammaDist.java
1/*
2 * Class: InverseGammaDist
3 * Description: inverse gamma 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
52 protected double alpha;
53 protected double beta;
54 protected double logam; // Ln (Gamma(alpha))
55
61 public InverseGammaDist(double alpha, double beta) {
62 setParam(alpha, beta);
63 }
64
65 public double density(double x) {
66 if (x <= 0.0)
67 return 0.0;
68 return Math.exp(alpha * Math.log(beta / x) - (beta / x) - logam) / 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 getMean(alpha, beta);
85 }
86
87 public double getVariance() {
88 return getVariance(alpha, beta);
89 }
90
91 public double getStandardDeviation() {
92 return getStandardDeviation(alpha, beta);
93 }
94
99 public static double density(double alpha, double beta, double x) {
100 if (alpha <= 0.0)
101 throw new IllegalArgumentException("alpha <= 0");
102 if (beta <= 0.0)
103 throw new IllegalArgumentException("beta <= 0");
104 if (x <= 0.0)
105 return 0.0;
106
107 return Math.exp(alpha * Math.log(beta / x) - (beta / x) - Num.lnGamma(alpha)) / x;
108 }
109
115 public static double cdf(double alpha, double beta, double x) {
116 if (alpha <= 0.0)
117 throw new IllegalArgumentException("alpha <= 0");
118 if (beta <= 0.0)
119 throw new IllegalArgumentException("beta <= 0");
120 if (x <= 0.0)
121 return 0.0;
122
123 return GammaDist.barF(alpha, beta, 15, 1.0 / x);
124 }
125
131 public static double barF(double alpha, double beta, double x) {
132 if (alpha <= 0.0)
133 throw new IllegalArgumentException("alpha <= 0");
134 if (beta <= 0.0)
135 throw new IllegalArgumentException("beta <= 0");
136 if (x <= 0.0)
137 return 1.0;
138
139 return GammaDist.cdf(alpha, beta, 15, 1.0 / x);
140 }
141
146 public static double inverseF(double alpha, double beta, double u) {
147 if (alpha <= 0.0)
148 throw new IllegalArgumentException("alpha <= 0");
149 if (beta <= 0.0)
150 throw new IllegalArgumentException("beta <= 0");
151
152 return 1.0 / GammaDist.inverseF(alpha, beta, 15, 1 - u);
153 }
154
167 public static double[] getMLE(double[] x, int n) {
168 double[] y = new double[n];
169
170 for (int i = 0; i < n; i++) {
171 if (x[i] > 0)
172 y[i] = 1.0 / x[i];
173 else
174 y[i] = 1.0E100;
175 }
176
177 return GammaDist.getMLE(y, n);
178 }
179
189 public static InverseGammaDist getInstanceFromMLE(double[] x, int n) {
190 double parameters[] = getMLE(x, n);
191 return new InverseGammaDist(parameters[0], parameters[1]);
192 }
193
199 public static double getMean(double alpha, double beta) {
200 if (alpha <= 0.0)
201 throw new IllegalArgumentException("alpha <= 0");
202 if (beta <= 0.0)
203 throw new IllegalArgumentException("beta <= 0");
204
205 return (beta / (alpha - 1.0));
206 }
207
213 public static double getVariance(double alpha, double beta) {
214 if (alpha <= 0.0)
215 throw new IllegalArgumentException("alpha <= 0");
216 if (beta <= 0.0)
217 throw new IllegalArgumentException("beta <= 0");
218
219 return ((beta * beta) / ((alpha - 1.0) * (alpha - 1.0) * (alpha - 2.0)));
220 }
221
226 public static double getStandardDeviation(double alpha, double beta) {
227 return Math.sqrt(getVariance(alpha, beta));
228 }
229
233 public double getAlpha() {
234 return alpha;
235 }
236
240 public double getBeta() {
241 return beta;
242 }
243
247 public void setParam(double alpha, double beta) {
248 if (alpha <= 0.0)
249 throw new IllegalArgumentException("alpha <= 0");
250 if (beta <= 0.0)
251 throw new IllegalArgumentException("beta <= 0");
252 supportA = 0.0;
253 this.alpha = alpha;
254 this.beta = beta;
255 logam = Num.lnGamma(alpha);
256 }
257
262 public double[] getParams() {
263 double[] retour = { alpha, beta };
264 return retour;
265 }
266
270 public String toString() {
271 return getClass().getSimpleName() + " : alpha = " + alpha + ", beta = " + beta;
272 }
273
274}
Classes implementing continuous distributions should inherit from this base class.
Extends the class ContinuousDistribution for the gamma distribution tjoh95a  (page 337) with shape pa...
double inverseF(double u)
Returns the inverse distribution function .
double cdf(double x)
Returns the distribution function .
static double[] getMLE(double[] x, int n)
Estimates the parameters of the gamma distribution using the maximum likelihood method,...
double barF(double x)
Returns the complementary distribution function.
double getAlpha()
Returns the parameter of this object.
double inverseF(double u)
Returns the inverse distribution function .
static double getVariance(double alpha, double beta)
Returns the variance of the inverse gamma distribution with shape parameter and scale parameter .
static double getStandardDeviation(double alpha, double beta)
Returns the standard deviation of the inverse gamma distribution with shape parameter and scale para...
double cdf(double x)
Returns the distribution function .
static double[] getMLE(double[] x, int n)
Estimates the parameters of the inverse gamma distribution using the maximum likelihood method,...
double density(double x)
Returns , the density evaluated at .
double barF(double x)
Returns the complementary distribution function.
double getBeta()
Returns the parameter of this object.
static double getMean(double alpha, double beta)
Returns the mean of the inverse gamma distribution with shape parameter and scale parameter .
static double cdf(double alpha, double beta, double x)
Computes the cumulative probability function of the inverse gamma distribution with shape parameter ...
static double density(double alpha, double beta, double x)
Computes the density function of the inverse gamma distribution with shape parameter and scale param...
double getStandardDeviation()
Returns the standard deviation.
double getVariance()
Returns the variance.
void setParam(double alpha, double beta)
Sets the parameters and of this object.
static double inverseF(double alpha, double beta, double u)
Computes the inverse distribution function of the inverse gamma distribution with shape parameter an...
static InverseGammaDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of the inverse gamma distribution with parameters and estimated using the ma...
static double barF(double alpha, double beta, double x)
Computes the complementary distribution function of the inverse gamma distribution with shape paramet...
InverseGammaDist(double alpha, double beta)
Constructs an InverseGammaDist object with parameters.
String toString()
Returns a String containing information about the current distribution.
double[] getParams()
Returns a table containing the parameters of the current distribution.
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static double lnGamma(double x)
Returns the natural logarithm of the gamma function evaluated at x.
Definition Num.java:417