|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectsim.util.distribution.AbstractDistribution
sim.util.distribution.AbstractDiscreteDistribution
sim.util.distribution.Binomial
public class Binomial
Binomial distribution; See the math definition and animated definition.
p(x) = k * p^k * (1-p)^(n-k) with k = n! / (k! * (n-k)!).
Instance methods operate on a user supplied uniform random number generator; they are unsynchronized.
Implementation: High performance implementation. Acceptance Rejection/Inversion method. This is a port of RandBinomial used in CLHEP 1.4.0 (C++). CLHEP's implementation is, in turn, based on
V. Kachitvichyanukul, B.W. Schmeiser (1988): Binomial random variate generation, Communications of the ACM 31, 216-222.
| Field Summary | |
|---|---|
protected int |
n
|
protected double |
p
|
| Fields inherited from class sim.util.distribution.AbstractDistribution |
|---|
randomGenerator |
| Constructor Summary | |
|---|---|
Binomial(int n,
double p,
MersenneTwisterFast randomGenerator)
Constructs a binomial distribution. |
|
| Method Summary | |
|---|---|
double |
cdf(int k)
Returns the cumulative distribution function. |
protected int |
generateBinomial(int n,
double p)
* Binomial-Distribution - Acceptance Rejection/Inversion * * * Acceptance Rejection method combined with Inversion for * generating Binomial random numbers with parameters * n (number of trials) and p (probability of success). |
int |
nextInt()
Returns a random number from the distribution. |
int |
nextInt(int n,
double p)
Returns a random number from the distribution with the given parameters n and p; bypasses the internal state. |
double |
pdf(int k)
Returns the probability distribution function. |
void |
setNandP(int n,
double p)
Sets the parameters number of trials and the probability of success. |
java.lang.String |
toString()
Returns a String representation of the receiver. |
| Methods inherited from class sim.util.distribution.AbstractDiscreteDistribution |
|---|
nextDouble |
| Methods inherited from class sim.util.distribution.AbstractDistribution |
|---|
apply, apply, getRandomGenerator, setRandomGenerator |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected int n
protected double p
| Constructor Detail |
|---|
public Binomial(int n,
double p,
MersenneTwisterFast randomGenerator)
n - the number of trials (also known as sample size).p - the probability of success.randomGenerator - a uniform random number generator.
java.lang.IllegalArgumentException - if n*Math.min(p,1-p) <= 0.0| Method Detail |
|---|
public double cdf(int k)
protected int generateBinomial(int n,
double p)
public int nextInt()
nextInt in class AbstractDiscreteDistribution
public int nextInt(int n,
double p)
n - the number of trialsp - the probability of success.
java.lang.IllegalArgumentException - if n*Math.min(p,1-p) <= 0.0public double pdf(int k)
public void setNandP(int n,
double p)
n - the number of trialsp - the probability of success.
java.lang.IllegalArgumentException - if n*Math.min(p,1-p) <= 0.0public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||