File indexing completed on 2025-01-18 09:39:40
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_STATS_FIND_LOCATION_HPP
0009 #define BOOST_STATS_FIND_LOCATION_HPP
0010
0011 #include <boost/math/distributions/fwd.hpp> // for all distribution signatures.
0012 #include <boost/math/distributions/complement.hpp>
0013 #include <boost/math/policies/policy.hpp>
0014 #include <boost/math/tools/traits.hpp>
0015 #include <boost/math/special_functions/fpclassify.hpp>
0016 #include <boost/math/policies/error_handling.hpp>
0017
0018
0019
0020
0021 namespace boost
0022 {
0023 namespace math
0024 {
0025
0026
0027
0028
0029
0030 template <class Dist, class Policy>
0031 inline
0032 typename Dist::value_type find_location(
0033 typename Dist::value_type z,
0034
0035 typename Dist::value_type p,
0036 typename Dist::value_type scale,
0037 const Policy& pol
0038 )
0039 {
0040 static_assert(::boost::math::tools::is_distribution<Dist>::value, "The provided distribution does not meet the conceptual requirements of a distribution.");
0041 static_assert(::boost::math::tools::is_scaled_distribution<Dist>::value, "The provided distribution does not meet the conceptual requirements of a scaled distribution.");
0042 static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)";
0043
0044 if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
0045 {
0046 return policies::raise_domain_error<typename Dist::value_type>(
0047 function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, pol);
0048 }
0049 if(!(boost::math::isfinite)(z))
0050 {
0051 return policies::raise_domain_error<typename Dist::value_type>(
0052 function, "z parameter was %1%, but must be finite!", z, pol);
0053 }
0054 if(!(boost::math::isfinite)(scale))
0055 {
0056 return policies::raise_domain_error<typename Dist::value_type>(
0057 function, "scale parameter was %1%, but must be finite!", scale, pol);
0058 }
0059
0060
0061
0062 return z - (quantile(Dist(), p) * scale);
0063 }
0064
0065 template <class Dist>
0066 inline
0067 typename Dist::value_type find_location(
0068 typename Dist::value_type z,
0069
0070 typename Dist::value_type p,
0071 typename Dist::value_type scale)
0072 {
0073 return (find_location<Dist>(z, p, scale, policies::policy<>()));
0074 }
0075
0076
0077
0078
0079 template <class Dist, class Real1, class Real2, class Real3>
0080 inline typename Dist::value_type find_location(
0081 complemented3_type<Real1, Real2, Real3> const& c)
0082 {
0083 static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)";
0084
0085 typename Dist::value_type p = c.param1;
0086 if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
0087 {
0088 return policies::raise_domain_error<typename Dist::value_type>(
0089 function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, policies::policy<>());
0090 }
0091 typename Dist::value_type z = c.dist;
0092 if(!(boost::math::isfinite)(z))
0093 {
0094 return policies::raise_domain_error<typename Dist::value_type>(
0095 function, "z parameter was %1%, but must be finite!", z, policies::policy<>());
0096 }
0097 typename Dist::value_type scale = c.param2;
0098 if(!(boost::math::isfinite)(scale))
0099 {
0100 return policies::raise_domain_error<typename Dist::value_type>(
0101 function, "scale parameter was %1%, but must be finite!", scale, policies::policy<>());
0102 }
0103
0104 return z - quantile(Dist(), p) * scale;
0105 }
0106
0107
0108 template <class Dist, class Real1, class Real2, class Real3, class Real4>
0109 inline typename Dist::value_type find_location(
0110 complemented4_type<Real1, Real2, Real3, Real4> const& c)
0111 {
0112 static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)";
0113
0114 typename Dist::value_type p = c.param1;
0115 if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
0116 {
0117 return policies::raise_domain_error<typename Dist::value_type>(
0118 function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, c.param3);
0119 }
0120 typename Dist::value_type z = c.dist;
0121 if(!(boost::math::isfinite)(z))
0122 {
0123 return policies::raise_domain_error<typename Dist::value_type>(
0124 function, "z parameter was %1%, but must be finite!", z, c.param3);
0125 }
0126 typename Dist::value_type scale = c.param2;
0127 if(!(boost::math::isfinite)(scale))
0128 {
0129 return policies::raise_domain_error<typename Dist::value_type>(
0130 function, "scale parameter was %1%, but must be finite!", scale, c.param3);
0131 }
0132
0133 return z - quantile(Dist(), p) * scale;
0134 }
0135
0136 }
0137 }
0138
0139 #endif
0140