25package umontreal.ssj.randvar;
27import umontreal.ssj.rng.*;
28import umontreal.ssj.probdist.*;
29import umontreal.ssj.util.Num;
52 private static final double default_theta_limit = 0.96;
54 private double theta_limit = default_theta_limit;
66 this(s, theta, default_theta_limit);
87 this(s, dist, default_theta_limit);
98 theta = dist.getTheta();
102 private void init() {
103 if (theta <= 0.0 || theta >= 1.0)
104 throw new IllegalArgumentException(
"theta not in (0, 1)");
105 if (theta >= theta_limit)
106 h = Math.log1p(-theta);
108 t = -theta / Math.log1p(-theta);
112 if (theta < theta_limit)
113 return ls(stream, theta, t);
115 return lk(stream, theta, h);
123 if (theta < default_theta_limit)
124 return ls(s, theta, -theta / Math.log1p(-theta));
126 return lk(s, theta, Math.log1p(-theta));
131 private static int ls(
RandomStream stream,
double theta,
double t) {
140 p *= theta * ((double) x - 1.0) / ((double) x);
145 private static int lk(
RandomStream stream,
double theta,
double h) {
153 q = 1.0 - Math.exp(v * h);
155 x = (int) (1. + (Math.log(u) / Math.log(q)));
158 return ((u > q) ? 1 : 2);
Extends the class DiscreteDistributionInt for the logarithmic distribution.
double getTheta()
Returns the associated with this object.
double getTheta0()
Returns the associated with this object.
LogarithmicGen(RandomStream s, double theta, double theta0)
Creates a logarithmic random variate generator with parameters.
LogarithmicGen(RandomStream s, LogarithmicDist dist, double theta0)
Creates a new generator with distribution dist and stream s, with .
LogarithmicGen(RandomStream s, LogarithmicDist dist)
Creates a new generator with distribution dist and stream s, with default value .
LogarithmicGen(RandomStream s, double theta)
Creates a logarithmic random variate generator with parameters.
int nextInt()
Generates a random number (an integer) from the discrete distribution contained in this object.
static int nextInt(RandomStream s, double theta)
Uses stream s to generate a new variate from the logarithmic distribution with parameter theta.
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,...