32 #ifndef SHARK_RNG_LOGNORMAL_H 33 #define SHARK_RNG_LOGNORMAL_H 37 #include <boost/random/lognormal_distribution.hpp> 52 template<
typename RngType = shark::DefaultRngType>
53 class LogNormal :
public boost::variate_generator<RngType*,boost::lognormal_distribution<> >
56 typedef boost::variate_generator<RngType*,boost::lognormal_distribution<> > Base;
61 boost::lognormal_distribution<> createDistribution(
double location,
double scale){
62 double mean = std::exp(location+scale*scale/2.0);
63 double variance = (std::exp(scale*scale)-1.0)* std::exp(2*location+scale*scale);
64 return boost::lognormal_distribution<>(
mean,std::sqrt(variance));
76 : Base(&rng,
boost::lognormal_distribution<>(1,1)),m_location(location),m_scale(scale)
78 Base::distribution() = createDistribution(location,scale);
82 using Base::operator();
90 return dist(createDistribution(location,scale) );
112 m_location = newLocation;
114 Base::distribution() = createDistribution(
location(),
scale());
123 Base::distribution() = createDistribution(
location(),
scale());
129 double p(
double x)
const {
132 return x > 0 ? std::exp(-y*y / 2.0) / (boost::math::constants::root_two_pi<double>() *
scale() * x) : 0;