File indexing completed on 2025-09-18 08:48:19
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_STATS_DERIVED_HPP
0008 #define BOOST_STATS_DERIVED_HPP
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #include <boost/math/tools/config.hpp>
0032 #include <boost/math/tools/assert.hpp>
0033
0034 #ifndef BOOST_MATH_HAS_NVRTC
0035 #include <cmath>
0036 #endif
0037
0038 #ifdef _MSC_VER
0039 # pragma warning(push)
0040 # pragma warning(disable: 4723)
0041
0042 #endif
0043
0044 namespace boost{ namespace math{
0045
0046 template <class Distribution>
0047 BOOST_MATH_GPU_ENABLED typename Distribution::value_type variance(const Distribution& dist);
0048
0049 template <class Distribution>
0050 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type standard_deviation(const Distribution& dist)
0051 {
0052 BOOST_MATH_STD_USING
0053 return sqrt(variance(dist));
0054 }
0055
0056 template <class Distribution>
0057 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type variance(const Distribution& dist)
0058 {
0059 typename Distribution::value_type result = standard_deviation(dist);
0060 return result * result;
0061 }
0062
0063 template <class Distribution, class RealType>
0064 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type hazard(const Distribution& dist, const RealType& x)
0065 {
0066
0067 typedef typename Distribution::value_type value_type;
0068 typedef typename Distribution::policy_type policy_type;
0069 value_type p = cdf(complement(dist, x));
0070 value_type d = pdf(dist, x);
0071 if(d > p * tools::max_value<value_type>())
0072 return policies::raise_overflow_error<value_type>(
0073 "boost::math::hazard(const Distribution&, %1%)", nullptr, policy_type());
0074 if(d == 0)
0075 {
0076
0077 return 0;
0078 }
0079 return d / p;
0080 }
0081
0082 template <class Distribution, class RealType>
0083 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type chf(const Distribution& dist, const RealType& x)
0084 {
0085
0086 BOOST_MATH_STD_USING
0087 return -log(cdf(complement(dist, x)));
0088 }
0089
0090 template <class Distribution>
0091 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type coefficient_of_variation(const Distribution& dist)
0092 {
0093 typedef typename Distribution::value_type value_type;
0094 typedef typename Distribution::policy_type policy_type;
0095
0096 using std::abs;
0097
0098 value_type m = mean(dist);
0099 value_type d = standard_deviation(dist);
0100 if((abs(m) < 1) && (d > abs(m) * tools::max_value<value_type>()))
0101 {
0102 return policies::raise_overflow_error<value_type>("boost::math::coefficient_of_variation(const Distribution&, %1%)", nullptr, policy_type());
0103 }
0104 return d / m;
0105 }
0106
0107
0108
0109
0110
0111 template <class Distribution, class RealType>
0112 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type pdf(const Distribution& dist, const RealType& x)
0113 {
0114 typedef typename Distribution::value_type value_type;
0115 return pdf(dist, static_cast<value_type>(x));
0116 }
0117 template <class Distribution, class RealType>
0118 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type logpdf(const Distribution& dist, const RealType& x)
0119 {
0120 using std::log;
0121 typedef typename Distribution::value_type value_type;
0122 return log(pdf(dist, static_cast<value_type>(x)));
0123 }
0124 template <class Distribution, class RealType>
0125 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type cdf(const Distribution& dist, const RealType& x)
0126 {
0127 typedef typename Distribution::value_type value_type;
0128 return cdf(dist, static_cast<value_type>(x));
0129 }
0130 template <class Distribution, class Realtype>
0131 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type logcdf(const Distribution& dist, const Realtype& x)
0132 {
0133 using std::log;
0134 using value_type = typename Distribution::value_type;
0135 return log(cdf(dist, static_cast<value_type>(x)));
0136 }
0137 template <class Distribution, class RealType>
0138 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type quantile(const Distribution& dist, const RealType& x)
0139 {
0140 typedef typename Distribution::value_type value_type;
0141 return quantile(dist, static_cast<value_type>(x));
0142 }
0143
0144
0145
0146
0147
0148
0149
0150
0151 template <class Distribution, class RealType>
0152 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type cdf(const complemented2_type<Distribution, RealType>& c)
0153 {
0154 typedef typename Distribution::value_type value_type;
0155 return cdf(complement(c.dist, static_cast<value_type>(c.param)));
0156 }
0157
0158 template <class Distribution, class RealType>
0159 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type logcdf(const complemented2_type<Distribution, RealType>& c)
0160 {
0161 using std::log;
0162 typedef typename Distribution::value_type value_type;
0163 return log(cdf(complement(c.dist, static_cast<value_type>(c.param))));
0164 }
0165
0166 template <class Distribution, class RealType>
0167 BOOST_MATH_GPU_ENABLED inline typename Distribution::value_type quantile(const complemented2_type<Distribution, RealType>& c)
0168 {
0169 typedef typename Distribution::value_type value_type;
0170 return quantile(complement(c.dist, static_cast<value_type>(c.param)));
0171 }
0172
0173 template <class Dist>
0174 BOOST_MATH_GPU_ENABLED inline typename Dist::value_type median(const Dist& d)
0175 {
0176
0177
0178 typedef typename Dist::value_type value_type;
0179 return quantile(d, static_cast<value_type>(0.5f));
0180 }
0181
0182 }
0183 }
0184
0185
0186 #ifdef _MSC_VER
0187 # pragma warning(pop)
0188 #endif
0189
0190 #endif