32 #ifndef SHARK_RNG_BINOMIAL_H 33 #define SHARK_RNG_BINOMIAL_H 37 #include <boost/random.hpp> 38 #include <boost/math/special_functions.hpp> 39 #include <boost/random/binomial_distribution.hpp> 48 template<
typename RngType = shark::DefaultRngType>
49 class Binomial:
public boost::variate_generator<RngType*,boost::binomial_distribution<> > {
51 typedef boost::variate_generator<RngType*,boost::binomial_distribution<> > Base;
61 :Base(&rng,
boost::binomial_distribution<>(
n,
prob))
67 using Base::operator();
73 boost::binomial_distribution<> dist(n,prob);
74 return dist(Base::engine());
81 return Base::distribution().p();
87 void prob(
double newProb) {
88 Base::distribution()=boost::binomial_distribution<>(
n(),newProb);
94 unsigned int n()
const {
95 return Base::distribution().t();
101 void n(
unsigned int newN) {
102 Base::distribution()=boost::binomial_distribution<>(newN,
prob());
111 double p(
long k)
const {
113 boost::math::binomial_coefficient<double>(
n(),k) *
114 std::pow(
prob(), static_cast<double>( k ) ) *
115 std::pow(1.0-
prob(),static_cast<double>(
n()-k ) )
122 template<
class RngType>
123 unsigned int binomial(RngType& rng,
unsigned int n,
double pHeads){