32 #ifndef SHARK_RNG_ERLANG_H 33 #define SHARK_RNG_ERLANG_H 38 #include <boost/random/uniform_01.hpp> 42 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS 49 template<
class RealType=
double>
53 typedef RealType input_type;
54 typedef RealType result_type;
80 template<
class Engine>
85 if (k == 0 || a <= 0)
return 0.;
90 unsigned int kPrime = k;
92 double uni = boost::uniform_01<RealType>()(eng);
95 return -std::log(prod) / a;
98 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS 99 template<
class CharT,
class Traits>
100 friend std::basic_ostream<CharT,Traits>&
103 os << d.alphas.size();
104 for(
int i=0;i!=d.alphas_.size();++i)
109 template<
class CharT,
class Traits>
110 friend std::basic_istream<CharT,Traits>&
115 for(
int i=0;i!=size;++i)
119 d.alphas_.push_back(element);
134 template<
typename RngType = shark::DefaultRngType>
135 class Erlang:
public boost::variate_generator<RngType*,Erlang_distribution<> >
139 typedef boost::variate_generator<RngType*,Erlang_distribution<> > Base;
155 using Base::operator();
167 return dist(Base::engine());
175 return Base::distribution().mean();
183 return Base::distribution().variance();
205 double p(
double&x)
const 217 if (k == 0 || a <= 0 || x < 0)
return 0.;
219 return std::pow(k * a, k) * std::pow(x, k - 1) * std::exp(- k * a * x);