template<typename IntType = int>
class Infinity::Engine::NegativeBinomialDistribution< IntType >
Platform-independent negative binomial distribution.
Produces integer counts of failures before achieving k successes in independent Bernoulli trials with success probability p. Generalizes the geometric distribution (which is the special case k=1).
The negative binomial distribution is essential for modeling overdispersed count data where the variance exceeds the mean, unlike Poisson where mean equals variance. This makes it valuable in ecology (species counts with clustering), epidemiology (disease cases with heterogeneity), and quality control (defects with non-uniform processes).
- Template Parameters
-
| IntType | Integer type for the result |
Example usage:
int failures = trials(rng);
int observed_count = counts(rng);
int cluster_size = clusters(rng);
int event_count = rare_events(rng);
Platform-independent negative binomial distribution.
Definition PRNGDistribution.hpp:3325
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
- Note
- Returns non-negative integers representing failures before k successes.
-
Mean = k(1-p)/p, Variance = k(1-p)/p² (variance > mean when p < 1).
-
Reduces to geometric distribution when k = 1.
-
Uses gamma-Poisson mixture for generation (compound distribution method).
template<typename IntType = int>
template<typename Generator >
Generates the next random value using provided parameters.
Uses the gamma-Poisson mixture representation (compound distribution method):
- Generate λ ~ Gamma(k, (1-p)/p)
- Generate X ~ Poisson(λ)
- Return X
This works because the negative binomial can be represented as a Poisson distribution where the rate parameter itself follows a gamma distribution. This compound representation provides an efficient and numerically stable generation method.
- Template Parameters
-
| Generator | The random number generator type (e.g., PRNG) |
- Parameters
-
| g | The random number generator |
| param | The distribution parameters to use for this generation |
- Returns
- A random count of failures before param.k() successes