File indexing completed on 2025-01-18 09:51:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
0014 #define BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
0015
0016 #include <boost/config/no_tr1/cmath.hpp>
0017 #include <iosfwd>
0018 #include <istream>
0019 #include <boost/config.hpp>
0020 #include <boost/limits.hpp>
0021 #include <boost/random/detail/operators.hpp>
0022 #include <boost/random/uniform_01.hpp>
0023
0024 namespace boost {
0025 namespace random {
0026
0027
0028
0029
0030
0031
0032
0033 template<class RealType = double>
0034 class extreme_value_distribution {
0035 public:
0036 typedef RealType result_type;
0037 typedef RealType input_type;
0038
0039 class param_type {
0040 public:
0041 typedef extreme_value_distribution distribution_type;
0042
0043
0044
0045
0046
0047
0048
0049 explicit param_type(RealType a_arg = 1.0, RealType b_arg = 1.0)
0050 : _a(a_arg), _b(b_arg)
0051 {}
0052
0053
0054 RealType a() const { return _a; }
0055
0056 RealType b() const { return _b; }
0057
0058
0059 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
0060 { os << parm._a << ' ' << parm._b; return os; }
0061
0062
0063 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
0064 { is >> parm._a >> std::ws >> parm._b; return is; }
0065
0066
0067 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
0068 { return lhs._a == rhs._a && lhs._b == rhs._b; }
0069
0070
0071 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
0072
0073 private:
0074 RealType _a;
0075 RealType _b;
0076 };
0077
0078
0079
0080
0081
0082
0083 explicit extreme_value_distribution(RealType a_arg = 1.0, RealType b_arg = 1.0)
0084 : _a(a_arg), _b(b_arg)
0085 {}
0086
0087 explicit extreme_value_distribution(const param_type& parm)
0088 : _a(parm.a()), _b(parm.b())
0089 {}
0090
0091
0092
0093
0094
0095 template<class URNG>
0096 RealType operator()(URNG& urng) const
0097 {
0098 using std::log;
0099 return _a - log(-log(uniform_01<RealType>()(urng))) * _b;
0100 }
0101
0102
0103
0104
0105
0106 template<class URNG>
0107 RealType operator()(URNG& urng, const param_type& parm) const
0108 {
0109 return extreme_value_distribution(parm)(urng);
0110 }
0111
0112
0113 RealType a() const { return _a; }
0114
0115 RealType b() const { return _b; }
0116
0117
0118 RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const
0119 { return -std::numeric_limits<RealType>::infinity(); }
0120
0121 RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const
0122 { return std::numeric_limits<RealType>::infinity(); }
0123
0124
0125 param_type param() const { return param_type(_a, _b); }
0126
0127 void param(const param_type& parm)
0128 {
0129 _a = parm.a();
0130 _b = parm.b();
0131 }
0132
0133
0134
0135
0136
0137 void reset() { }
0138
0139
0140 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, extreme_value_distribution, wd)
0141 {
0142 os << wd.param();
0143 return os;
0144 }
0145
0146
0147 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, extreme_value_distribution, wd)
0148 {
0149 param_type parm;
0150 if(is >> parm) {
0151 wd.param(parm);
0152 }
0153 return is;
0154 }
0155
0156
0157
0158
0159
0160 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(extreme_value_distribution, lhs, rhs)
0161 { return lhs._a == rhs._a && lhs._b == rhs._b; }
0162
0163
0164
0165
0166
0167 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(extreme_value_distribution)
0168
0169 private:
0170 RealType _a;
0171 RealType _b;
0172 };
0173
0174 }
0175 }
0176
0177 #endif