1
/* boost random/lognormal_distribution.hpp header file
3
* Copyright Jens Maurer 2000-2001
4
* Permission to use, copy, modify, sell, and distribute this software
5
* is hereby granted without fee provided that the above copyright notice
6
* appears in all copies and that both that copyright notice and this
7
* permission notice appear in supporting documentation,
9
* Jens Maurer makes no representations about the suitability of this
10
* software for any purpose. It is provided "as is" without express or
13
* See http://www.boost.org for most recent version including documentation.
15
* $Id: lognormal_distribution.hpp,v 1.1 2004/02/27 03:16:46 pseudonym Exp $
18
* 2001-02-18 moved to individual header files
21
#ifndef BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP
22
#define BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP
24
#include <cmath> // std::exp, std::sqrt
26
#include <boost/random/normal_distribution.hpp>
28
#ifdef BOOST_NO_STDC_NAMESPACE
37
#if defined(__GNUC__) && (__GNUC__ < 3)
38
// Special gcc workaround: gcc 2.95.x ignores using-declarations
39
// in template classes (confirmed by gcc author Martin v. Loewis)
44
template<class UniformRandomNumberGenerator, class RealType = double,
45
class Adaptor = uniform_01<UniformRandomNumberGenerator, RealType> >
46
class lognormal_distribution
49
typedef Adaptor adaptor_type;
50
typedef UniformRandomNumberGenerator base_type;
51
typedef RealType result_type;
53
explicit lognormal_distribution(base_type & rng,
54
result_type mean = result_type(1),
55
result_type sigma = result_type(1))
56
: _mean(mean), _sigma(sigma),
57
_rng(rng, std::log(mean*mean/std::sqrt(sigma*sigma + mean*mean)),
58
std::sqrt(std::log(sigma*sigma/mean/mean+result_type(1))))
60
assert(mean > result_type(0));
63
// compiler-generated copy ctor and assignment operator are fine
65
adaptor_type& adaptor() { return _rng.adaptor(); }
66
base_type& base() const { return _rng.base(); }
67
RealType mean() const { return _mean; }
68
RealType sigma() const { return _sigma; }
69
void reset() { _rng.reset(); }
71
result_type operator()()
73
#ifndef BOOST_NO_STDC_NAMESPACE
74
// allow for Koenig lookup
80
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
81
friend bool operator==(const lognormal_distribution& x,
82
const lognormal_distribution& y)
83
{ return x._rng == y._rng; }
85
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
86
template<class CharT, class Traits>
87
friend std::basic_ostream<CharT,Traits>&
88
operator<<(std::basic_ostream<CharT,Traits>& os, const lognormal_distribution& ld)
90
os << ld._rng << " " << ld._mean << " " << ld._sigma;
94
template<class CharT, class Traits>
95
friend std::basic_istream<CharT,Traits>&
96
operator>>(std::basic_istream<CharT,Traits>& is, lognormal_distribution& ld)
98
is >> std::ws >> ld._rng >> std::ws >> ld._mean >> std::ws >> ld._sigma;
104
// Use a member function
105
bool operator==(const lognormal_distribution& rhs) const
106
{ return _rng == rhs._rng; }
109
RealType _mean, _sigma;
110
normal_distribution<base_type, result_type, adaptor_type> _rng;
115
#endif // BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP