SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NormalInverseGaussianDist.java
1/*
2 * Class: NormalInverseGaussianDist
3 * Description: normal inverse gaussian 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.probdist.NormalDist;
28import umontreal.ssj.util.Num;
29
52 protected double alpha;
53 protected double beta;
54 protected double gamma;
55 protected double delta;
56 protected double mu;
57
64 public NormalInverseGaussianDist(double alpha, double beta, double mu, double delta) {
65 setParams(alpha, beta, mu, delta);
66 }
67
68 public double density(double x) {
69 return density(alpha, beta, mu, delta, x);
70 }
71
72 public double cdf(double x) {
73 return cdf(alpha, beta, mu, delta, x);
74 }
75
76 public double barF(double x) {
77 return barF(alpha, beta, mu, delta, x);
78 }
79
80 public double getMean() {
81 return getMean(alpha, beta, mu, delta);
82 }
83
84 public double getVariance() {
85 return getVariance(alpha, beta, mu, delta);
86 }
87
88 public double getStandardDeviation() {
89 return getStandardDeviation(alpha, beta, mu, delta);
90 }
91
99 public static double density(double alpha, double beta, double mu, double delta, double x) {
100 if (delta <= 0.0)
101 throw new IllegalArgumentException("delta <= 0");
102 if (alpha <= 0.0)
103 throw new IllegalArgumentException("alpha <= 0");
104 if (Math.abs(beta) >= alpha)
105 throw new IllegalArgumentException("|beta| >= alpha");
106
107 double gamma = Math.sqrt(alpha * alpha - beta * beta);
108 double z = (x - mu) / delta;
109 double w;
110 if (Math.abs(z) <= 1.0e10)
111 w = Math.sqrt(1.0 + z * z);
112 else
113 w = Math.abs(z);
114 double y = alpha * delta * w;
115 double v = delta * (gamma + beta * z);
116 double R = Num.expBesselK1(v, y);
117 return alpha * R / (Math.PI * w);
118 }
119
127 public static double cdf(double alpha, double beta, double mu, double delta, double x) {
128 if (delta <= 0.0)
129 throw new IllegalArgumentException("delta <= 0");
130 if (alpha <= 0.0)
131 throw new IllegalArgumentException("alpha <= 0");
132 if (Math.abs(beta) >= alpha)
133 throw new IllegalArgumentException("|beta| >= alpha");
134
135 double gamma = Math.sqrt(alpha * alpha - beta * beta);
136 double z = (x - mu) / delta;
137 if (z > 0.0 && (gamma + (beta - alpha) * z >= XBIG))
138 return 1.0;
139 if (z < 0.0 && (gamma + (beta + alpha) * z <= -XBIGM))
140 return 0.0;
141 // double w = Math.sqrt (1.0 + z*z);
142
143 throw new UnsupportedOperationException("NormalInverseGaussianDist: cdf NOT IMPLEMENTED");
144 }
145
152 public static double barF(double alpha, double beta, double mu, double delta, double x) {
153 return 1.0 - cdf(alpha, beta, mu, delta, x);
154 }
155
162 public static double inverseF(double alpha, double beta, double mu, double delta, double u) {
163 throw new UnsupportedOperationException(" Inversion NOT IMPLEMENTED");
164 }
165
174 public static double[] getMLE(double[] x, int n) {
175 if (n <= 0)
176 throw new IllegalArgumentException("n <= 0");
177 /*
178 * double[] parameters = new double[4]; double sum = 0; for (int i = 0; i < n;
179 * i++) { sum += x[i]; }
180 */
181 throw new UnsupportedOperationException("getMLE is not implemented");
182
183 // return parameters;
184 }
185
192 public static NormalInverseGaussianDist getInstanceFromMLE(double[] x, int n) {
193 double parameters[] = getMLE(x, n);
194 return new NormalInverseGaussianDist(parameters[0], parameters[1], parameters[2], parameters[3]);
195 }
196
205 public static double getMean(double alpha, double beta, double mu, double delta) {
206 if (delta <= 0.0)
207 throw new IllegalArgumentException("delta <= 0");
208 if (alpha <= 0.0)
209 throw new IllegalArgumentException("alpha <= 0");
210 if (Math.abs(beta) >= alpha)
211 throw new IllegalArgumentException("|beta| >= alpha");
212
213 double gamma = Math.sqrt(alpha * alpha - beta * beta);
214 return mu + delta * beta / gamma;
215 }
216
225 public static double getVariance(double alpha, double beta, double mu, double delta) {
226 if (delta <= 0.0)
227 throw new IllegalArgumentException("delta <= 0");
228 if (alpha <= 0.0)
229 throw new IllegalArgumentException("alpha <= 0");
230 if (Math.abs(beta) >= alpha)
231 throw new IllegalArgumentException("|beta| >= alpha");
232
233 double gamma = Math.sqrt(alpha * alpha - beta * beta);
234 return delta * alpha * alpha / (gamma * gamma * gamma);
235 }
236
244 public static double getStandardDeviation(double alpha, double beta, double mu, double delta) {
245 return Math.sqrt(getVariance(alpha, beta, mu, delta));
246 }
247
251 public double getAlpha() {
252 return alpha;
253 }
254
258 public double getBeta() {
259 return beta;
260 }
261
265 public double getMu() {
266 return mu;
267 }
268
272 public double getDelta() {
273 return delta;
274 }
275
281 public void setParams(double alpha, double beta, double mu, double delta) {
282 if (delta <= 0.0)
283 throw new IllegalArgumentException("delta <= 0");
284 if (alpha <= 0.0)
285 throw new IllegalArgumentException("alpha <= 0");
286 if (Math.abs(beta) >= alpha)
287 throw new IllegalArgumentException("|beta| >= alpha");
288
289 gamma = Math.sqrt(alpha * alpha - beta * beta);
290
291 this.mu = mu;
292 this.delta = delta;
293 this.beta = beta;
294 this.alpha = alpha;
295 }
296
302 public double[] getParams() {
303 double[] retour = { alpha, beta, mu, delta };
304 return retour;
305 }
306
310 public String toString() {
311 return getClass().getSimpleName() + ": alpha = " + alpha + ", beta = " + beta + ", mu = " + mu + ", delta = "
312 + delta;
313 }
314
315}
Classes implementing continuous distributions should inherit from this base class.
double[] getParams()
Returns a table containing the parameters of the current distribution.
static double getStandardDeviation(double alpha, double beta, double mu, double delta)
Computes and returns the standard deviation of the normal inverse gaussian distribution with paramete...
double cdf(double x)
Returns the distribution function .
static NormalInverseGaussianDist getInstanceFromMLE(double[] x, int n)
NOT IMPLEMENTED.
NormalInverseGaussianDist(double alpha, double beta, double mu, double delta)
Constructor for a normal inverse gaussian distribution with parameters = alpha, = beta,...
static double density(double alpha, double beta, double mu, double delta, double x)
Computes the density function ( fNormalInverseGaussian ) for the normal inverse gaussian distribution...
double getStandardDeviation()
Returns the standard deviation.
static double[] getMLE(double[] x, int n)
NOT IMPLEMENTED.
double getAlpha()
Returns the parameter of this object.
static double getVariance(double alpha, double beta, double mu, double delta)
Computes and returns the variance of the normal inverse gaussian distribution with parameters ,...
double barF(double x)
Returns the complementary distribution function.
double getMu()
Returns the parameter of this object.
double density(double x)
Returns , the density evaluated at .
double getDelta()
Returns the parameter of this object.
static double inverseF(double alpha, double beta, double mu, double delta, double u)
NOT IMPLEMENTED.
String toString()
Returns a String containing information about the current distribution.
double getBeta()
Returns the parameter of this object.
static double getMean(double alpha, double beta, double mu, double delta)
Returns the mean of the normal inverse gaussian distribution with parameters.
static double barF(double alpha, double beta, double mu, double delta, double x)
NOT IMPLEMENTED.
static double cdf(double alpha, double beta, double mu, double delta, double x)
NOT IMPLEMENTED.
void setParams(double alpha, double beta, double mu, double delta)
Sets the parameters , , and.
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static double expBesselK1(double x, double y)
Returns the value of , where is the modified Bessel function of the second kind of order 1.
Definition Num.java:909