32 #ifndef SHARK_RNG_TRUNCATED_EXPONENTIAL_H 33 #define SHARK_RNG_TRUNCATED_EXPONENTIAL_H 36 #include <boost/random.hpp> 37 #include <boost/random/uniform_01.hpp> 47 template<
class RealType =
double>
50 typedef RealType input_type;
51 typedef RealType result_type;
54 :m_max(max),m_lambda(lambda),m_integral(1-
std::exp(-lambda*max))
57 :m_max(max),m_lambda(lambda),m_integral(integral)
74 template<
class Engine>
78 return boost::uniform_01<RealType>()(eng);
80 double y = m_max * boost::uniform_01<RealType>()(eng);
81 return - std::log(1. - y*m_integral)/m_lambda;
84 template<
class CharT,
class Traits,
class T>
85 friend std::basic_ostream<CharT,Traits>&
92 template<
class CharT,
class Traits,
class T>
93 friend std::basic_istream<CharT,Traits>&
116 template<
typename RngType = DefaultRngType>
119 typedef boost::variate_generator<RngType*,TruncatedExponential_distribution<> > Base;
131 using Base::operator();
135 return dist(Base::engine());
139 return Base::distribution().lambda();
142 return Base::distribution().max();
153 if(x >= 0 && x<=
max()) {
154 return std::exp(-
lambda()*x)/Base::distribution().integral();