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_FISHER_F_DISTRIBUTION_HPP
0014 #define BOOST_RANDOM_FISHER_F_DISTRIBUTION_HPP
0015
0016 #include <iosfwd>
0017 #include <istream>
0018 #include <boost/config.hpp>
0019 #include <boost/limits.hpp>
0020 #include <boost/random/detail/operators.hpp>
0021 #include <boost/random/chi_squared_distribution.hpp>
0022
0023 namespace boost {
0024 namespace random {
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 template<class RealType = double>
0037 class fisher_f_distribution {
0038 public:
0039 typedef RealType result_type;
0040 typedef RealType input_type;
0041
0042 class param_type {
0043 public:
0044 typedef fisher_f_distribution distribution_type;
0045
0046
0047
0048
0049
0050
0051
0052 explicit param_type(RealType m_arg = RealType(1.0),
0053 RealType n_arg = RealType(1.0))
0054 : _m(m_arg), _n(n_arg)
0055 {}
0056
0057
0058 RealType m() const { return _m; }
0059
0060 RealType n() const { return _n; }
0061
0062
0063 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
0064 { os << parm._m << ' ' << parm._n; return os; }
0065
0066
0067 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
0068 { is >> parm._m >> std::ws >> parm._n; return is; }
0069
0070
0071 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
0072 { return lhs._m == rhs._m && lhs._n == rhs._n; }
0073
0074
0075 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
0076
0077 private:
0078 RealType _m;
0079 RealType _n;
0080 };
0081
0082
0083
0084
0085
0086
0087 explicit fisher_f_distribution(RealType m_arg = RealType(1.0),
0088 RealType n_arg = RealType(1.0))
0089 : _impl_m(m_arg), _impl_n(n_arg)
0090 {}
0091
0092 explicit fisher_f_distribution(const param_type& parm)
0093 : _impl_m(parm.m()), _impl_n(parm.n())
0094 {}
0095
0096
0097
0098
0099
0100 template<class URNG>
0101 RealType operator()(URNG& urng)
0102 {
0103 return (_impl_m(urng) * n()) / (_impl_n(urng) * m());
0104 }
0105
0106
0107
0108
0109
0110 template<class URNG>
0111 RealType operator()(URNG& urng, const param_type& parm) const
0112 {
0113 return fisher_f_distribution(parm)(urng);
0114 }
0115
0116
0117 RealType m() const { return _impl_m.n(); }
0118
0119 RealType n() const { return _impl_n.n(); }
0120
0121
0122 RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
0123
0124 RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const
0125 { return std::numeric_limits<RealType>::infinity(); }
0126
0127
0128 param_type param() const { return param_type(m(), n()); }
0129
0130 void param(const param_type& parm)
0131 {
0132 typedef chi_squared_distribution<RealType> impl_type;
0133 typename impl_type::param_type m_param(parm.m());
0134 _impl_m.param(m_param);
0135 typename impl_type::param_type n_param(parm.n());
0136 _impl_n.param(n_param);
0137 }
0138
0139
0140
0141
0142
0143 void reset() { }
0144
0145
0146 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, fisher_f_distribution, fd)
0147 {
0148 os << fd.param();
0149 return os;
0150 }
0151
0152
0153 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, fisher_f_distribution, fd)
0154 {
0155 param_type parm;
0156 if(is >> parm) {
0157 fd.param(parm);
0158 }
0159 return is;
0160 }
0161
0162
0163
0164
0165
0166 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(fisher_f_distribution, lhs, rhs)
0167 { return lhs._impl_m == rhs._impl_m && lhs._impl_n == rhs._impl_n; }
0168
0169
0170
0171
0172
0173 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(fisher_f_distribution)
0174
0175 private:
0176 chi_squared_distribution<RealType> _impl_m;
0177 chi_squared_distribution<RealType> _impl_n;
0178 };
0179
0180 }
0181 }
0182
0183 #endif