File indexing completed on 2025-01-18 09:51:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
0017 #define BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
0018
0019 #include <boost/config/no_tr1/cmath.hpp>
0020 #include <iosfwd>
0021 #include <istream>
0022 #include <boost/limits.hpp>
0023 #include <boost/random/detail/config.hpp>
0024 #include <boost/random/detail/operators.hpp>
0025 #include <boost/random/uniform_01.hpp>
0026
0027 namespace boost {
0028 namespace random {
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 template<class RealType = double>
0039 class cauchy_distribution
0040 {
0041 public:
0042 typedef RealType input_type;
0043 typedef RealType result_type;
0044
0045 class param_type
0046 {
0047 public:
0048
0049 typedef cauchy_distribution distribution_type;
0050
0051
0052 explicit param_type(RealType median_arg = RealType(0.0),
0053 RealType sigma_arg = RealType(1.0))
0054 : _median(median_arg), _sigma(sigma_arg) {}
0055
0056
0057
0058
0059 RealType median() const { return _median; }
0060
0061 RealType sigma() const { return _sigma; }
0062
0063
0064
0065
0066 RealType a() const { return _median; }
0067
0068 RealType b() const { return _sigma; }
0069
0070
0071 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
0072 {
0073 os << parm._median << " " << parm._sigma;
0074 return os;
0075 }
0076
0077
0078 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
0079 {
0080 is >> parm._median >> std::ws >> parm._sigma;
0081 return is;
0082 }
0083
0084
0085 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
0086 { return lhs._median == rhs._median && lhs._sigma == rhs._sigma; }
0087
0088
0089 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
0090
0091 private:
0092 RealType _median;
0093 RealType _sigma;
0094 };
0095
0096
0097
0098
0099
0100 explicit cauchy_distribution(RealType median_arg = RealType(0.0),
0101 RealType sigma_arg = RealType(1.0))
0102 : _median(median_arg), _sigma(sigma_arg) { }
0103
0104
0105
0106
0107 explicit cauchy_distribution(const param_type& parm)
0108 : _median(parm.median()), _sigma(parm.sigma()) { }
0109
0110
0111
0112
0113
0114
0115 RealType median() const { return _median; }
0116
0117 RealType sigma() const { return _sigma; }
0118
0119
0120
0121
0122 RealType a() const { return _median; }
0123
0124 RealType b() const { return _sigma; }
0125
0126
0127 RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const
0128 { return -(std::numeric_limits<RealType>::infinity)(); }
0129
0130
0131 RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const
0132 { return (std::numeric_limits<RealType>::infinity)(); }
0133
0134 param_type param() const { return param_type(_median, _sigma); }
0135
0136 void param(const param_type& parm)
0137 {
0138 _median = parm.median();
0139 _sigma = parm.sigma();
0140 }
0141
0142
0143
0144
0145
0146 void reset() { }
0147
0148
0149
0150
0151
0152 template<class Engine>
0153 result_type operator()(Engine& eng)
0154 {
0155
0156 const result_type pi = result_type(3.14159265358979323846);
0157 using std::tan;
0158 RealType val = uniform_01<RealType>()(eng)-result_type(0.5);
0159 return _median + _sigma * tan(pi*val);
0160 }
0161
0162
0163
0164
0165
0166 template<class Engine>
0167 result_type operator()(Engine& eng, const param_type& parm)
0168 {
0169 return cauchy_distribution(parm)(eng);
0170 }
0171
0172
0173
0174
0175 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, cauchy_distribution, cd)
0176 {
0177 os << cd._median << " " << cd._sigma;
0178 return os;
0179 }
0180
0181
0182
0183
0184 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, cauchy_distribution, cd)
0185 {
0186 is >> cd._median >> std::ws >> cd._sigma;
0187 return is;
0188 }
0189
0190
0191
0192
0193
0194 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(cauchy_distribution, lhs, rhs)
0195 { return lhs._median == rhs._median && lhs._sigma == rhs._sigma; }
0196
0197
0198
0199
0200
0201 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(cauchy_distribution)
0202
0203 private:
0204 RealType _median;
0205 RealType _sigma;
0206 };
0207
0208 }
0209
0210 using random::cauchy_distribution;
0211
0212 }
0213
0214 #endif