update boost
This commit is contained in:
@@ -12,15 +12,15 @@
|
||||
#include <boost/math/special_functions/expm1.hpp>
|
||||
#include <boost/math/distributions/complement.hpp>
|
||||
#include <boost/math/distributions/detail/common_error_handling.hpp>
|
||||
#include <boost/config/no_tr1/cmath.hpp>
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4127) // conditional expression is constant
|
||||
# pragma warning(disable: 4702) // unreachable code (return after domain_error throw).
|
||||
#endif
|
||||
|
||||
#include <utility>
|
||||
#include <cmath>
|
||||
|
||||
namespace boost{ namespace math{
|
||||
|
||||
@@ -60,10 +60,10 @@ template <class RealType = double, class Policy = policies::policy<> >
|
||||
class exponential_distribution
|
||||
{
|
||||
public:
|
||||
typedef RealType value_type;
|
||||
typedef Policy policy_type;
|
||||
using value_type = RealType;
|
||||
using policy_type = Policy;
|
||||
|
||||
exponential_distribution(RealType l_lambda = 1)
|
||||
explicit exponential_distribution(RealType l_lambda = 1)
|
||||
: m_lambda(l_lambda)
|
||||
{
|
||||
RealType err;
|
||||
@@ -76,10 +76,15 @@ private:
|
||||
RealType m_lambda;
|
||||
};
|
||||
|
||||
typedef exponential_distribution<double> exponential;
|
||||
using exponential = exponential_distribution<double>;
|
||||
|
||||
#ifdef __cpp_deduction_guides
|
||||
template <class RealType>
|
||||
exponential_distribution(RealType)->exponential_distribution<typename boost::math::tools::promote_args<RealType>::type>;
|
||||
#endif
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline const std::pair<RealType, RealType> range(const exponential_distribution<RealType, Policy>& /*dist*/)
|
||||
inline std::pair<RealType, RealType> range(const exponential_distribution<RealType, Policy>& /*dist*/)
|
||||
{ // Range of permissible values for random variable x.
|
||||
if (std::numeric_limits<RealType>::has_infinity)
|
||||
{
|
||||
@@ -93,7 +98,7 @@ inline const std::pair<RealType, RealType> range(const exponential_distribution<
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline const std::pair<RealType, RealType> support(const exponential_distribution<RealType, Policy>& /*dist*/)
|
||||
inline std::pair<RealType, RealType> support(const exponential_distribution<RealType, Policy>& /*dist*/)
|
||||
{ // Range of supported values for random variable x.
|
||||
// This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
|
||||
using boost::math::tools::max_value;
|
||||
@@ -122,6 +127,24 @@ inline RealType pdf(const exponential_distribution<RealType, Policy>& dist, cons
|
||||
return result;
|
||||
} // pdf
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType logpdf(const exponential_distribution<RealType, Policy>& dist, const RealType& x)
|
||||
{
|
||||
BOOST_MATH_STD_USING // for ADL of std functions
|
||||
|
||||
static const char* function = "boost::math::logpdf(const exponential_distribution<%1%>&, %1%)";
|
||||
|
||||
RealType lambda = dist.lambda();
|
||||
RealType result = -std::numeric_limits<RealType>::infinity();
|
||||
if(0 == detail::verify_lambda(function, lambda, &result, Policy()))
|
||||
return result;
|
||||
if(0 == detail::verify_exp_x(function, x, &result, Policy()))
|
||||
return result;
|
||||
|
||||
result = log(lambda) - lambda * x;
|
||||
return result;
|
||||
} // logpdf
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType cdf(const exponential_distribution<RealType, Policy>& dist, const RealType& x)
|
||||
{
|
||||
@@ -140,6 +163,24 @@ inline RealType cdf(const exponential_distribution<RealType, Policy>& dist, cons
|
||||
return result;
|
||||
} // cdf
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType logcdf(const exponential_distribution<RealType, Policy>& dist, const RealType& x)
|
||||
{
|
||||
BOOST_MATH_STD_USING // for ADL of std functions
|
||||
|
||||
static const char* function = "boost::math::logcdf(const exponential_distribution<%1%>&, %1%)";
|
||||
|
||||
RealType result = 0;
|
||||
RealType lambda = dist.lambda();
|
||||
if(0 == detail::verify_lambda(function, lambda, &result, Policy()))
|
||||
return result;
|
||||
if(0 == detail::verify_exp_x(function, x, &result, Policy()))
|
||||
return result;
|
||||
result = boost::math::log1p(-exp(-x * lambda), Policy());
|
||||
|
||||
return result;
|
||||
} // cdf
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType quantile(const exponential_distribution<RealType, Policy>& dist, const RealType& p)
|
||||
{
|
||||
@@ -184,6 +225,27 @@ inline RealType cdf(const complemented2_type<exponential_distribution<RealType,
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType logcdf(const complemented2_type<exponential_distribution<RealType, Policy>, RealType>& c)
|
||||
{
|
||||
BOOST_MATH_STD_USING // for ADL of std functions
|
||||
|
||||
static const char* function = "boost::math::logcdf(const exponential_distribution<%1%>&, %1%)";
|
||||
|
||||
RealType result = 0;
|
||||
RealType lambda = c.dist.lambda();
|
||||
if(0 == detail::verify_lambda(function, lambda, &result, Policy()))
|
||||
return result;
|
||||
if(0 == detail::verify_exp_x(function, c.param, &result, Policy()))
|
||||
return result;
|
||||
// Workaround for VC11/12 bug:
|
||||
if (c.param >= tools::max_value<RealType>())
|
||||
return 0;
|
||||
result = -c.param * lambda;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType quantile(const complemented2_type<exponential_distribution<RealType, Policy>, RealType>& c)
|
||||
{
|
||||
@@ -260,10 +322,17 @@ inline RealType kurtosis_excess(const exponential_distribution<RealType, Policy>
|
||||
return 6;
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType entropy(const exponential_distribution<RealType, Policy>& dist)
|
||||
{
|
||||
using std::log;
|
||||
return 1 - log(dist.lambda());
|
||||
}
|
||||
|
||||
} // namespace math
|
||||
} // namespace boost
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user