CombinedBinomialDistribution.hpp
A means of quickly generating binomial random variables while only storing a small number of distributions.
Quick check for theory: https://math.stackexchange.com/questions/1176385/sum-of-two-independent-binomial-variables
If we want to generate binomial random variables of various trial counts (n’s) using the Distribution class, we’d have to create a new Distribution for each unique trial count.
This class leverages the fact that B(n, p) + B(m, p) = B(n + m, p) to calculate binomial draws with arbitrary trail counts without storing N distributions. By storing distributions for powers of 2, we only store log_2(N) distributions.
Developor Notes:
We should come up with a more informative name for the file/class
Note
Status: ALPHA
-
namespace emp
-
class CombinedBinomialDistribution
- #include <CombinedBinomialDistribution.hpp>
A collection of distributions that allows for pulls from a binomial distribution with arbitrary N while only storing log_2(N) distributions.
Public Functions
-
inline CombinedBinomialDistribution()
-
inline CombinedBinomialDistribution(double _p, size_t _starting_n)
-
inline void Setup(double _p, size_t _n)
Reset the distribution with a new probability, p, and a starting n value.
-
inline void Expand(size_t max_n)
Create more distributions to handle the given value of n.
-
inline size_t GetCurMaxPower()
Fetch the current maximum power handled by this combined distribution.
Protected Functions
-
inline size_t GetMaxPower(size_t n) const
Fetch the smallest power of two that is larger than N.
-
inline CombinedBinomialDistribution()
-
class CombinedBinomialDistribution