SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
JohnsonSUDist.java
1/*
2 * Class: JohnsonSUDist
3 * Description: Johnson S_U 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
55public class JohnsonSUDist extends JohnsonSystem {
56
57 private static double calcR(double a, double b, double x) {
58 /***
59 * cette fonction calcule r = z + sqrt(z*z + 1) en utilisant un algorithme
60 * stable
61 ***/
62
63 double z = (x - a) / b;
64
65 double s = Math.abs(z);
66 if (s < 1.0e20)
67 s = Math.sqrt(z * z + 1.0);
68
69 // compute r = z + sqrt (z * z + 1)
70 double r;
71 if (z >= 0.0)
72 r = s + z;
73 else
74 r = 1.0 / (s - z);
75
76 return r;
77 }
78
83 public JohnsonSUDist(double gamma, double delta) {
84 this(gamma, delta, 0, 1);
85 }
86
93 public JohnsonSUDist(double gamma, double delta, double xi, double lambda) {
94 super(gamma, delta, xi, lambda);
95 }
96
97 public double density(double x) {
98 return density(gamma, delta, xi, lambda, x);
99 }
100
101 public double cdf(double x) {
102 return cdf(gamma, delta, xi, lambda, x);
103 }
104
105 public double barF(double x) {
106 return barF(gamma, delta, xi, lambda, x);
107 }
108
109 public double inverseF(double u) {
110 return inverseF(gamma, delta, xi, lambda, u);
111 }
112
113 public double getMean() {
114 return JohnsonSUDist.getMean(gamma, delta, xi, lambda);
115 }
116
117 public double getVariance() {
118 return JohnsonSUDist.getVariance(gamma, delta, xi, lambda);
119 }
120
121 public double getStandardDeviation() {
122 return JohnsonSUDist.getStandardDeviation(gamma, delta, xi, lambda);
123 }
124
128 public static double density(double gamma, double delta, double xi, double lambda, double x) {
129 if (lambda <= 0)
130 throw new IllegalArgumentException("lambda <= 0");
131 if (delta <= 0)
132 throw new IllegalArgumentException("delta <= 0");
133 double r = calcR(xi, lambda, x);
134 if (r <= 0.0)
135 return 0.0;
136 double z = gamma + delta * Math.log(r);
137 double y = (x - xi) / lambda;
138 if (z >= 1.0e10)
139 return 0;
140 return delta / (lambda * Math.sqrt(2.0 * Math.PI) * Math.sqrt(y * y + 1.0)) * Math.exp(-z * z / 2.0);
141 }
142
146 public static double cdf(double gamma, double delta, double xi, double lambda, double x) {
147 if (lambda <= 0)
148 throw new IllegalArgumentException("lambda <= 0");
149 if (delta <= 0)
150 throw new IllegalArgumentException("delta <= 0");
151 double r = calcR(xi, lambda, x);
152 if (r > 0.0)
153 return NormalDist.cdf01(gamma + delta * Math.log(r));
154 else
155 return 0.0;
156 }
157
161 public static double barF(double gamma, double delta, double xi, double lambda, double x) {
162 if (lambda <= 0)
163 throw new IllegalArgumentException("lambda <= 0");
164 if (delta <= 0)
165 throw new IllegalArgumentException("delta <= 0");
166
167 double r = calcR(xi, lambda, x);
168 if (r > 0.0)
169 return NormalDist.barF01(gamma + delta * Math.log(r));
170 else
171 return 1.0;
172 }
173
177 public static double inverseF(double gamma, double delta, double xi, double lambda, double u) {
178 if (lambda <= 0)
179 throw new IllegalArgumentException("lambda <= 0");
180 if (delta <= 0)
181 throw new IllegalArgumentException("delta <= 0");
182 if (u > 1.0 || u < 0.0)
183 throw new IllegalArgumentException("u not in [0,1]");
184
185 if (u >= 1.0)
186 return Double.POSITIVE_INFINITY;
187 if (u <= 0.0)
188 return Double.NEGATIVE_INFINITY;
189
190 double z = NormalDist.inverseF01(u);
191 double v = (z - gamma) / delta;
192 if (v >= Num.DBL_MAX_EXP * Num.LN2)
193 return Double.POSITIVE_INFINITY;
194 if (v <= Num.LN2 * Num.DBL_MIN_EXP)
195 return Double.NEGATIVE_INFINITY;
196
197 return xi + lambda * Math.sinh(v);
198 }
199
209 public static double getMean(double gamma, double delta, double xi, double lambda) {
210 if (lambda <= 0.0)
211 throw new IllegalArgumentException("lambda <= 0");
212 if (delta <= 0.0)
213 throw new IllegalArgumentException("delta <= 0");
214
215 return (xi - (lambda * Math.exp(1.0 / (2.0 * delta * delta)) * Math.sinh(gamma / delta)));
216 }
217
229 public static double getVariance(double gamma, double delta, double xi, double lambda) {
230 if (lambda <= 0.0)
231 throw new IllegalArgumentException("lambda <= 0");
232 if (delta <= 0.0)
233 throw new IllegalArgumentException("delta <= 0");
234
235 double omega2 = Math.exp(1 / (delta * delta));
236 return ((omega2 - 1) * (omega2 * Math.cosh(2 * gamma / delta) + 1) / 2 * lambda * lambda);
237 }
238
246 public static double getStandardDeviation(double gamma, double delta, double xi, double lambda) {
247 return Math.sqrt(JohnsonSUDist.getVariance(gamma, delta, xi, lambda));
248 }
249
255 public void setParams(double gamma, double delta, double xi, double lambda) {
256 setParams0(gamma, delta, xi, lambda);
257 }
258
259}
double getVariance()
Returns the variance.
void setParams(double gamma, double delta, double xi, double lambda)
Sets the value of the parameters , ,.
double cdf(double x)
Returns the distribution function .
static double getStandardDeviation(double gamma, double delta, double xi, double lambda)
Returns the standard deviation of the Johnson distribution with parameters , , ,.
double density(double x)
Returns , the density evaluated at .
static double getVariance(double gamma, double delta, double xi, double lambda)
Returns the variance.
static double cdf(double gamma, double delta, double xi, double lambda, double x)
Returns the distribution function .
double inverseF(double u)
Returns the inverse distribution function .
double getMean()
Returns the mean.
static double inverseF(double gamma, double delta, double xi, double lambda, double u)
Returns the inverse distribution function .
static double getMean(double gamma, double delta, double xi, double lambda)
Returns the mean.
static double barF(double gamma, double delta, double xi, double lambda, double x)
Returns the complementary distribution function .
double getStandardDeviation()
Returns the standard deviation.
JohnsonSUDist(double gamma, double delta)
Same as JohnsonSUDist(gamma, delta, 0, 1).
static double density(double gamma, double delta, double xi, double lambda, double x)
Returns the density function .
double barF(double x)
Returns the complementary distribution function.
JohnsonSUDist(double gamma, double delta, double xi, double lambda)
Constructs a JohnsonSUDist object with shape parameters.
void setParams0(double gamma, double delta, double xi, double lambda)
Sets the value of the parameters , ,.
JohnsonSystem(double gamma, double delta, double xi, double lambda)
Constructs a JohnsonSystem object with shape parameters.
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a  (page 80)).
static double inverseF01(double u)
Same as inverseF(0, 1, u).
static double cdf01(double x)
Same as cdf(0, 1, x).
static double barF01(double x)
Same as barF(0, 1, x).
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static final int DBL_MIN_EXP
Smallest int such that is representable (approximately) as a normalised double.
Definition Num.java:102
static final int DBL_MAX_EXP
Largest int such that is representable (approximately) as a double.
Definition Num.java:96
static final double LN2
The values of .
Definition Num.java:148