Distribution.hpp
A set of pre-calculated discrete distributions that can quickly generate random values.
This file is part of Empirical, https://github.com/devosoft/Empirical Copyright (C) 2018-2024 Michigan State University MIT Software license; see doc/LICENSE.md
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 likely 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: BETA
Defines
-
INCLUDE_EMP_MATH_DISTRIBUTION_HPP_GUARD
-
class Distribution
- #include <Distribution.hpp>
Subclassed by Binomial, GeometricDistribution, 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.
Protected Attributes
-
UnorderedIndexMap weights
-
inline size_t GetSize() const
-
class Uniform : public Distribution
- #include <Distribution.hpp>
-
class GeometricDistribution : public Distribution
- #include <Distribution.hpp>
How many attempts before a probability p succeeds?
-
class Binomial : public Distribution
- #include <Distribution.hpp>
How many successes with p probability and N attempts?
-
class NegativeBinomial : public Distribution
- #include <Distribution.hpp>
How many attempts to reach N successes, assuming p probability per attempt?