Distribution.hpp

A set of pre-calculated discrete distributions that can quickly generate random values.

A Distribution is a pre-calculated set of probabilities to quickly pick a whole-number result. These should be used when either we need to draw from the same distribution many time (and hence the extra time to pre-calculate it is amortized away) -or- in functions that we want to call with a range of distributions that we may not know ahead of time.

Currently, we have:

Uniform - All values in a range are equally likelty to be picked. Binomial - How many successes with p probability will occur in N attempts? NegativeBinomial - How many attempts to reach N successes, with p probability per attempt?

Developer Notes:

  • We should setup an offset in the base Distribution class to ignore “impossible” low values.

Note

Status: ALPHA

class Distribution
#include <Distribution.hpp>

Subclassed by Binomial, NegativeBinomial, Uniform

Public Functions

inline size_t GetSize() const
inline double GetTotalProb() const
inline double operator[](size_t id) const
inline size_t PickPosition(double in_value)

Pick an item from a distribution using a value between 0.0 and 1.0.

inline size_t PickRandom(Random &random) const

Pick a random item using this distribution.

Protected Attributes

UnorderedIndexMap weights
class Uniform : public Distribution
#include <Distribution.hpp>

Public Functions

inline Uniform(size_t _min, size_t _max)
inline size_t GetMin() const
inline size_t GetMax() const
inline void Setup(size_t _min, size_t _max)

Private Members

size_t min_val = 0
size_t max_val = 0
class Binomial : public Distribution
#include <Distribution.hpp>

How many successes with p probability and N attempts?

Public Functions

inline Binomial()
inline Binomial(double _p, size_t _N)
inline double GetP() const
inline double GetN() const
inline void Setup(double _p, size_t _N)

Private Members

double p = 0.0
size_t N = 0
class NegativeBinomial : public Distribution
#include <Distribution.hpp>

How many attempts to reach N successes, assuming p probability per attempt?

Public Functions

inline NegativeBinomial(double _p, size_t _N)
inline double GetP() const
inline double GetN() const
inline void Setup(double _p, size_t _N)

Private Members

double p = 0.0
size_t N = 0