umontreal.iro.lecuyer.randvar.NegativeBinomialGen Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ssj Show documentation
Show all versions of ssj Show documentation
SSJ is a Java library for stochastic simulation, developed under the direction of Pierre L'Ecuyer,
in the Département d'Informatique et de Recherche Opérationnelle (DIRO), at the Université de Montréal.
It provides facilities for generating uniform and nonuniform random variates, computing different
measures related to probability distributions, performing goodness-of-fit tests, applying quasi-Monte
Carlo methods, collecting (elementary) statistics, and programming discrete-event simulations with both
events and processes.
The newest version!
/*
* Class: NegativeBinomialGen
* Description: random variate generators for the negative binomial distribution
* Environment: Java
* Software: SSJ
* Copyright (C) 2001 Pierre L'Ecuyer and Université de Montréal
* Organization: DIRO, Université de Montréal
* @author
* @since
* SSJ is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License (GPL) as published by the
* Free Software Foundation, either version 3 of the License, or
* any later version.
* SSJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* A copy of the GNU General Public License is available at
GPL licence site.
*/
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;
}
}