1 /* boost random/extreme_value_distribution.hpp header file
3 * Copyright Steven Watanabe 2010
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org for most recent version including documentation.
10 * $Id: extreme_value_distribution.hpp 71018 2011-04-05 21:27:52Z steven_watanabe $
13 #ifndef BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
14 #define BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
16 #include <boost/config/no_tr1/cmath.hpp>
19 #include <boost/config.hpp>
20 #include <boost/limits.hpp>
21 #include <boost/random/detail/operators.hpp>
22 #include <boost/random/uniform_01.hpp>
28 * The extreme value distribution is a real valued distribution with two
31 * It has \f$\displaystyle p(x) = \frac{1}{b}e^{\frac{a-x}{b} - e^\frac{a-x}{b}}\f$.
33 template<class RealType = double>
34 class extreme_value_distribution {
36 typedef RealType result_type;
37 typedef RealType input_type;
41 typedef extreme_value_distribution distribution_type;
44 * Constructs a @c param_type from the "a" and "b" parameters
45 * of the distribution.
49 explicit param_type(RealType a_arg = 1.0, RealType b_arg = 1.0)
50 : _a(a_arg), _b(b_arg)
53 /** Returns the "a" parameter of the distribtuion. */
54 RealType a() const { return _a; }
55 /** Returns the "b" parameter of the distribution. */
56 RealType b() const { return _b; }
58 /** Writes a @c param_type to a @c std::ostream. */
59 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
60 { os << parm._a << ' ' << parm._b; return os; }
62 /** Reads a @c param_type from a @c std::istream. */
63 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
64 { is >> parm._a >> std::ws >> parm._b; return is; }
66 /** Returns true if the two sets of parameters are the same. */
67 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
68 { return lhs._a == rhs._a && lhs._b == rhs._b; }
70 /** Returns true if the two sets of parameters are the different. */
71 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
79 * Constructs an @c extreme_value_distribution from its "a" and "b" parameters.
83 explicit extreme_value_distribution(RealType a_arg = 1.0, RealType b_arg = 1.0)
84 : _a(a_arg), _b(b_arg)
86 /** Constructs an @c extreme_value_distribution from its parameters. */
87 explicit extreme_value_distribution(const param_type& parm)
88 : _a(parm.a()), _b(parm.b())
92 * Returns a random variate distributed according to the
93 * @c extreme_value_distribution.
96 RealType operator()(URNG& urng) const
99 return _a - log(-log(uniform_01<RealType>()(urng))) * _b;
103 * Returns a random variate distributed accordint to the extreme
104 * value distribution with parameters specified by @c param.
107 RealType operator()(URNG& urng, const param_type& parm) const
109 return extreme_value_distribution(parm)(urng);
112 /** Returns the "a" parameter of the distribution. */
113 RealType a() const { return _a; }
114 /** Returns the "b" parameter of the distribution. */
115 RealType b() const { return _b; }
117 /** Returns the smallest value that the distribution can produce. */
118 RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const
119 { return -std::numeric_limits<RealType>::infinity(); }
120 /** Returns the largest value that the distribution can produce. */
121 RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const
122 { return std::numeric_limits<RealType>::infinity(); }
124 /** Returns the parameters of the distribution. */
125 param_type param() const { return param_type(_a, _b); }
126 /** Sets the parameters of the distribution. */
127 void param(const param_type& parm)
134 * Effects: Subsequent uses of the distribution do not depend
135 * on values produced by any engine prior to invoking reset.
139 /** Writes an @c extreme_value_distribution to a @c std::ostream. */
140 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, extreme_value_distribution, wd)
146 /** Reads an @c extreme_value_distribution from a @c std::istream. */
147 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, extreme_value_distribution, wd)
157 * Returns true if the two instances of @c extreme_value_distribution will
158 * return identical sequences of values given equal generators.
160 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(extreme_value_distribution, lhs, rhs)
161 { return lhs._a == rhs._a && lhs._b == rhs._b; }
164 * Returns true if the two instances of @c extreme_value_distribution will
165 * return different sequences of values given equal generators.
167 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(extreme_value_distribution)
174 } // namespace random
177 #endif // BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP