SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
RayleighDist.java
1/*
2 * Class: RayleighDist
3 * Description: Rayleigh 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
48 private double a;
49 private double beta;
50
56 public RayleighDist(double beta) {
57 setParams(0.0, beta);
58 }
59
64 public RayleighDist(double a, double beta) {
65 setParams(a, beta);
66 }
67
68 public double density(double x) {
69 return density(a, beta, x);
70 }
71
72 public double cdf(double x) {
73 return cdf(a, beta, x);
74 }
75
76 public double barF(double x) {
77 return barF(a, beta, x);
78 }
79
80 public double inverseF(double u) {
81 return inverseF(a, beta, u);
82 }
83
84 public double getMean() {
85 return RayleighDist.getMean(a, beta);
86 }
87
88 public double getVariance() {
89 return RayleighDist.getVariance(beta);
90 }
91
92 public double getStandardDeviation() {
93 return RayleighDist.getStandardDeviation(beta);
94 }
95
105 public static double density(double a, double beta, double x) {
106 if (beta <= 0.0)
107 throw new IllegalArgumentException("beta <= 0");
108 if (x <= a)
109 return 0.0;
110 final double Z = (x - a) / beta;
111 return Z / beta * Math.exp(-Z * Z / 2.0);
112 }
113
121 public static double density(double beta, double x) {
122 return density(0.0, beta, x);
123 }
124
134 public static double cdf(double a, double beta, double x) {
135 if (beta <= 0.0)
136 throw new IllegalArgumentException("beta <= 0");
137 if (x <= a)
138 return 0.0;
139 final double Z = (x - a) / beta;
140 if (Z >= 10.0)
141 return 1.0;
142 return -Math.expm1(-Z * Z / 2.0);
143 }
144
152 public static double cdf(double beta, double x) {
153 return cdf(0.0, beta, x);
154 }
155
164 public static double barF(double a, double beta, double x) {
165 if (beta <= 0.0)
166 throw new IllegalArgumentException("beta <= 0");
167 if (x <= a)
168 return 1.0;
169 double z = (x - a) / beta;
170 if (z >= 44.0)
171 return 0.0;
172 return Math.exp(-z * z / 2.0);
173 }
174
182 public static double barF(double beta, double x) {
183 return barF(0.0, beta, x);
184 }
185
195 public static double inverseF(double a, double beta, double u) {
196 if (beta <= 0.0)
197 throw new IllegalArgumentException("beta <= 0");
198 if (u < 0.0 || u > 1.0)
199 throw new IllegalArgumentException("u not in [0, 1]");
200 if (u <= 0.0)
201 return a;
202 if (u >= 1.0)
203 return Double.POSITIVE_INFINITY;
204
205 return a + beta * Math.sqrt(-2.0 * Math.log1p(-u));
206 }
207
215 public static double inverseF(double beta, double u) {
216 return inverseF(0.0, beta, u);
217 }
218
233 public static double[] getMLE(double[] x, int n, double a) {
234 if (n <= 0)
235 throw new IllegalArgumentException("n <= 0");
236
237 double somme = 0;
238 for (int i = 0; i < n; ++i)
239 somme += (x[i] - a) * (x[i] - a);
240
241 double[] parametres = new double[1];
242 parametres[0] = Math.sqrt(somme / (2.0 * n));
243 return parametres;
244 }
245
256 public static RayleighDist getInstanceFromMLE(double[] x, int n, double a) {
257 double parameters[] = getMLE(x, n, a);
258 return new RayleighDist(parameters[0], parameters[1]);
259 }
260
269 public static double getMean(double a, double beta) {
270 if (beta <= 0.0)
271 throw new IllegalArgumentException("beta <= 0");
272 return (a + beta * Math.sqrt(Math.PI / 2.0));
273 }
274
281 public static double getVariance(double beta) {
282 if (beta == 0.0)
283 throw new IllegalArgumentException("beta = 0");
284 return (2.0 - 0.5 * Math.PI) * beta * beta;
285 }
286
294 public static double getStandardDeviation(double beta) {
295 return Math.sqrt(RayleighDist.getVariance(beta));
296 }
297
303 public double getA() {
304 return a;
305 }
306
312 public double getSigma() {
313 return beta;
314 }
315
322 public void setParams(double a, double beta) {
323 if (beta <= 0.0)
324 throw new IllegalArgumentException("beta <= 0");
325 this.a = a;
326 this.beta = beta;
327 supportA = a;
328 }
329
336 public double[] getParams() {
337 double[] retour = { a, beta };
338 return retour;
339 }
340
346 public String toString() {
347 return getClass().getSimpleName() + " : a = " + a + ", beta = " + beta;
348 }
349
350}
Classes implementing continuous distributions should inherit from this base class.
static double inverseF(double beta, double u)
Same as inverseF (0, beta, u).
RayleighDist(double a, double beta)
Constructs a RayleighDist object with parameters a, and = beta.
static RayleighDist getInstanceFromMLE(double[] x, int n, double a)
Creates a new instance of a Rayleigh distribution with parameters.
static double barF(double beta, double x)
Same as barF (0, beta, x).
static double[] getMLE(double[] x, int n, double a)
Estimates the parameter of the Rayleigh distribution using the maximum likelihood method,...
void setParams(double a, double beta)
Sets the parameters and for this object.
String toString()
Returns a String containing information about the current distribution.
double getStandardDeviation()
Returns the standard deviation.
double barF(double x)
Returns the complementary distribution function.
static double getVariance(double beta)
Returns the variance of the Rayleigh distribution with parameter.
RayleighDist(double beta)
Constructs a RayleighDist object with parameters and.
double getMean()
Returns the mean.
static double density(double beta, double x)
Same as density (0, beta, x).
double density(double x)
Returns , the density evaluated at .
static double density(double a, double beta, double x)
Computes the density function ( frayleigh ).
static double inverseF(double a, double beta, double u)
Computes the inverse of the distribution function ( Invrayleigh ).
static double barF(double a, double beta, double x)
Computes the complementary distribution function.
static double getMean(double a, double beta)
Returns the mean of the Rayleigh distribution with parameters and .
static double getStandardDeviation(double beta)
Returns the standard deviation of the Rayleigh distribution with parameter .
static double cdf(double beta, double x)
Same as cdf (0, beta, x).
double getA()
Returns the parameter .
double getVariance()
Returns the variance.
static double cdf(double a, double beta, double x)
Computes the distribution function ( Frayleigh ).
double[] getParams()
Return an array containing the parameters of the current distribution in the order: [ ,...
double getSigma()
Returns the parameter .
double cdf(double x)
Returns the distribution function .
double inverseF(double u)
Returns the inverse distribution function .