SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NormalKindermannRamageGen.java
1/*
2 * Class: NormalKindermannRamageGen
3 * Description: normal random variate generators using the Kindermann-Ramage method
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.randvar;
26
27import umontreal.ssj.rng.*;
28import umontreal.ssj.probdist.*;
29
43
48 public NormalKindermannRamageGen(RandomStream s, double mu, double sigma) {
49 super(s, null);
50 setParams(mu, sigma);
51 }
52
58 this(s, 0.0, 1.0);
59 }
60
66 super(s, dist);
67 if (dist != null)
68 setParams(dist.getMu(), dist.getSigma());
69 }
70
71 public double nextDouble() {
72 return kindermanRamage(stream, mu, sigma);
73 }
74
80 public static double nextDouble(RandomStream s, double mu, double sigma) {
81 return kindermanRamage(s, mu, sigma);
82 }
83//>>>>>>>>>>>>>>>>>>>> P R I V A T E S M E T H O D S <<<<<<<<<<<<<<<<<<<<
84
85 private static double kindermanRamage(RandomStream stream, double mu, double sigma) {
86 final double XI = 2.216035867166471;
87 final double PIhochK = 0.3989422804;
88 double U, V, W, X;
89 double t, z;
90
91 U = stream.nextDouble();
92 if (U < 0.884070402298758) {
93 V = stream.nextDouble();
94 X = XI * (1.131131635444180 * U + V - 1.);
95 }
96
97 else if (U >= 0.973310954173898) {
98 do {
99 V = stream.nextDouble();
100 W = stream.nextDouble();
101 if (W == 0.) {
102 t = 0.;
103 continue;
104 }
105 t = XI * XI / 2. - Math.log(W);
106 } while ((V * V * t) > (XI * XI / 2.));
107 X = (U < 0.986655477086949) ? Math.pow(2 * t, 0.5) : -Math.pow(2 * t, 0.5);
108 }
109
110 else if (U >= 0.958720824790463) {
111 do {
112 V = stream.nextDouble();
113 W = stream.nextDouble();
114 z = V - W;
115 t = XI - 0.630834801921960 * Math.min(V, W);
116 } while (Math.max(V, W) > 0.755591531667601 && 0.034240503750111
117 * Math.abs(z) > (PIhochK * Math.exp(t * t / (-2.)) - 0.180025191068563 * (XI - Math.abs(t))));
118 X = (z < 0) ? t : -t;
119 }
120
121 else if (U >= 0.911312780288703) {
122 do {
123 V = stream.nextDouble();
124 W = stream.nextDouble();
125 z = V - W;
126 t = 0.479727404222441 + 1.105473661022070 * Math.min(V, W);
127 } while (Math.max(V, W) > 0.872834976671790 && 0.049264496373128
128 * Math.abs(z) > (PIhochK * Math.exp(t * t / (-2)) - 0.180025191068563 * (XI - Math.abs(t))));
129 X = (z < 0) ? t : -t;
130 }
131
132 else {
133 do {
134 V = stream.nextDouble();
135 W = stream.nextDouble();
136 z = V - W;
137 t = 0.479727404222441 - 0.595507138015940 * Math.min(V, W);
138 if (t < 0.0)
139 continue;
140 } while (Math.max(V, W) > 0.805777924423817 && 0.053377549506886
141 * Math.abs(z) > (PIhochK * Math.exp(t * t / (-2)) - 0.180025191068563 * (XI - Math.abs(t))));
142 X = (z < 0) ? t : -t;
143 }
144
145 return mu + sigma * X;
146 }
147}
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a  (page 80)).
void setParams(double mu, double sigma)
Sets the parameters and of this object.
NormalGen(RandomStream s, double mu, double sigma)
Creates a normal random variate generator with mean mu and standard deviation sigma,...
static double nextDouble(RandomStream s, double mu, double sigma)
Generates a variate from the normal distribution with parameters &#160;mu and &#160;sigma,...
NormalKindermannRamageGen(RandomStream s)
Creates a standard normal random variate generator with mean 0 and standard deviation 1,...
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
NormalKindermannRamageGen(RandomStream s, NormalDist dist)
Creates a random variate generator for the normal distribution dist and stream s.
NormalKindermannRamageGen(RandomStream s, double mu, double sigma)
Creates a normal random variate generator with mean mu and standard deviation sigma,...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...