32 #ifndef SHARK_RNG_HYPERGEOMETRIC_H 33 #define SHARK_RNG_HYPERGEOMETRIC_H 39 #include <boost/random/uniform_01.hpp> 41 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS 47 template<
class IntType=
int,
class RealType =
double>
51 typedef RealType input_type;
52 typedef IntType result_type;
55 :mean_(mean),variance_(variance)
63 double z = variance / (mean *
mean);
64 p = (1 - std::sqrt((z - 1) / (z + 1))) / 2;
81 template<
class Engine>
84 double uni1 = boost::uniform_01<RealType>(eng);
85 double uni2 = boost::uniform_01<RealType>(eng);
86 return -mean_ * ::log( uni1) / (2 *( uni2 > p? 1 - p : p));
89 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS 90 template<
class CharT,
class Traits>
91 friend std::basic_ostream<CharT,Traits>&
99 template<
class CharT,
class Traits>
100 friend std::basic_istream<CharT,Traits>&
117 template<
typename RngType = shark::DefaultRngType>
118 class HyperGeometric:
public boost::variate_generator<RngType*,HyperGeometric_distribution<> > {
120 typedef boost::variate_generator<RngType*,HyperGeometric_distribution<> > Base;
127 using Base::operator();
132 return dist(Base::engine());
137 return Base::distribution().mean();
141 return Base::distribution().variance();
152 double p(
double x)
const