umontreal.iro.lecuyer.probdist
Class BinomialDist
- java.lang.Object
-
- umontreal.iro.lecuyer.probdist.DiscreteDistributionInt
-
- umontreal.iro.lecuyer.probdist.BinomialDist
-
- All Implemented Interfaces:
- Distribution
public class BinomialDist extends DiscreteDistributionInt
Extends the classDiscreteDistributionIntfor the binomial distribution with parameters n and p, where n is a positive integer and 0 <= p <= 1. Its mass function is given by and its distribution function isF(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
Fields Modifier and Type Field and Description static doubleMAXN-
Fields inherited from class umontreal.iro.lecuyer.probdist.DiscreteDistributionInt
EPSILON
-
-
Constructor Summary
Constructors Constructor and Description BinomialDist(int n, double p)Creates an object that contains the binomial terms, for 0 <= x <= n, and the corresponding cumulative function.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublebarF(int x)Returns bar(F)(x), the complementary distribution function.static doublebarF(int n, double p, int x)Returns bar(F)(x) = P[X >= x], the complementary distribution function.doublecdf(int x)Returns the distribution function F evaluated at x (see).static doublecdf(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.static BinomialDistgetInstanceFromMLE(int[] x, int m)Creates a new instance of a binomial distribution with both parameters n and p estimated using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.static BinomialDistgetInstanceFromMLE(int[] x, int m, int n)Creates a new instance of a binomial distribution with given (fixed) parameter n, and with parameter p estimated by the maximum likelihood method based on the m observations x[i], i = 0, 1,…, m - 1.doublegetMean()Returns the mean of the distribution function.static doublegetMean(int n, double p)Computes the mean E[X] = np of the binomial distribution with parameters n and p.static double[]getMLE(int[] x, int m)Estimates the parameters (n, p) of the binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.static double[]getMLE(int[] x, int m, int n)Estimates the parameter p of the binomial distribution with given (fixed) parameter n, by the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.intgetN()Returns the parameter n of this object.doublegetP()Returns the parameter p of this object.double[]getParams()Returns a table that contains the parameters (n, p) of the current distribution, in regular order: [n, p].doublegetStandardDeviation()Returns the standard deviation of the distribution function.static doublegetStandardDeviation(int n, double p)Computes the standard deviation of the Binomial distribution with parameters n and p.doublegetVariance()Returns the variance of the distribution function.static doublegetVariance(int n, double p)Computes the variance Var[X] = np(1 - p) of the binomial distribution with parameters n and p.static intinverseF(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.intinverseFInt(double u)Returns the inverse distribution function F-1(u), where 0 <= u <= 1.doubleprob(int x)Returns p(x), the probability of x, which should be a real number in the interval [0, 1].static doubleprob(int n, double p, double q, int x)A generalization of the previous method.static doubleprob(int n, double p, int x)Computes and returns the binomial probability p(x) in eq..voidsetParams(int n, double p)Resets the parameters to these new values and recomputes everything as in the constructor.java.lang.StringtoString()
-
-
-
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:DiscreteDistributionIntReturns p(x), the probability of x, which should be a real number in the interval [0, 1].- Specified by:
probin classDiscreteDistributionInt- 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:DiscreteDistributionIntReturns the distribution function F evaluated at x (see).- Specified by:
cdfin classDiscreteDistributionInt- 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:DiscreteDistributionIntReturns bar(F)(x), the complementary distribution function. See the WARNING above.- Overrides:
barFin classDiscreteDistributionInt- Parameters:
x- value at which the complementary distribution function must be evaluated- Returns:
- the complementary distribution function evaluated at x
-
inverseFInt
public int inverseFInt(double u)
Description copied from class:DiscreteDistributionIntReturns the inverse distribution function F-1(u), where 0 <= u <= 1. The default implementation uses binary search.- Overrides:
inverseFIntin classDiscreteDistributionInt- Parameters:
u- value in the interval (0, 1) for which the inverse distribution function is evaluated- Returns:
- the inverse distribution function evaluated at u
-
getMean
public double getMean()
Description copied from interface:DistributionReturns the mean of the distribution function.
-
getVariance
public double getVariance()
Description copied from interface:DistributionReturns the variance of the distribution function.
-
getStandardDeviation
public double getStandardDeviation()
Description copied from interface:DistributionReturns the standard deviation of the distribution function.
-
prob
public static double prob(int n, double p, int x)Computes and returns the binomial probability p(x) in eq..
-
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.
-
barF
public static double barF(int n, double p, int x)Returns bar(F)(x) = P[X >= x], the complementary distribution function.
-
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 thecdfstatic method is used to compute F(x) at different values of x, which is much less efficient.
-
getMLE
public static double[] getMLE(int[] x, int m)Estimates the parameters (n, p) of the binomial distribution using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1. The estimates are returned in a two-element array, in regular order: [n, p].- Parameters:
x- the list of observations used to evaluate parametersm- the number of observations used to evaluate parameters- Returns:
- returns the parameters [hat(n), hat(p)]
-
getInstanceFromMLE
public static BinomialDist getInstanceFromMLE(int[] x, int m)
Creates a new instance of a binomial distribution with both parameters n and p estimated using the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1.- Parameters:
x- the list of observations to use to estimate the parametersm- the number of observations to use to estimate the parameters
-
getMLE
public static double[] getMLE(int[] x, int m, int n)Estimates the parameter p of the binomial distribution with given (fixed) parameter n, by the maximum likelihood method, from the m observations x[i], i = 0, 1,…, m - 1. Returns the estimator in an array with a single element.- Parameters:
x- the list of observations used to evaluate parametersm- the number of observations used to evaluate parametersn- the number of success- Returns:
- returns the parameter [hat(p)]
-
getInstanceFromMLE
public static BinomialDist getInstanceFromMLE(int[] x, int m, int n)
Creates a new instance of a binomial distribution with given (fixed) parameter n, and with parameter p estimated by the maximum likelihood method based on the m observations x[i], i = 0, 1,…, m - 1.- Parameters:
x- the list of observations to use to evaluate parametersm- the number of observations to use to evaluate parametersn- the parameter n of the binomial
-
getMean
public static double getMean(int n, double p)Computes the mean E[X] = np of the binomial distribution with parameters n and p.- Returns:
- the mean of the Binomial distribution E[X] = np
-
getVariance
public static double getVariance(int n, double p)Computes the variance Var[X] = np(1 - p) of the binomial distribution with parameters n and p.- Returns:
- the variance of the binomial distribution Var[X] = np(1 - p)
-
getStandardDeviation
public static double getStandardDeviation(int n, double p)Computes the standard deviation of the Binomial distribution with parameters n and p.- Returns:
- the standard deviation of the binomial distribution
-
getN
public int getN()
Returns the parameter n of this object.
-
getP
public double getP()
Returns the parameter p of this object.
-
getParams
public double[] getParams()
Returns a table that contains the parameters (n, p) of the current distribution, in regular order: [n, p].
-
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 newBinomialDistobject.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG