31 #ifndef BOOST_165_RANDOM_GAMMA_DISTRIBUTION_HPP
32 #define BOOST_165_RANDOM_GAMMA_DISTRIBUTION_HPP
34 #include <boost/assert.hpp>
35 #include <boost/config/no_tr1/cmath.hpp>
36 #include <boost/limits.hpp>
37 #include <boost/random/detail/config.hpp>
39 #include <boost/static_assert.hpp>
58 template <
class RealType =
double>
62 typedef RealType input_type;
63 typedef RealType result_type;
77 const RealType& beta_arg = RealType(1.0))
78 : _alpha(alpha_arg), _beta(beta_arg)
83 RealType
alpha()
const {
return _alpha; }
85 RealType
beta()
const {
return _beta; }
87 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
89 template <
class CharT,
class Traits>
90 friend std::basic_ostream<CharT, Traits>&
91 operator<<(std::basic_ostream<CharT, Traits>& os,
94 os << parm._alpha <<
' ' << parm._beta;
99 template <
class CharT,
class Traits>
100 friend std::basic_istream<CharT, Traits>&
103 is >> parm._alpha >> std::ws >> parm._beta;
111 return lhs._alpha == rhs._alpha && lhs._beta == rhs._beta;
116 return !(lhs == rhs);
124 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
125 BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
134 const result_type& beta_arg = result_type(1.0))
135 : _exp(result_type(1)), _alpha(alpha_arg), _beta(beta_arg)
137 BOOST_ASSERT(_alpha > result_type(0));
138 BOOST_ASSERT(_beta > result_type(0));
144 : _exp(result_type(1)), _alpha(parm.
alpha()), _beta(parm.
beta())
152 RealType
alpha()
const {
return _alpha; }
154 RealType
beta()
const {
return _beta; }
160 return (std::numeric_limits<RealType>::infinity)();
168 _alpha = parm.
alpha();
183 template <
class Engine>
186 #ifndef BOOST_NO_STDC_NAMESPACE
194 if (_alpha == result_type(1))
196 return _exp(eng) * _beta;
198 else if (_alpha > result_type(1))
201 const result_type pi = result_type(3.14159265358979323846);
204 result_type y = tan(pi * uniform_01<RealType>()(eng));
205 result_type x = sqrt(result_type(2) * _alpha - result_type(1)) * y
206 + _alpha - result_type(1);
207 if (x <= result_type(0))
209 if (uniform_01<RealType>()(eng) > (result_type(1) + y * y) * exp((_alpha - result_type(1))
210 * log(x / (_alpha - result_type(1)))
211 - sqrt(result_type(2) * _alpha
222 result_type u = uniform_01<RealType>()(eng);
223 result_type y = _exp(eng);
227 x = exp(-y / _alpha);
232 x = result_type(1) + y;
233 q = _p + (result_type(1) - _p) * pow(x, _alpha - result_type(1));
242 template <
class URNG>
243 RealType
operator()(URNG& urng,
const param_type& parm)
const
248 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
250 template <
class CharT,
class Traits>
251 friend std::basic_ostream<CharT, Traits>&
252 operator<<(std::basic_ostream<CharT, Traits>& os,
260 template <
class CharT,
class Traits>
261 friend std::basic_istream<CharT, Traits>&
276 return lhs._alpha == rhs._alpha
277 && lhs._beta == rhs._beta
278 && lhs._exp == rhs._exp;
288 return !(lhs == rhs);
294 template <
class CharT,
class Traits>
295 void read(std::basic_istream<CharT, Traits>& is)
306 #ifndef BOOST_NO_STDC_NAMESPACE
310 _p = exp(result_type(1)) / (_alpha + exp(result_type(1)));
314 exponential_distribution_v165<RealType> _exp;
325 #endif // BOOST_165_RANDOM_GAMMA_DISTRIBUTION_HPP
friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &is, param_type &parm)
friend bool operator==(const gamma_distribution_v165 &lhs, const gamma_distribution_v165 &rhs)
param_type(const RealType &alpha_arg=RealType(1.0), const RealType &beta_arg=RealType(1.0))
gamma_distribution_v165(const result_type &alpha_arg=result_type(1.0), const result_type &beta_arg=result_type(1.0))
RealType min BOOST_PREVENT_MACRO_SUBSTITUTION() const
friend bool operator!=(const gamma_distribution_v165 &lhs, const gamma_distribution_v165 &rhs)
result_type operator()(Engine &eng)
void param(const param_type &parm)
friend bool operator!=(const param_type &lhs, const param_type &rhs)
friend bool operator==(const param_type &lhs, const param_type &rhs)
gamma_distribution_v165(const param_type &parm)
friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &is, gamma_distribution_v165 &gd)