Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Engine::NegativeBinomialDistribution< IntType > Class Template Reference

Platform-independent negative binomial distribution. More...

#include <PRNGDistribution.hpp>

Classes

struct  param_type
 Parameter set for the distribution. More...
 

Public Types

using result_type = IntType
 The type of values produced by the distribution.
 

Public Member Functions

 NegativeBinomialDistribution ()
 Default constructor. Creates distribution with k=1, p=0.5 (geometric).
 
 NegativeBinomialDistribution (IntType k, double p=0.5)
 Constructs a negative binomial distribution with specified parameters.
 
 NegativeBinomialDistribution (const param_type &param)
 Constructs from a parameter set.
 
void reset ()
 Resets the distribution state.
 
IntType k () const
 Gets the number of successes required.
 
double p () const
 Gets the success probability.
 
param_type param () const
 Gets the current parameter set.
 
void param (const param_type &param)
 Sets new parameters for the distribution.
 
result_type min () const
 Gets the minimum value that can be generated (0).
 
result_type max () const
 Gets the theoretical maximum value (unbounded).
 
template<typename Generator >
result_type operator() (Generator &g)
 Generates the next random value using stored parameters.
 
template<typename Generator >
result_type operator() (Generator &g, const param_type &param)
 Generates the next random value using provided parameters.
 

Friends

bool operator== (const NegativeBinomialDistribution &lhs, const NegativeBinomialDistribution &rhs)
 
bool operator!= (const NegativeBinomialDistribution &lhs, const NegativeBinomialDistribution &rhs)
 

Detailed Description

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
IntTypeInteger type for the result

Example usage:

PRNG rng(12345);
// Failures before 5 successes (30% success rate)
int failures = trials(rng);
// Overdispersed count data (more variable than Poisson)
int observed_count = counts(rng);
// Model clustered events (spatial overdispersion)
int cluster_size = clusters(rng);
// Rare event modeling with high variance
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).

Member Typedef Documentation

◆ result_type

template<typename IntType = int>
using Infinity::Engine::NegativeBinomialDistribution< IntType >::result_type = IntType

The type of values produced by the distribution.

Constructor & Destructor Documentation

◆ NegativeBinomialDistribution() [1/3]

template<typename IntType = int>
Infinity::Engine::NegativeBinomialDistribution< IntType >::NegativeBinomialDistribution ( )
inline

Default constructor. Creates distribution with k=1, p=0.5 (geometric).

◆ NegativeBinomialDistribution() [2/3]

template<typename IntType = int>
Infinity::Engine::NegativeBinomialDistribution< IntType >::NegativeBinomialDistribution ( IntType  k,
double  p = 0.5 
)
inlineexplicit

Constructs a negative binomial distribution with specified parameters.

Parameters
kNumber of successes required
pSuccess probability per trial

◆ NegativeBinomialDistribution() [3/3]

template<typename IntType = int>
Infinity::Engine::NegativeBinomialDistribution< IntType >::NegativeBinomialDistribution ( const param_type param)
inlineexplicit

Constructs from a parameter set.

Parameters
paramThe distribution parameters

Member Function Documentation

◆ k()

template<typename IntType = int>
IntType Infinity::Engine::NegativeBinomialDistribution< IntType >::k ( ) const
inline

Gets the number of successes required.

◆ max()

template<typename IntType = int>
result_type Infinity::Engine::NegativeBinomialDistribution< IntType >::max ( ) const
inline

Gets the theoretical maximum value (unbounded).

◆ min()

template<typename IntType = int>
result_type Infinity::Engine::NegativeBinomialDistribution< IntType >::min ( ) const
inline

Gets the minimum value that can be generated (0).

◆ operator()() [1/2]

template<typename IntType = int>
template<typename Generator >
result_type Infinity::Engine::NegativeBinomialDistribution< IntType >::operator() ( Generator &  g)
inline

Generates the next random value using stored parameters.

Template Parameters
GeneratorThe random number generator type (e.g., PRNG)
Parameters
gThe random number generator
Returns
A random count of failures before k successes

◆ operator()() [2/2]

template<typename IntType = int>
template<typename Generator >
result_type Infinity::Engine::NegativeBinomialDistribution< IntType >::operator() ( Generator &  g,
const param_type param 
)
inline

Generates the next random value using provided parameters.

Uses the gamma-Poisson mixture representation (compound distribution method):

  1. Generate λ ~ Gamma(k, (1-p)/p)
  2. Generate X ~ Poisson(λ)
  3. 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
GeneratorThe random number generator type (e.g., PRNG)
Parameters
gThe random number generator
paramThe distribution parameters to use for this generation
Returns
A random count of failures before param.k() successes

◆ p()

template<typename IntType = int>
double Infinity::Engine::NegativeBinomialDistribution< IntType >::p ( ) const
inline

Gets the success probability.

◆ param() [1/2]

template<typename IntType = int>
param_type Infinity::Engine::NegativeBinomialDistribution< IntType >::param ( ) const
inline

Gets the current parameter set.

◆ param() [2/2]

template<typename IntType = int>
void Infinity::Engine::NegativeBinomialDistribution< IntType >::param ( const param_type param)
inline

Sets new parameters for the distribution.

Recreates the underlying gamma distribution with the new parameters.

Parameters
paramThe new distribution parameters

◆ reset()

template<typename IntType = int>
void Infinity::Engine::NegativeBinomialDistribution< IntType >::reset ( )
inline

Resets the distribution state.

Resets the underlying gamma distribution.

Friends And Related Symbol Documentation

◆ operator!=

template<typename IntType = int>
bool operator!= ( const NegativeBinomialDistribution< IntType > &  lhs,
const NegativeBinomialDistribution< IntType > &  rhs 
)
friend

◆ operator==

template<typename IntType = int>
bool operator== ( const NegativeBinomialDistribution< IntType > &  lhs,
const NegativeBinomialDistribution< IntType > &  rhs 
)
friend