SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NakagamiDist.java
1/*
2 * Class: NakagamiDist
3 * Description: Nakagami 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.*;
28import umontreal.ssj.functions.MathFunction;
29
45 protected double a; // Location parameter
46 protected double lambda; // Scale parameter
47 protected double c; // Shape parameter
48 private double factor;
49 private double ratio; // Gamma(c + 1/2)/Gamma(c)
50
56 public NakagamiDist(double a, double lambda, double c) {
57 setParams(a, lambda, c);
58 }
59
60 public double density(double x) {
61 if (x <= a)
62 return 0.0;
63 return 2.0 * Math.exp(factor + Math.log(x - a) * (2.0 * c - 1.0) - lambda * (x - a) * (x - a));
64 }
65
66 public double cdf(double x) {
67 return cdf(a, lambda, c, x);
68 }
69
70 public double barF(double x) {
71 return barF(a, lambda, c, x);
72 }
73
74 public double inverseF(double u) {
75 return inverseF(a, lambda, c, u);
76 }
77
78 public double getMean() {
79 return a + ratio / Math.sqrt(lambda);
80 }
81
82 public double getVariance() {
83 return (c - ratio * ratio) / lambda;
84 }
85
86 public double getStandardDeviation() {
87 return Math.sqrt(getVariance());
88 }
89
99 public static double density(double a, double lambda, double c, double x) {
100 if (lambda <= 0.0)
101 throw new IllegalArgumentException("lambda <= 0");
102 if (c <= 0.0)
103 throw new IllegalArgumentException("c <= 0");
104 if (x <= a)
105 return 0.0;
106
107 return 2.0 * Math.exp(
108 Math.log(lambda) * c - Num.lnGamma(c) + Math.log(x - a) * (2.0 * c - 1.0) - lambda * (x - a) * (x - a));
109 }
110
120 public static double cdf(double a, double lambda, double c, double x) {
121 if (lambda <= 0.0)
122 throw new IllegalArgumentException("lambda <= 0");
123 if (c <= 0.0)
124 throw new IllegalArgumentException("c <= 0");
125 if (x <= a)
126 return 0.0;
127
128 return GammaDist.cdf(c, 12, lambda * (x - a) * (x - a));
129 }
130
140 public static double barF(double a, double lambda, double c, double x) {
141 if (lambda <= 0.0)
142 throw new IllegalArgumentException("lambda <= 0");
143 if (c <= 0.0)
144 throw new IllegalArgumentException("c <= 0");
145 if (x <= a)
146 return 1.0;
147 return GammaDist.barF(c, 12, lambda * (x - a) * (x - a));
148 }
149
159 public static double inverseF(double a, double lambda, double c, double u) {
160 if (lambda <= 0.0)
161 throw new IllegalArgumentException("lambda <= 0");
162 if (c <= 0.0)
163 throw new IllegalArgumentException("c <= 0");
164 if (u > 1.0 || u < 0.0)
165 throw new IllegalArgumentException("u not in [0,1]");
166 if (u <= 0.0)
167 return a;
168 if (u >= 1.0)
169 return Double.POSITIVE_INFINITY;
170 double res = GammaDist.inverseF(c, 12, u);
171 return a + Math.sqrt(res / lambda);
172 }
173
183 public static double getMean(double a, double lambda, double c) {
184 if (lambda <= 0.0)
185 throw new IllegalArgumentException("lambda <= 0");
186 if (c <= 0.0)
187 throw new IllegalArgumentException("c <= 0");
188 return a + Num.gammaRatioHalf(c) / Math.sqrt(lambda);
189 }
190
200 public static double getVariance(double a, double lambda, double c) {
201 if (lambda <= 0.0)
202 throw new IllegalArgumentException("lambda <= 0");
203 if (c <= 0.0)
204 throw new IllegalArgumentException("c <= 0");
205 double rat = Num.gammaRatioHalf(c);
206 return (c - rat * rat) / lambda;
207 }
208
218 public static double getStandardDeviation(double a, double lambda, double c) {
219 return Math.sqrt(NakagamiDist.getVariance(a, lambda, c));
220 }
221
227 public double getA() {
228 return a;
229 }
230
236 public double getLambda() {
237 return lambda;
238 }
239
245 public double getC() {
246 return c;
247 }
248
256 public void setParams(double a, double lambda, double c) {
257 if (lambda <= 0.0)
258 throw new IllegalArgumentException("lambda <= 0");
259 if (c <= 0.0)
260 throw new IllegalArgumentException("c <= 0");
261 this.a = a;
262 this.lambda = lambda;
263 this.c = c;
264 factor = (Math.log(lambda) * c - Num.lnGamma(c));
265 ratio = Num.gammaRatioHalf(c);
266 }
267
274 public double[] getParams() {
275 double[] retour = { a, lambda, c };
276 return retour;
277 }
278
285 public String toString() {
286 return getClass().getSimpleName() + " : a = " + a + ", lambda = " + lambda + ", c = " + c;
287 }
288
289}
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 .
double barF(double x)
Returns the complementary distribution function.
double inverseF(double u)
Returns the inverse distribution function .
double getStandardDeviation()
Returns the standard deviation.
double cdf(double x)
Returns the distribution function .
static double inverseF(double a, double lambda, double c, double u)
Computes the inverse of the distribution function.
void setParams(double a, double lambda, double c)
Sets the parameters , and of this object.
double getC()
Returns the shape parameter of this object.
NakagamiDist(double a, double lambda, double c)
Constructs a NakagamiDist object with parameters a,.
static double getStandardDeviation(double a, double lambda, double c)
Computes the standard deviation of the Nakagami distribution with parameters , and .
double density(double x)
Returns , the density evaluated at .
double getA()
Returns the location parameter of this object.
static double barF(double a, double lambda, double c, double x)
Computes the complementary distribution function.
double[] getParams()
Return a table containing the parameters of the current distribution.
double getLambda()
Returns the scale parameter of this object.
static double cdf(double a, double lambda, double c, double x)
Computes the distribution function.
String toString()
Returns a String containing information about the current distribution.
static double getVariance(double a, double lambda, double c)
Computes and returns the variance.
double getVariance()
Returns the variance.
double getMean()
Returns the mean.
double barF(double x)
Returns the complementary distribution function.
static double density(double a, double lambda, double c, double x)
Computes the density function of the Nakagami distribution.
static double getMean(double a, double lambda, double c)
Computes and returns the mean.
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
static double gammaRatioHalf(double x)
Returns the value of the ratio of two gamma functions.
Definition Num.java:635