123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- #ifndef BOOST_STATS_FIND_SCALE_HPP
- #define BOOST_STATS_FIND_SCALE_HPP
- #include <boost/math/distributions/fwd.hpp> // for all distribution signatures.
- #include <boost/math/distributions/complement.hpp>
- #include <boost/math/policies/policy.hpp>
- #include <boost/math/tools/traits.hpp>
- #include <boost/static_assert.hpp>
- #include <boost/math/special_functions/fpclassify.hpp>
- #include <boost/math/policies/error_handling.hpp>
- namespace boost
- {
- namespace math
- {
-
-
-
-
-
- template <class Dist, class Policy>
- inline
- typename Dist::value_type find_scale(
- typename Dist::value_type z,
-
- typename Dist::value_type p,
- typename Dist::value_type location,
- const Policy& pol
- )
- {
- #if !defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
- BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value);
- BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value);
- #endif
- static const char* function = "boost::math::find_scale<Dist, Policy>(%1%, %1%, %1%, Policy)";
- if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
- {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, pol);
- }
- if(!(boost::math::isfinite)(z))
- {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "find_scale z parameter was %1%, but must be finite!", z, pol);
- }
- if(!(boost::math::isfinite)(location))
- {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "find_scale location parameter was %1%, but must be finite!", location, pol);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- typename Dist::value_type result =
- (z - location)
- / quantile(Dist(), p);
- if (result <= 0)
- { // If policy isn't to throw, return the scale <= 0.
- policies::raise_evaluation_error<typename Dist::value_type>(function,
- "Computed scale (%1%) is <= 0!" " Was the complement intended?",
- result, Policy());
- }
- return result;
- }
- template <class Dist>
- inline
- typename Dist::value_type find_scale(
- typename Dist::value_type z,
-
- typename Dist::value_type p,
- typename Dist::value_type location)
- {
- return (find_scale<Dist>(z, p, location, policies::policy<>()));
- }
- template <class Dist, class Real1, class Real2, class Real3, class Policy>
- inline typename Dist::value_type find_scale(
- complemented4_type<Real1, Real2, Real3, Policy> const& c)
- {
-
-
-
-
-
-
- #if !defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
- BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value);
- BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value);
- #endif
- static const char* function = "boost::math::find_scale<Dist, Policy>(complement(%1%, %1%, %1%, Policy))";
-
-
- typename Dist::value_type q = c.param1;
- if(!(boost::math::isfinite)(q) || (q < 0) || (q > 1))
- {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "Probability parameter was %1%, but must be >= 0 and <= 1!", q, c.param3);
- }
- typename Dist::value_type z = c.dist;
- if(!(boost::math::isfinite)(z))
- {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "find_scale z parameter was %1%, but must be finite!", z, c.param3);
- }
- typename Dist::value_type location = c.param2;
- if(!(boost::math::isfinite)(location))
- {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "find_scale location parameter was %1%, but must be finite!", location, c.param3);
- }
- typename Dist::value_type result =
- (c.dist - c.param2)
- / quantile(complement(Dist(), c.param1));
-
- if (result <= 0)
- { // If policy isn't to throw, return the scale <= 0.
- policies::raise_evaluation_error<typename Dist::value_type>(function,
- "Computed scale (%1%) is <= 0!" " Was the complement intended?",
- result, Policy());
- }
- return result;
- }
-
-
- template <class Dist, class Real1, class Real2, class Real3>
- inline typename Dist::value_type find_scale(
- complemented3_type<Real1, Real2, Real3> const& c)
- {
-
-
-
-
-
-
- #if !defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
- BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value);
- BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value);
- #endif
- static const char* function = "boost::math::find_scale<Dist, Policy>(complement(%1%, %1%, %1%, Policy))";
-
-
- typename Dist::value_type q = c.param1;
- if(!(boost::math::isfinite)(q) || (q < 0) || (q > 1))
- {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "Probability parameter was %1%, but must be >= 0 and <= 1!", q, policies::policy<>());
- }
- typename Dist::value_type z = c.dist;
- if(!(boost::math::isfinite)(z))
- {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "find_scale z parameter was %1%, but must be finite!", z, policies::policy<>());
- }
- typename Dist::value_type location = c.param2;
- if(!(boost::math::isfinite)(location))
- {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "find_scale location parameter was %1%, but must be finite!", location, policies::policy<>());
- }
- typename Dist::value_type result =
- (z - location)
- / quantile(complement(Dist(), q));
-
- if (result <= 0)
- { // If policy isn't to throw, return the scale <= 0.
- policies::raise_evaluation_error<typename Dist::value_type>(function,
- "Computed scale (%1%) is <= 0!" " Was the complement intended?",
- result, policies::policy<>());
- }
- return result;
- }
- }
- }
- #endif
|