SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
GammaRejectionLoglogisticGen.java
1/*
2 * Class: GammaRejectionLoglogisticGen
3 * Description: gamma random variate generators using a rejection method
4 with log-logistic envelopes
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
43
44 private RandomStream auxStream;
45
46 // UNURAN parameters for the distribution
47 private double beta;
48 private double gamma;
49 // Generator parameters
50 // Rejection with log-logistic envelopes
51 private double aa;
52 private double bb;
53 private double cc;
54
63 public GammaRejectionLoglogisticGen(RandomStream s, RandomStream aux, double alpha, double lambda) {
64 super(s, null);
65 auxStream = aux;
66 setParams(alpha, lambda);
67 beta = 1.0 / lambda;
68 gamma = 0.0;
69 init();
70 }
71
77 public GammaRejectionLoglogisticGen(RandomStream s, double alpha, double lambda) {
78 this(s, s, alpha, lambda);
79 }
80
87 super(s, dist);
88 auxStream = aux;
89 if (dist != null)
90 setParams(dist.getAlpha(), dist.getLambda());
91 beta = 1.0 / dist.getLambda();
92 gamma = 0.0;
93 init();
94 }
95
101 this(s, s, dist);
102 }
103
108 return auxStream;
109 }
110
111 public double nextDouble() {
112 return rejectionLogLogistic(stream, auxStream, alpha, beta, gamma, aa, bb, cc);
113 }
114
120 public static double nextDouble(RandomStream s, RandomStream aux, double alpha, double lambda) {
121 double aa, bb, cc;
122
123 // Code taken from UNURAN
124 aa = (alpha > 1.0) ? Math.sqrt(alpha + alpha - 1.0) : alpha;
125 bb = alpha - 1.386294361;
126 cc = alpha + aa;
127
128 return rejectionLogLogistic(s, aux, alpha, 1.0 / lambda, 0.0, aa, bb, cc);
129 }
130
134 public static double nextDouble(RandomStream s, double alpha, double lambda) {
135 return nextDouble(s, s, alpha, lambda);
136 }
137
138 private static double rejectionLogLogistic(RandomStream stream, RandomStream auxStream, double alpha, double beta,
139 double gamma, double aa, double bb, double cc) {
140 // Code taken from UNURAN
141 double X;
142 double u1, u2, v, r, z;
143
144 while (true) {
145 u1 = stream.nextDouble();
146 u2 = stream.nextDouble();
147 stream = auxStream;
148 v = Math.log(u1 / (1.0 - u1)) / aa;
149 X = alpha * Math.exp(v);
150 r = bb + cc * v - X;
151 z = u1 * u1 * u2;
152 if (r + 2.504077397 >= 4.5 * z)
153 break;
154 if (r >= Math.log(z))
155 break;
156 }
157
158 return gamma + beta * X;
159 }
160
161 private void init() {
162 // Code taken from UNURAN
163 aa = (alpha > 1.0) ? Math.sqrt(alpha + alpha - 1.0) : alpha;
164 bb = alpha - 1.386294361;
165 cc = alpha + aa;
166 }
167
168}
Extends the class ContinuousDistribution for the gamma distribution tjoh95a  (page 337) with shape pa...
GammaGen(RandomStream s, double alpha, double lambda)
Creates a gamma random variate generator with parameters.
Definition GammaGen.java:56
void setParams(double alpha, double lambda)
Sets the parameter and of this object.
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
GammaRejectionLoglogisticGen(RandomStream s, RandomStream aux, GammaDist dist)
Creates a new generator object for the gamma distribution dist, using main stream s and auxiliary str...
GammaRejectionLoglogisticGen(RandomStream s, RandomStream aux, double alpha, double lambda)
Creates a gamma random variate generator with parameters.
RandomStream getAuxStream()
Returns the auxiliary stream associated with this object.
GammaRejectionLoglogisticGen(RandomStream s, double alpha, double lambda)
Creates a gamma random variate generator with parameters.
static double nextDouble(RandomStream s, double alpha, double lambda)
Same as nextDouble(s, s, alpha, lambda).
GammaRejectionLoglogisticGen(RandomStream s, GammaDist dist)
Creates a new generator object for the gamma distribution dist and stream s for both the main and aux...
static double nextDouble(RandomStream s, RandomStream aux, double alpha, double lambda)
Generates a new gamma variate with parameters  alpha and  lambda, using main stream s and auxiliary...
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,...