SSJ
V. 1.1.9.

umontreal.iro.lecuyer.probdist
Class BinomialDist

java.lang.Object
  extended by umontreal.iro.lecuyer.probdist.DiscreteDistributionInt
      extended by umontreal.iro.lecuyer.probdist.BinomialDist

public class BinomialDist
extends DiscreteDistributionInt

Extends the class DiscreteDistributionInt for the binomial distribution with parameters n and p, where n is a positive integer and 0 <= p <= 1. Its mass function is given by

p(x) = nCr(n, x)px(1 - p)n-x = n!/[x!(n - x)!]  px(1 - p)n-x        for x = 0, 1, 2,…n,

and its distribution function is

F(x) = ∑j=0xnCr(n, j)  pj(1 - p)n-j        for x = 0, 1, 2,…n,

where nCr(n, x) is the number of possible combinations of x elements chosen among a set of n elements.


Field Summary
static double MAXN
           
 
Fields inherited from class umontreal.iro.lecuyer.probdist.DiscreteDistributionInt
EPSILON
 
Constructor Summary
BinomialDist(int n, double p)
          Creates an object that contains the binomial terms, for 0 <= x <= n, and the corresponding cumulative function.
 
Method Summary
 double barF(int x)
          Returns bar(F)(x), the complementary distribution function.
 double cdf(int x)
          Returns the distribution function F evaluated at x (see).
static double cdf(int n, double p, int x)
          Computes F(x), the distribution function of a binomial random variable with parameters n and p, evaluated at x.
 int getN()
          Returns the parameter n of this object.
 double getP()
          Returns the parameter p of this object.
 int inverseF(double u)
          Returns the inverse distribution function F-1(u), where 0 <= u <= 1.
static int inverseF(int n, double p, double u)
          Computes the inverse of the binomial distribution, x = F-1(u), using a linear search starting at the mode if n is small.
 double prob(int x)
          Returns p(x), the probability of x, which should be a real number in the interval [0, 1].
static double prob(int n, double p, double q, int x)
          A generalization of the previous method.
static double prob(int n, double p, int x)
          Computes and returns the mass function p(x).
 void setParams(int n, double p)
          Resets the parameters to these new values and recomputes everything as in the constructor.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXN

public static double MAXN
Constructor Detail

BinomialDist

public BinomialDist(int n,
                    double p)
Creates an object that contains the binomial terms, for 0 <= x <= n, and the corresponding cumulative function. These values are computed and stored in dynamic arrays, unless n exceeds MAXN.

Method Detail

prob

public double prob(int x)
Description copied from class: DiscreteDistributionInt
Returns p(x), the probability of x, which should be a real number in the interval [0, 1].

Specified by:
prob in class DiscreteDistributionInt
Parameters:
x - value at which the mass function must be evaluated
Returns:
the mass function evaluated at x

cdf

public double cdf(int x)
Description copied from class: DiscreteDistributionInt
Returns the distribution function F evaluated at x (see).

Specified by:
cdf in class DiscreteDistributionInt
Parameters:
x - value at which the distribution function must be evaluated
Returns:
the distribution function evaluated at x

barF

public double barF(int x)
Description copied from class: DiscreteDistributionInt
Returns bar(F)(x), the complementary distribution function.

Overrides:
barF in class DiscreteDistributionInt
Parameters:
x - value at which the complementary distribution function must be evaluated
Returns:
the complementary distribution function evaluated at x

inverseF

public int inverseF(double u)
Description copied from class: DiscreteDistributionInt
Returns the inverse distribution function F-1(u), where 0 <= u <= 1. The default implementation uses binary search.

Overrides:
inverseF in class DiscreteDistributionInt
Parameters:
u - value in the interval (0, 1) for which the inverse distribution function is evaluated
Returns:
the inverse distribution function evaluated at u

prob

public static double prob(int n,
                          double p,
                          int x)
Computes and returns the mass function p(x).


prob

public static double prob(int n,
                          double p,
                          double q,
                          int x)
A generalization of the previous method. Computes and returns the binomial term f (x) = (n!/x!(n-x)!)pxqn-x, where p and q are arbitrary real numbers (q is not necessarily equal to 1 - p). In the case where 0 <= p <= 1 and q = 1 - p, the returned value is a probability term for the binomial distribution.


cdf

public static double cdf(int n,
                         double p,
                         int x)
Computes F(x), the distribution function of a binomial random variable with parameters n and p, evaluated at x.


inverseF

public static int inverseF(int n,
                           double p,
                           double u)
Computes the inverse of the binomial distribution, x = F-1(u), using a linear search starting at the mode if n is small. If n is larger than 10000, the linear search starts from 0 and the cdf static method is used to compute F(x) at different values of x, which much is less efficient.


getN

public int getN()
Returns the parameter n of this object.


getP

public double getP()
Returns the parameter p of this object.


setParams

public void setParams(int n,
                      double p)
Resets the parameters to these new values and recomputes everything as in the constructor. From the performance viewpoint, it is essentially the same as constructing a new BinomialDist object.


SSJ
V. 1.1.9.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.