Class BinomialDistribution
- java.lang.Object
-
- org.nd4j.linalg.api.rng.distribution.BaseDistribution
-
- org.nd4j.linalg.api.rng.distribution.impl.BinomialDistribution
-
- All Implemented Interfaces:
Distribution
public class BinomialDistribution extends BaseDistribution
-
-
Field Summary
-
Fields inherited from class org.nd4j.linalg.api.rng.distribution.BaseDistribution
random, solverAbsoluteAccuracy
-
-
Constructor Summary
Constructors Constructor Description BinomialDistribution(int trials, double p)Create a binomial distribution with the given number of trials and probability of success.BinomialDistribution(int n, INDArray p)BinomialDistribution(Random rng, int trials, double p)Creates a binomial distribution.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublecumulativeProbability(double x)For a random variableXwhose values are distributed according to this distribution, this method returnsP(X <= x).doublecumulativeProbability(double x0, double x1)For a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1).doublecumulativeProbability(int x)doubledensity(double x)Returns the probability density function (PDF) of this distribution evaluated at the specified pointx.intgetNumberOfTrials()Access the number of trials for this distribution.doublegetNumericalMean()Use this method to get the numerical value of the mean of this distribution.doublegetNumericalVariance()Use this method to get the numerical value of the variance of this distribution.doublegetProbabilityOfSuccess()Access the probability of success for this distribution.doublegetSupportLowerBound()Access the lower bound of the support.doublegetSupportUpperBound()Access the upper bound of the support.booleanisSupportConnected()Use this method to get information about whether the support is connected, i.e.booleanisSupportLowerBoundInclusive()Whether or not the lower bound of support is in the domain of the density function.booleanisSupportUpperBoundInclusive()Whether or not the upper bound of support is in the domain of the density function.doubleprobability(int x)INDArraysample(int[] shape)Sample the given shapeINDArraysample(INDArray ret)Fill the target array by sampling from the distribution-
Methods inherited from class org.nd4j.linalg.api.rng.distribution.BaseDistribution
getSolverAbsoluteAccuracy, inverseCumulativeProbability, probability, probability, reseedRandomGenerator, sample, sample, sample
-
-
-
-
Constructor Detail
-
BinomialDistribution
public BinomialDistribution(int trials, double p)Create a binomial distribution with the given number of trials and probability of success.- Parameters:
trials- Number of trials.p- Probability of success.- Throws:
org.apache.commons.math3.exception.NotPositiveException- iftrials < 0.org.apache.commons.math3.exception.OutOfRangeException- ifp < 0orp > 1.
-
BinomialDistribution
public BinomialDistribution(Random rng, int trials, double p)
Creates a binomial distribution.- Parameters:
rng- Random number generator.trials- Number of trials.p- Probability of success.- Throws:
org.apache.commons.math3.exception.NotPositiveException- iftrials < 0.org.apache.commons.math3.exception.OutOfRangeException- ifp < 0orp > 1.- Since:
- 3.1
-
BinomialDistribution
public BinomialDistribution(int n, INDArray p)
-
-
Method Detail
-
getNumberOfTrials
public int getNumberOfTrials()
Access the number of trials for this distribution.- Returns:
- the number of trials.
-
getProbabilityOfSuccess
public double getProbabilityOfSuccess()
Access the probability of success for this distribution.- Returns:
- the probability of success.
-
probability
public double probability(int x)
-
cumulativeProbability
public double cumulativeProbability(int x)
-
density
public double density(double x)
Description copied from interface:DistributionReturns the probability density function (PDF) of this distribution evaluated at the specified pointx. In general, the PDF is the derivative of theCDF. If the derivative does not exist atx, then an appropriate replacement should be returned, e.g.Double.POSITIVE_INFINITY,Double.NaN, or the limit inferior or limit superior of the difference quotient.- Parameters:
x- the point at which the PDF is evaluated- Returns:
- the value of the probability density function at point
x
-
cumulativeProbability
public double cumulativeProbability(double x)
Description copied from interface:DistributionFor a random variableXwhose values are distributed according to this distribution, this method returnsP(X <= x). In other words, this method represents the (cumulative) distribution function (CDF) for this distribution.- Parameters:
x- the point at which the CDF is evaluated- Returns:
- the probability that a random variable with this
distribution takes a value less than or equal to
x
-
cumulativeProbability
public double cumulativeProbability(double x0, double x1) throws org.apache.commons.math3.exception.NumberIsTooLargeExceptionDescription copied from interface:DistributionFor a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1).- Parameters:
x0- the exclusive lower boundx1- the inclusive upper bound- Returns:
- the probability that a random variable with this distribution
takes a value between
x0andx1, excluding the lower and including the upper endpoint - Throws:
org.apache.commons.math3.exception.NumberIsTooLargeException- ifx0 > x1
-
getNumericalMean
public double getNumericalMean()
Use this method to get the numerical value of the mean of this distribution. Forntrials and probability parameterp, the mean isn * p.- Returns:
- the mean or
Double.NaNif it is not defined
-
getNumericalVariance
public double getNumericalVariance()
Use this method to get the numerical value of the variance of this distribution. Forntrials and probability parameterp, the variance isn * p * (1 - p).- Returns:
- the variance (possibly
Double.POSITIVE_INFINITYas for certain cases inTDistribution) orDouble.NaNif it is not defined
-
getSupportLowerBound
public double getSupportLowerBound()
Access the lower bound of the support. This method must return the same value asinverseCumulativeProbability(0). In other words, this method must return
The lower bound of the support is always 0 except for the probability parameterinf {x in R | P(X <= x) > 0}.p = 1.- Returns:
- lower bound of the support (0 or the number of trials)
-
getSupportUpperBound
public double getSupportUpperBound()
Access the upper bound of the support. This method must return the same value asinverseCumulativeProbability(1). In other words, this method must return
The upper bound of the support is the number of trials except for the probability parameterinf {x in R | P(X <= x) = 1}.p = 0.- Returns:
- upper bound of the support (number of trials or 0)
-
isSupportLowerBoundInclusive
public boolean isSupportLowerBoundInclusive()
Description copied from interface:DistributionWhether or not the lower bound of support is in the domain of the density function. Returns true iffgetSupporLowerBound()is finite anddensity(getSupportLowerBound())returns a non-NaN, non-infinite value.- Returns:
- true if the lower bound of support is finite and the density function returns a non-NaN, non-infinite value there
-
isSupportUpperBoundInclusive
public boolean isSupportUpperBoundInclusive()
Description copied from interface:DistributionWhether or not the upper bound of support is in the domain of the density function. Returns true iffgetSupportUpperBound()is finite anddensity(getSupportUpperBound())returns a non-NaN, non-infinite value.- Returns:
- true if the upper bound of support is finite and the density function returns a non-NaN, non-infinite value there
-
isSupportConnected
public boolean isSupportConnected()
Use this method to get information about whether the support is connected, i.e. whether all values between the lower and upper bound of the support are included in the support. The support of this distribution is connected.- Returns:
true
-
sample
public INDArray sample(int[] shape)
Description copied from interface:DistributionSample the given shape- Specified by:
samplein interfaceDistribution- Overrides:
samplein classBaseDistribution- Parameters:
shape- the given shape- Returns:
- an ndarray with random samples from this distribution
-
sample
public INDArray sample(INDArray ret)
Description copied from interface:DistributionFill the target array by sampling from the distribution- Specified by:
samplein interfaceDistribution- Overrides:
samplein classBaseDistribution- Parameters:
ret- target array- Returns:
- an ndarray with random samples from this distribution
-
-