org.nd4j.linalg.api.rng.distribution.impl

## Class BinomialDistribution

• All Implemented Interfaces:
Distribution

```public class BinomialDistribution
extends BaseDistribution```
Base distribution derived from apache commons math http://commons.apache.org/proper/commons-math/

(specifically the `BinomialDistribution`

• ### Fields inherited from class org.nd4j.linalg.api.rng.distribution.BaseDistribution

`random, solverAbsoluteAccuracy`
• ### Constructor Summary

Constructors
Constructor and 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
Modifier and Type Method and Description
`double` `cumulativeProbability(double x)`
For a random variable `X` whose values are distributed according to this distribution, this method returns `P(X <= x)`.
`double` ```cumulativeProbability(double x0, double x1)```
For a random variable `X` whose values are distributed according to this distribution, this method returns `P(x0 < X <= x1)`.
`double` `cumulativeProbability(int x)`
`double` `density(double x)`
Returns the probability density function (PDF) of this distribution evaluated at the specified point `x`.
`int` `getNumberOfTrials()`
Access the number of trials for this distribution.
`double` `getNumericalMean()`
Use this method to get the numerical value of the mean of this distribution.
`double` `getNumericalVariance()`
Use this method to get the numerical value of the variance of this distribution.
`double` `getProbabilityOfSuccess()`
Access the probability of success for this distribution.
`double` `getSupportLowerBound()`
Access the lower bound of the support.
`double` `getSupportUpperBound()`
Access the upper bound of the support.
`boolean` `isSupportConnected()`
Use this method to get information about whether the support is connected, i.e.
`boolean` `isSupportLowerBoundInclusive()`
Whether or not the lower bound of support is in the domain of the density function.
`boolean` `isSupportUpperBoundInclusive()`
Whether or not the upper bound of support is in the domain of the density function.
`double` `probability(int x)`
`INDArray` `sample(INDArray ret)`
Fill the target array by sampling from the distribution
`INDArray` `sample(int[] shape)`
Sample the given shape
• ### Methods inherited from class org.nd4j.linalg.api.rng.distribution.BaseDistribution

`getSolverAbsoluteAccuracy, inverseCumulativeProbability, probability, probability, reseedRandomGenerator, sample, sample, sample`
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### 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` - if `trials < 0`.
`org.apache.commons.math3.exception.OutOfRangeException` - if `p < 0` or `p > 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` - if `trials < 0`.
`org.apache.commons.math3.exception.OutOfRangeException` - if `p < 0` or `p > 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: `Distribution`
Returns the probability density function (PDF) of this distribution evaluated at the specified point `x`. In general, the PDF is the derivative of the `CDF`. If the derivative does not exist at `x`, 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: `Distribution`
For a random variable `X` whose values are distributed according to this distribution, this method returns `P(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.NumberIsTooLargeException```
Description copied from interface: `Distribution`
For a random variable `X` whose values are distributed according to this distribution, this method returns `P(x0 < X <= x1)`.
Parameters:
`x0` - the exclusive lower bound
`x1` - the inclusive upper bound
Returns:
the probability that a random variable with this distribution takes a value between `x0` and `x1`, excluding the lower and including the upper endpoint
Throws:
`org.apache.commons.math3.exception.NumberIsTooLargeException` - if `x0 > x1`
• #### getNumericalMean

`public double getNumericalMean()`
Use this method to get the numerical value of the mean of this distribution.

For `n` trials and probability parameter `p`, the mean is `n * p`.

Returns:
the mean or `Double.NaN` if it is not defined
• #### getNumericalVariance

`public double getNumericalVariance()`
Use this method to get the numerical value of the variance of this distribution.

For `n` trials and probability parameter `p`, the variance is `n * p * (1 - p)`.

Returns:
the variance (possibly `Double.POSITIVE_INFINITY` as for certain cases in `TDistribution`) or `Double.NaN` if it is not defined
• #### getSupportLowerBound

`public double getSupportLowerBound()`
Access the lower bound of the support. This method must return the same value as `inverseCumulativeProbability(0)`. In other words, this method must return

`inf {x in R | P(X <= x) > 0}`.

The lower bound of the support is always 0 except for the probability parameter `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 as `inverseCumulativeProbability(1)`. In other words, this method must return

`inf {x in R | P(X <= x) = 1}`.

The upper bound of the support is the number of trials except for the probability parameter `p = 0`.

Returns:
upper bound of the support (number of trials or 0)
• #### isSupportLowerBoundInclusive

`public boolean isSupportLowerBoundInclusive()`
Description copied from interface: `Distribution`
Whether or not the lower bound of support is in the domain of the density function. Returns true iff `getSupporLowerBound()` is finite and `density(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: `Distribution`
Whether or not the upper bound of support is in the domain of the density function. Returns true iff `getSupportUpperBound()` is finite and `density(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: `Distribution`
Sample the given shape
Specified by:
`sample` in interface `Distribution`
Overrides:
`sample` in class `BaseDistribution`
Parameters:
`shape` - the given shape
Returns:
an ndarray with random samples from this distribution
• #### sample

`public INDArray sample(INDArray ret)`
Description copied from interface: `Distribution`
Fill the target array by sampling from the distribution
Specified by:
`sample` in interface `Distribution`
Overrides:
`sample` in class `BaseDistribution`
Parameters:
`ret` - target array
Returns:
an ndarray with random samples from this distribution