|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78723 - in trunk: boost/math/distributions libs/math/test
From: john_at_[hidden]
Date: 2012-05-28 12:27:00
Author: johnmaddock
Date: 2012-05-28 12:27:00 EDT (Mon, 28 May 2012)
New Revision: 78723
URL: http://svn.boost.org/trac/boost/changeset/78723
Log:
Tighten Weibull distro tests.
Fix corner cases in Weibull distro.
Fixes #6939.
Fixes #6938.
Text files modified:
trunk/boost/math/distributions/weibull.hpp | 16 ++++++++++++----
trunk/libs/math/test/test_weibull.cpp | 13 +++++++++++--
2 files changed, 23 insertions(+), 6 deletions(-)
Modified: trunk/boost/math/distributions/weibull.hpp
==============================================================================
--- trunk/boost/math/distributions/weibull.hpp (original)
+++ trunk/boost/math/distributions/weibull.hpp 2012-05-28 12:27:00 EDT (Mon, 28 May 2012)
@@ -28,7 +28,7 @@
RealType shape,
RealType* result, const Policy& pol)
{
- if((shape < 0) || !(boost::math::isfinite)(shape))
+ if((shape <= 0) || !(boost::math::isfinite)(shape))
{
*result = policies::raise_domain_error<RealType>(
function,
@@ -133,11 +133,19 @@
return result;
if(x == 0)
- { // Special case, but x == min, pdf = 1 for shape = 1,
- return 0;
+ {
+ if(shape == 1)
+ {
+ return 1 / scale;
+ }
+ if(shape > 1)
+ {
+ return 0;
+ }
+ return policies::raise_overflow_error<RealType>(function, 0, Policy());
}
result = exp(-pow(x / scale, shape));
- result *= pow(x / scale, shape) * shape / x;
+ result *= pow(x / scale, shape - 1) * shape / scale;
return result;
}
Modified: trunk/libs/math/test/test_weibull.cpp
==============================================================================
--- trunk/libs/math/test/test_weibull.cpp (original)
+++ trunk/libs/math/test/test_weibull.cpp 2012-05-28 12:27:00 EDT (Mon, 28 May 2012)
@@ -311,22 +311,31 @@
//
// Special cases:
//
- BOOST_CHECK(pdf(dist, 0) == 0);
BOOST_CHECK(cdf(dist, 0) == 0);
BOOST_CHECK(cdf(complement(dist, 0)) == 1);
BOOST_CHECK(quantile(dist, 0) == 0);
BOOST_CHECK(quantile(complement(dist, 1)) == 0);
+ BOOST_CHECK_EQUAL(pdf(weibull_distribution<RealType>(1, 1), 0), 1);
+
//
// Error checks:
//
- BOOST_CHECK_THROW(weibull_distribution<RealType>(0, -1), std::domain_error);
+ BOOST_CHECK_THROW(weibull_distribution<RealType>(1, -1), std::domain_error);
BOOST_CHECK_THROW(weibull_distribution<RealType>(-1, 1), std::domain_error);
+ BOOST_CHECK_THROW(weibull_distribution<RealType>(1, 0), std::domain_error);
+ BOOST_CHECK_THROW(weibull_distribution<RealType>(0, 1), std::domain_error);
BOOST_CHECK_THROW(pdf(dist, -1), std::domain_error);
BOOST_CHECK_THROW(cdf(dist, -1), std::domain_error);
BOOST_CHECK_THROW(cdf(complement(dist, -1)), std::domain_error);
BOOST_CHECK_THROW(quantile(dist, 1), std::overflow_error);
BOOST_CHECK_THROW(quantile(complement(dist, 0)), std::overflow_error);
+ BOOST_CHECK_THROW(quantile(dist, -1), std::domain_error);
+ BOOST_CHECK_THROW(quantile(complement(dist, -1)), std::domain_error);
+
+ BOOST_CHECK_EQUAL(pdf(dist, 0), exp(-pow(RealType(0) / RealType(3), RealType(2))) * pow(RealType(0), RealType(1)) * RealType(2) / RealType(3));
+ BOOST_CHECK_EQUAL(pdf(weibull_distribution<RealType>(1, 3), 0), exp(-pow(RealType(0) / RealType(3), RealType(1))) * pow(RealType(0), RealType(0)) * RealType(1) / RealType(3));
+ BOOST_CHECK_THROW(pdf(weibull_distribution<RealType>(0.5, 3), 0), std::overflow_error);
} // template <class RealType>void test_spots(RealType)
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk