2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Add logcdf specialization to weibull distribution

This commit is contained in:
Matt Borland
2023-02-06 11:24:09 -08:00
parent 58006b2250
commit f7a4adc0cc
2 changed files with 55 additions and 0 deletions

View File

@@ -212,6 +212,27 @@ inline RealType cdf(const weibull_distribution<RealType, Policy>& dist, const Re
return result;
}
template <class RealType, class Policy>
inline RealType logcdf(const weibull_distribution<RealType, Policy>& dist, const RealType& x)
{
BOOST_MATH_STD_USING // for ADL of std functions
static const char* function = "boost::math::logcdf(const weibull_distribution<%1%>, %1%)";
RealType shape = dist.shape();
RealType scale = dist.scale();
RealType result = 0;
if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
return result;
if(false == detail::check_weibull_x(function, x, &result, Policy()))
return result;
result = log1p(-exp(-pow(x / scale, shape)), Policy());
return result;
}
template <class RealType, class Policy>
inline RealType quantile(const weibull_distribution<RealType, Policy>& dist, const RealType& p)
{
@@ -257,6 +278,27 @@ inline RealType cdf(const complemented2_type<weibull_distribution<RealType, Poli
return result;
}
template <class RealType, class Policy>
inline RealType logcdf(const complemented2_type<weibull_distribution<RealType, Policy>, RealType>& c)
{
BOOST_MATH_STD_USING // for ADL of std functions
static const char* function = "boost::math::logcdf(const weibull_distribution<%1%>, %1%)";
RealType shape = c.dist.shape();
RealType scale = c.dist.scale();
RealType result = 0;
if(false == detail::check_weibull(function, scale, shape, &result, Policy()))
return result;
if(false == detail::check_weibull_x(function, c.param, &result, Policy()))
return result;
result = -pow(c.param / scale, shape);
return result;
}
template <class RealType, class Policy>
inline RealType quantile(const complemented2_type<weibull_distribution<RealType, Policy>, RealType>& c)
{

View File

@@ -41,6 +41,12 @@ void check_weibull(RealType shape, RealType scale, RealType x, RealType p, RealT
x), // random variable.
p, // probability.
tol); // %tolerance.
BOOST_CHECK_CLOSE(
::boost::math::logcdf(
weibull_distribution<RealType>(shape, scale), // distribution.
x), // random variable.
log(p), // probability.
tol);
BOOST_CHECK_CLOSE(
::boost::math::cdf(
complement(
@@ -48,6 +54,13 @@ void check_weibull(RealType shape, RealType scale, RealType x, RealType p, RealT
x)), // random variable.
q, // probability complement.
tol); // %tolerance.
BOOST_CHECK_CLOSE(
::boost::math::logcdf(
complement(
weibull_distribution<RealType>(shape, scale), // distribution.
x)), // random variable.
log(q), // probability complement.
tol);
BOOST_CHECK_CLOSE(
::boost::math::quantile(
weibull_distribution<RealType>(shape, scale), // distribution.