SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NormalACRGen.java
1/*
2 * Class: NormalACRGen
3 * Description: normal random variate generators using the
4 acceptance-complement ratio method
5 * Environment: Java
6 * Software: SSJ
7 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
8 * Organization: DIRO, Universite de Montreal
9 * @author
10 * @since
11 *
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 */
26package umontreal.ssj.randvar;
27
28import umontreal.ssj.rng.*;
29import umontreal.ssj.probdist.*;
30
40public class NormalACRGen extends NormalGen {
41
46 public NormalACRGen(RandomStream s, double mu, double sigma) {
47 super(s, null);
48 setParams(mu, sigma);
49 }
50
56 this(s, 0.0, 1.0);
57 }
58
64 super(s, dist);
65 if (dist != null)
66 setParams(dist.getMu(), dist.getSigma());
67 }
68
69 public double nextDouble() {
70 return nextDouble(stream, mu, sigma);
71 }
72
78 public static double nextDouble(RandomStream s, double mu, double sigma) {
79 /*****************************************************************************
80 * SAMPLING A RANDOM NUMBER FROM THE STANDARD NORMAL DISTRIBUTION N(0,1).
81 * ---------------------------------------------------------------------------
82 * GENERATION METHOD : Acceptance-Complement Ratio
83 * ---------------------------------------------------------------------------
84 * REFERENCE : - UNURAN (c) 2000 W. Hoermann & J. Leydold, Institut f.
85 * Statistik, WU Wien
86 *
87 * - W. Hoermann and G. Derflinger (1990): The ACR Method for generating normal
88 * random variables, OR Spektrum 12 (1990), 181-185.
89 *****************************************************************************/
90 final double c1 = 1.448242853;
91 final double c2 = 3.307147487;
92 final double c3 = 1.46754004;
93 final double d1 = 1.036467755;
94 final double d2 = 5.295844968;
95 final double d3 = 3.631288474;
96 final double hm = 0.483941449;
97 final double zm = 0.107981933;
98 final double hp = 4.132731354;
99 final double zp = 18.52161694;
100 final double phln = 0.4515827053;
101 final double hm1 = 0.516058551;
102 final double hp1 = 3.132731354;
103 final double hzm = 0.375959516;
104 final double hzmp = 0.591923442;
105 final double as = 0.8853395638;
106 final double bs = 0.2452635696;
107 final double cs = 0.2770276848;
108 final double b = 0.5029324303;
109 final double x0 = 0.4571828819;
110 final double ym = 0.187308492;
111 final double ss = 0.7270572718;
112 final double t = 0.03895759111;
113
114 double X;
115 double rn, x, y, z;
116
117 do {
118 y = s.nextDouble();
119 if (y > hm1) {
120 X = hp * y - hp1;
121 break;
122 } else if (y < zm) {
123 rn = zp * y - 1;
124 X = (rn > 0) ? (1 + rn) : (-1 + rn);
125 break;
126 } else if (y < hm) {
127 rn = s.nextDouble();
128 rn = rn - 1 + rn;
129 z = (rn > 0) ? 2 - rn : -2 - rn;
130 if ((c1 - y) * (c3 + Math.abs(z)) < c2) {
131 X = z;
132 break;
133 } else {
134 x = rn * rn;
135 if ((y + d1) * (d3 + x) < d2) {
136 X = rn;
137 break;
138 } else if (hzmp - y < Math.exp(-(z * z + phln) / 2)) {
139 X = z;
140 break;
141 } else if (y + hzm < Math.exp(-(x + phln) / 2)) {
142 X = rn;
143 break;
144 }
145 }
146 }
147
148 while (true) {
149 x = s.nextDouble();
150 y = ym * s.nextDouble();
151 z = x0 - ss * x - y;
152 if (z > 0)
153 rn = 2 + y / x;
154 else {
155 x = 1 - x;
156 y = ym - y;
157 rn = -(2 + y / x);
158 }
159 if ((y - as + x) * (cs + x) + bs < 0) {
160 X = rn;
161 break;
162 } else if (y < x + t)
163 if (rn * rn < 4 * (b - Math.log(x))) {
164 X = rn;
165 break;
166 }
167 }
168
169 } while (false);
170
171 return mu + sigma * X;
172
173 }
174}
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a  (page 80)).
static double nextDouble(RandomStream s, double mu, double sigma)
Generates a variate from the normal distribution with parameters &#160;mu and &#160;sigma,...
NormalACRGen(RandomStream s, NormalDist dist)
Creates a random variate generator for the normal distribution dist and stream s.
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
NormalACRGen(RandomStream s, double mu, double sigma)
Creates a normal random variate generator with mean mu and standard deviation sigma,...
NormalACRGen(RandomStream s)
Creates a standard normal random variate generator with mean 0 and standard deviation 1,...
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,...
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,...