cern.jet.random.tdouble
Class Binomial
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.jet.random.tdouble.AbstractDoubleDistribution
-
- cern.jet.random.tdouble.AbstractDiscreteDistribution
-
- cern.jet.random.tdouble.Binomial
-
- All Implemented Interfaces:
- DoubleFunction, IntFunction, java.io.Serializable, java.lang.Cloneable
public class Binomial extends AbstractDiscreteDistribution
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.
- Static methods operate on a default uniform random number generator; they are synchronized.
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.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Binomial(int n, double p, DoubleRandomEngine randomGenerator)Constructs a binomial distribution.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublecdf(int k)Returns the cumulative distribution function.intnextInt()Returns a random number from the distribution.intnextInt(int n, double p)Returns a random number from the distribution with the given parameters n and p; bypasses the internal state.doublepdf(int k)Returns the probability distribution function.voidsetNandP(int n, double p)Sets the parameters number of trials and the probability of success.static intstaticNextInt(int n, double p)Returns a random number from the distribution with the given parameters n and p.java.lang.StringtoString()Returns a String representation of the receiver.-
Methods inherited from class cern.jet.random.tdouble.AbstractDiscreteDistribution
nextDouble
-
Methods inherited from class cern.jet.random.tdouble.AbstractDoubleDistribution
apply, apply, clone, makeDefaultGenerator
-
-
-
-
Constructor Detail
-
Binomial
public Binomial(int n, double p, DoubleRandomEngine randomGenerator)Constructs a binomial distribution. Example: n=1, p=0.5.- Parameters:
n- the number of trials (also known as sample size).p- the probability of success.randomGenerator- a uniform random number generator.- Throws:
java.lang.IllegalArgumentException- if n*Math.min(p,1-p) <= 0.0
-
-
Method Detail
-
cdf
public double cdf(int k)
Returns the cumulative distribution function.
-
nextInt
public int nextInt()
Returns a random number from the distribution.- Specified by:
nextIntin classAbstractDiscreteDistribution
-
nextInt
public int nextInt(int n, double p)Returns a random number from the distribution with the given parameters n and p; bypasses the internal state.- Parameters:
n- the number of trialsp- the probability of success.- Throws:
java.lang.IllegalArgumentException- if n*Math.min(p,1-p) <= 0.0
-
pdf
public double pdf(int k)
Returns the probability distribution function.
-
setNandP
public void setNandP(int n, double p)Sets the parameters number of trials and the probability of success.- Parameters:
n- the number of trialsp- the probability of success.- Throws:
java.lang.IllegalArgumentException- if n*Math.min(p,1-p) <= 0.0
-
staticNextInt
public static int staticNextInt(int n, double p)Returns a random number from the distribution with the given parameters n and p.- Parameters:
n- the number of trialsp- the probability of success.- Throws:
java.lang.IllegalArgumentException- if n*Math.min(p,1-p) <= 0.0
-
toString
public java.lang.String toString()
Returns a String representation of the receiver.- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG