package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
/**
* This class implements random variate generators having the
* negative binomial distribution. Its mass function is
*
*
*
* where Γ is the gamma function,
*
* γ > 0 and
* 0 <= p <= 1.
* No local copy of the parameters γ and p is maintained in this class.
* The (non-static) nextInt method simply calls inverseF on the
* distribution.
*
*/
public class NegativeBinomialGen extends RandomVariateGenInt {
protected double gamma;
protected double p;
/**
* Creates a negative binomial random variate generator with parameters
* γ = gamma and p, using stream s.
*
*/
public NegativeBinomialGen (RandomStream s, double gamma, double p) {
super (s, new NegativeBinomialDist (gamma, p));
setParams (gamma, p);
}
/**
* Creates a new generator for the distribution dist, using
* stream s.
*
*/
public NegativeBinomialGen (RandomStream s, NegativeBinomialDist dist) {
super (s, dist);
if (dist != null)
setParams (dist.getGamma(), dist.getP());
}
/**
* Generates a new variate from the negative binomial distribution,
* with parameters γ = gamma and p = p,
* using stream s.
*
*/
public static int nextInt (RandomStream s, double gamma, double p) {
return NegativeBinomialDist.inverseF (gamma, p, s.nextDouble());
}
/**
* Returns the parameter γ of this object.
*
*/
public double getGamma() {
return gamma;
}
/**
* Returns the parameter p of this object.
*
*
*/
public double getP() {
return p;
}
/**
* Sets the parameter γ and p of this object.
*
*/
protected void setParams (double gamma, double p) {
if (p < 0.0 || p > 1.0)
throw new IllegalArgumentException ("p not in [0, 1]");
if (gamma <= 0.0)
throw new IllegalArgumentException ("gamma <= 0");
this.p = p;
this.gamma = gamma;
}
}
Ads help maintain this website.