annotate DEPENDENCIES/generic/include/boost/math/distributions/find_location.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright John Maddock 2007.
Chris@16 2 // Copyright Paul A. Bristow 2007.
Chris@16 3
Chris@16 4 // Use, modification and distribution are subject to the
Chris@16 5 // Boost Software License, Version 1.0. (See accompanying file
Chris@16 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7
Chris@16 8 #ifndef BOOST_STATS_FIND_LOCATION_HPP
Chris@16 9 #define BOOST_STATS_FIND_LOCATION_HPP
Chris@16 10
Chris@16 11 #include <boost/math/distributions/fwd.hpp> // for all distribution signatures.
Chris@16 12 #include <boost/math/distributions/complement.hpp>
Chris@16 13 #include <boost/math/policies/policy.hpp>
Chris@16 14 #include <boost/math/tools/traits.hpp>
Chris@16 15 #include <boost/static_assert.hpp>
Chris@16 16 #include <boost/math/special_functions/fpclassify.hpp>
Chris@16 17 #include <boost/math/policies/error_handling.hpp>
Chris@16 18 // using boost::math::policies::policy;
Chris@16 19 // using boost::math::complement; // will be needed by users who want complement,
Chris@16 20 // but NOT placed here to avoid putting it in global scope.
Chris@16 21
Chris@16 22 namespace boost
Chris@16 23 {
Chris@16 24 namespace math
Chris@16 25 {
Chris@16 26 // Function to find location of random variable z
Chris@16 27 // to give probability p (given scale)
Chris@16 28 // Applies to normal, lognormal, extreme value, Cauchy, (and symmetrical triangular),
Chris@16 29 // enforced by BOOST_STATIC_ASSERT below.
Chris@16 30
Chris@16 31 template <class Dist, class Policy>
Chris@16 32 inline
Chris@16 33 typename Dist::value_type find_location( // For example, normal mean.
Chris@16 34 typename Dist::value_type z, // location of random variable z to give probability, P(X > z) == p.
Chris@16 35 // For example, a nominal minimum acceptable z, so that p * 100 % are > z
Chris@16 36 typename Dist::value_type p, // probability value desired at x, say 0.95 for 95% > z.
Chris@16 37 typename Dist::value_type scale, // scale parameter, for example, normal standard deviation.
Chris@16 38 const Policy& pol
Chris@16 39 )
Chris@16 40 {
Chris@16 41 #if !defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
Chris@16 42 // Will fail to compile here if try to use with a distribution without scale & location,
Chris@16 43 // for example pareto, and many others. These tests are disabled by the pp-logic
Chris@16 44 // above if the compiler doesn't support the SFINAE tricks used in the traits class.
Chris@16 45 BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value);
Chris@16 46 BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value);
Chris@16 47 #endif
Chris@16 48 static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)";
Chris@16 49
Chris@16 50 if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
Chris@16 51 {
Chris@16 52 return policies::raise_domain_error<typename Dist::value_type>(
Chris@16 53 function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, pol);
Chris@16 54 }
Chris@16 55 if(!(boost::math::isfinite)(z))
Chris@16 56 {
Chris@16 57 return policies::raise_domain_error<typename Dist::value_type>(
Chris@16 58 function, "z parameter was %1%, but must be finite!", z, pol);
Chris@16 59 }
Chris@16 60 if(!(boost::math::isfinite)(scale))
Chris@16 61 {
Chris@16 62 return policies::raise_domain_error<typename Dist::value_type>(
Chris@16 63 function, "scale parameter was %1%, but must be finite!", scale, pol);
Chris@16 64 }
Chris@16 65
Chris@16 66 //cout << "z " << z << ", p " << p << ", quantile(Dist(), p) "
Chris@16 67 // << quantile(Dist(), p) << ", quan * scale " << quantile(Dist(), p) * scale << endl;
Chris@16 68 return z - (quantile(Dist(), p) * scale);
Chris@16 69 } // find_location
Chris@16 70
Chris@16 71 template <class Dist>
Chris@16 72 inline // with default policy.
Chris@16 73 typename Dist::value_type find_location( // For example, normal mean.
Chris@16 74 typename Dist::value_type z, // location of random variable z to give probability, P(X > z) == p.
Chris@16 75 // For example, a nominal minimum acceptable z, so that p * 100 % are > z
Chris@16 76 typename Dist::value_type p, // probability value desired at x, say 0.95 for 95% > z.
Chris@16 77 typename Dist::value_type scale) // scale parameter, for example, normal standard deviation.
Chris@16 78 { // Forward to find_location with default policy.
Chris@16 79 return (find_location<Dist>(z, p, scale, policies::policy<>()));
Chris@16 80 } // find_location
Chris@16 81
Chris@16 82 // So the user can start from the complement q = (1 - p) of the probability p,
Chris@16 83 // for example, l = find_location<normal>(complement(z, q, sd));
Chris@16 84
Chris@16 85 template <class Dist, class Real1, class Real2, class Real3>
Chris@16 86 inline typename Dist::value_type find_location( // Default policy.
Chris@16 87 complemented3_type<Real1, Real2, Real3> const& c)
Chris@16 88 {
Chris@16 89 static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)";
Chris@16 90
Chris@16 91 typename Dist::value_type p = c.param1;
Chris@16 92 if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
Chris@16 93 {
Chris@16 94 return policies::raise_domain_error<typename Dist::value_type>(
Chris@16 95 function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, policies::policy<>());
Chris@16 96 }
Chris@16 97 typename Dist::value_type z = c.dist;
Chris@16 98 if(!(boost::math::isfinite)(z))
Chris@16 99 {
Chris@16 100 return policies::raise_domain_error<typename Dist::value_type>(
Chris@16 101 function, "z parameter was %1%, but must be finite!", z, policies::policy<>());
Chris@16 102 }
Chris@16 103 typename Dist::value_type scale = c.param2;
Chris@16 104 if(!(boost::math::isfinite)(scale))
Chris@16 105 {
Chris@16 106 return policies::raise_domain_error<typename Dist::value_type>(
Chris@16 107 function, "scale parameter was %1%, but must be finite!", scale, policies::policy<>());
Chris@16 108 }
Chris@16 109 // cout << "z " << c.dist << ", quantile (Dist(), " << c.param1 << ") * scale " << c.param2 << endl;
Chris@16 110 return z - quantile(Dist(), p) * scale;
Chris@16 111 } // find_location complement
Chris@16 112
Chris@16 113
Chris@16 114 template <class Dist, class Real1, class Real2, class Real3, class Real4>
Chris@16 115 inline typename Dist::value_type find_location( // Explicit policy.
Chris@16 116 complemented4_type<Real1, Real2, Real3, Real4> const& c)
Chris@16 117 {
Chris@16 118 static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)";
Chris@16 119
Chris@16 120 typename Dist::value_type p = c.param1;
Chris@16 121 if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
Chris@16 122 {
Chris@16 123 return policies::raise_domain_error<typename Dist::value_type>(
Chris@16 124 function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, c.param3);
Chris@16 125 }
Chris@16 126 typename Dist::value_type z = c.dist;
Chris@16 127 if(!(boost::math::isfinite)(z))
Chris@16 128 {
Chris@16 129 return policies::raise_domain_error<typename Dist::value_type>(
Chris@16 130 function, "z parameter was %1%, but must be finite!", z, c.param3);
Chris@16 131 }
Chris@16 132 typename Dist::value_type scale = c.param2;
Chris@16 133 if(!(boost::math::isfinite)(scale))
Chris@16 134 {
Chris@16 135 return policies::raise_domain_error<typename Dist::value_type>(
Chris@16 136 function, "scale parameter was %1%, but must be finite!", scale, c.param3);
Chris@16 137 }
Chris@16 138 // cout << "z " << c.dist << ", quantile (Dist(), " << c.param1 << ") * scale " << c.param2 << endl;
Chris@16 139 return z - quantile(Dist(), p) * scale;
Chris@16 140 } // find_location complement
Chris@16 141
Chris@16 142 } // namespace boost
Chris@16 143 } // namespace math
Chris@16 144
Chris@16 145 #endif // BOOST_STATS_FIND_LOCATION_HPP
Chris@16 146