26package umontreal.ssj.randvar;
28import umontreal.ssj.util.Num;
29import umontreal.ssj.rng.*;
30import umontreal.ssj.probdist.*;
50 private static final int b00 = 2;
51 private static final int b01 = 3;
52 private static final int b01inv = 4;
53 private static final int b1prs = 5;
95 setParams(alpha, beta, 0.0, 1.0);
105 this(s, s, alpha, beta);
119 setParams(alpha, beta, a, b);
130 this(s, s, alpha, beta, a, b);
142 setParams(dist.getAlpha(), dist.getBeta(), dist.getA(), dist.getB());
169 double U, V, Z, W, Y;
175 U = stream.nextDouble() * p2;
178 Z = Math.exp(Math.log(U / p1) / p);
181 V = stream.nextDouble() * fq;
182 if (V <= 1. - q_ * X)
185 if (V <= 1. + (fq - 1.) * Z) {
187 if (Math.log(V) <= q_ * Math.log(1. - X))
191 Z = Math.exp(Math.log((U - p1) / (p2 - p1)) / q);
192 X = 1. - (1. - t) * Z;
194 V = stream.nextDouble() * fp;
195 if (V <= 1.0 - p_ * (1. - X))
198 if (V <= 1.0 + (fp - 1.) * Z) {
200 if (Math.log(V) <= p_ * Math.log(X))
211 U = stream.nextDouble() * p2;
214 Z = Math.exp(Math.log(U / p1) / pint);
217 V = stream.nextDouble();
218 if (V <= 1. - ml * X)
221 if (V <= 1. - mu * Z)
223 if (Math.log(V) <= q_ * Math.log(1. - X))
226 Z = Math.exp(Math.log((U - p1) / (p2 - p1)) / qint);
227 X = 1. - (1. - t) * Z;
229 V = stream.nextDouble() * fp;
230 if (V <= 1. - p_ * (1. - X))
233 if (V <= 1. + (fp - 1.) * Z)
235 if (Math.log(V) <= p_ * Math.log(X))
246 U = stream.nextDouble() * p4;
257 X = x2 - W / f1 * Dl;
261 U = stream.nextDouble();
266 if (W * (x2 - z2) <= f2 * (X - z2))
271 if (V <= f2 + (1. - f2) * U) {
276 if (V <= Math.exp(p_ * Math.log(Y / m) + q_ * Math.log((10. - Y) / (1.0 - m)))) {
281 }
else if (U <= p2) {
295 U = stream.nextDouble();
300 if (W * (z4 - x4) <= f4 * (z4 - X))
305 if (V <= f4 + (1.0 - f4) * U) {
310 if (V <= Math.exp(p_ * Math.log(Y / m) + q_ * Math.log((1.0 - Y) / (1.0 - m)))) {
315 }
else if (U <= p3) {
316 U = (U - p2) / (p3 - p2);
321 W = U * stream.nextDouble();
328 U = (U - p3) / (p4 - p3);
333 W = U * stream.nextDouble();
341 if (Math.log(W) <= p_ * Math.log(X / m) + q_ * Math.log((1.0 - X) / (1.0 - m)))
347 throw new IllegalStateException();
350 return gen == b01inv ? a + (b - a) * (1.0 - X) : a + (b - a) * X;
357 private void init() {
380 c = (q * q_) / (p * p_);
381 t = (c == 1.) ? 0.5 : (1. - Math.sqrt(c)) / (1. - c);
382 fp = Math.exp(p_ * Math.log(t));
383 fq = Math.exp(q_ * Math.log(1. - t));
386 p2 = (1. - t) / q + p1;
404 t = p_ / (pint - qint);
405 fq = Math.exp((q_ - 1.) * Math.log(1. - t));
406 fp = pint - (pint + q_) * t;
407 t -= (t - (1. - fp) * (1. - t) * fq / qint) / (1. - fp * fq);
408 fp = Math.exp(p_ * Math.log(t));
409 fq = Math.exp(q_ * Math.log(1. - t));
418 p2 = fq * (1. - t) / qint + p1;
428 if (p_ > 1.0 || q_ > 1.0)
429 D = Math.sqrt(m * (1. - m) / (s - 1.0));
433 x1 = z2 = f1 = ll = 0.0;
437 z2 = x2 * (1.0 - (1.0 - x2) / (s * D));
438 if (x1 <= 0.0 || (s - 6.0) * x2 - p_ + 3.0 > 0.0) {
445 f1 = Math.exp(p_ * Math.log(x1 / m) + q_ * Math.log((1.0 - x1) / (1.0 - m)));
446 ll = x1 * (1.0 - x1) / (s * (m - x1));
448 f2 = Math.exp(p_ * Math.log(x2 / m) + q_ * Math.log((1.0 - x2) / (1.0 - m)));
458 z4 = x4 * (1.0 + (1.0 - x4) / (s * D));
459 if (x5 >= 1.0 || (s - 6.0) * x4 - p_ + 3.0 < 0.0) {
464 f5 = Math.exp(p_ * Math.log(x5 / m) + q_ * Math.log((1.0 - x5) / (1. - m)));
465 lr = x5 * (1.0 - x5) / (s * (x5 - m));
467 f4 = Math.exp(p_ * Math.log(x4 / m) + q_ * Math.log((1.0 - x4) / (1.0 - m)));
470 p2 = f4 * (D + D) + p1;
476 throw new IllegalStateException();
480 private static boolean equalsDouble(
double a,
double b) {
483 double absa = Math.abs(a);
484 double absb = Math.abs(b);
485 return Math.abs(a - b) <= Math.min(absa, absb) * Num.DBL_EPSILON;
Extends the class ContinuousDistribution for the beta distribution.
double inverseF(double u)
Returns the inverse distribution function .
BetaGen(RandomStream s, double alpha, double beta, double a, double b)
Creates a new beta generator with parameters alpha and beta, over the interval.
BetaStratifiedRejectionGen(RandomStream s, RandomStream aux, double alpha, double beta, double a, double b)
Creates a beta random variate generator with parameters.
BetaStratifiedRejectionGen(RandomStream s, RandomStream aux, double alpha, double beta)
Creates a beta random variate generator with parameters alpha and beta, over the interval ,...
RandomStream getAuxStream()
Returns the auxiliary stream associated with this object.
static double nextDouble(RandomStream s, double alpha, double beta, double a, double b)
Generates a variate from the beta distribution with parameters.
BetaStratifiedRejectionGen(RandomStream s, RandomStream aux, BetaDist dist)
Creates a new generator for the distribution dist, using the given stream s and auxiliary stream aux.
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
BetaStratifiedRejectionGen(RandomStream s, double alpha, double beta, double a, double b)
Creates a beta random variate generator with parameters.
BetaStratifiedRejectionGen(RandomStream s, BetaDist dist)
Same as BetaStratifiedRejectionGen(s, s,dist).
BetaStratifiedRejectionGen(RandomStream s, double alpha, double beta)
Creates a beta random variate generator with parameters alpha and beta, over the interval ,...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...