public class PascalDistribution extends Object
r
successes occur.
This is the convention adopted in e.g.
MathWorld,
but not in
Wikipedia.
For a random variable X
whose values are distributed according to this
distribution, the probability mass function is given byP(X = k) = C(k + r  1, r  1) * p^r * (1  p)^k,
r
is the number of successes, p
is the probability of
success, and X
is the total number of failures. C(n, k)
is
the binomial coefficient (n
choose k
). The mean and variance
of X
areE(X) = (1  p) * r / p, var(X) = (1  p) * r / p^2.
P(X <= k) = I(p, r, k + 1)
,
where I is the regularized incomplete Beta function.DiscreteDistribution.Sampler
Constructor and Description 

PascalDistribution(int r,
double p)
Create a Pascal distribution with the given number of successes and
probability of success.

Modifier and Type  Method and Description 

DiscreteDistribution.Sampler 
createSampler(org.apache.commons.rng.UniformRandomProvider rng)
Creates a sampler.

double 
cumulativeProbability(int x)
For a random variable
X whose values are distributed according
to this distribution, this method returns P(X <= x) . 
double 
getMean()
Gets the mean of this distribution.

int 
getNumberOfSuccesses()
Access the number of successes for this distribution.

double 
getProbabilityOfSuccess()
Access the probability of success for this distribution.

int 
getSupportLowerBound()
Gets the lower bound of the support.

int 
getSupportUpperBound()
Gets the upper bound of the support.

double 
getVariance()
Gets the variance of this distribution.

int 
inverseCumulativeProbability(double p)
Computes the quantile function of this distribution.

boolean 
isSupportConnected()
Indicates whether the support is connected, i.e.

double 
logProbability(int x)
For a random variable
X whose values are distributed according
to this distribution, this method returns log(P(X = x)) , where
log is the natural logarithm. 
double 
probability(int x)
For a random variable
X whose values are distributed according
to this distribution, this method returns P(X = x) . 
double 
probability(int x0,
int x1)
For a random variable
X whose values are distributed according
to this distribution, this method returns P(x0 < X <= x1) . 
static int[] 
sample(int n,
DiscreteDistribution.Sampler sampler)
Utility function for allocating an array and filling it with
n
samples generated by the given sampler . 
public PascalDistribution(int r, double p)
r
 Number of successes.p
 Probability of success.IllegalArgumentException
 if r <= 0
or p < 0
or p > 1
.public int getNumberOfSuccesses()
public double getProbabilityOfSuccess()
public double probability(int x)
X
whose values are distributed according
to this distribution, this method returns P(X = x)
.
In other words, this method represents the probability mass function (PMF)
for the distribution.x
 Point at which the PMF is evaluated.x
.public double logProbability(int x)
X
whose values are distributed according
to this distribution, this method returns log(P(X = x))
, where
log
is the natural logarithm.x
 Point at which the PMF is evaluated.x
.public double cumulativeProbability(int x)
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.x
 Point at which the CDF is evaluated.x
.public double getMean()
r
and probability of success p
,
the mean is r * (1  p) / p
.Double.NaN
if it is not defined.public double getVariance()
r
and probability of success p
,
the variance is r * (1  p) / p^2
.Double.NaN
if it is not defined.public int getSupportLowerBound()
inverseCumulativeProbability(0)
, i.e.
inf {x in Z  P(X <= x) > 0}
.
By convention, Integer.MIN_VALUE
should be substituted
for negative infinity.
The lower bound of the support is always 0 no matter the parameters.public int getSupportUpperBound()
inverseCumulativeProbability(1)
, i.e.
inf {x in R  P(X <= x) = 1}
.
By convention, Integer.MAX_VALUE
should be substituted
for positive infinity.
The upper bound of the support is always positive infinity no matter the
parameters. Positive infinity is symbolized by Integer.MAX_VALUE
.Integer.MAX_VALUE
for positive infinity)public boolean isSupportConnected()
true
public double probability(int x0, int x1)
X
whose values are distributed according
to this distribution, this method returns P(x0 < X <= x1)
.
The default implementation uses the identity
P(x0 < X <= x1) = P(X <= x1)  P(X <= x0)
probability
in interface DiscreteDistribution
x0
 Lower bound (exclusive).x1
 Upper bound (inclusive).x0
and x1
, excluding the lower
and including the upper endpoint.public int inverseCumulativeProbability(double p)
X
distributed according to this distribution,
the returned value is
inf{x in Z  P(X<=x) >= p}
for 0 < p <= 1
,inf{x in Z  P(X<=x) > 0}
for p = 0
.int
,
then Integer.MIN_VALUE
or Integer.MAX_VALUE
is returned.
The default implementation returns
DiscreteDistribution.getSupportLowerBound()
for p = 0
,DiscreteDistribution.getSupportUpperBound()
for p = 1
, andsolveInverseCumulativeProbability(double, int, int)
for
0 < p < 1
.inverseCumulativeProbability
in interface DiscreteDistribution
p
 Cumulative probability.p
quantile of this distribution
(largest 0quantile for p = 0
).public static int[] sample(int n, DiscreteDistribution.Sampler sampler)
n
samples generated by the given sampler
.n
 Number of samples.sampler
 Sampler.n
.public DiscreteDistribution.Sampler createSampler(org.apache.commons.rng.UniformRandomProvider rng)
createSampler
in interface DiscreteDistribution
rng
 Generator of uniformly distributed numbers.Copyright © 2018 The Apache Software Foundation. All rights reserved.