|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78783 - in trunk: boost/math/distributions libs/math/test
From: john_at_[hidden]
Date: 2012-05-31 07:15:43
Author: johnmaddock
Date: 2012-05-31 07:15:42 EDT (Thu, 31 May 2012)
New Revision: 78783
URL: http://svn.boost.org/trac/boost/changeset/78783
Log:
Update more distribution tests for fisher_f and extreme_value and fix failures.
Refs #6934.
Text files modified:
trunk/boost/math/distributions/extreme_value.hpp | 49 +++++++++++++++++++++++++++++++++++----
trunk/boost/math/distributions/fisher_f.hpp | 4 +-
trunk/libs/math/test/test_extreme_value.cpp | 14 ++++++++++
trunk/libs/math/test/test_fisher_f.cpp | 3 +
4 files changed, 60 insertions(+), 10 deletions(-)
Modified: trunk/boost/math/distributions/extreme_value.hpp
==============================================================================
--- trunk/boost/math/distributions/extreme_value.hpp (original)
+++ trunk/boost/math/distributions/extreme_value.hpp 2012-05-31 07:15:42 EDT (Thu, 31 May 2012)
@@ -37,11 +37,11 @@
template <class RealType, class Policy>
inline bool verify_scale_b(const char* function, RealType b, RealType* presult, const Policy& pol)
{
- if(b <= 0)
+ if((b <= 0) || !(boost::math::isfinite)(b))
{
*presult = policies::raise_domain_error<RealType>(
function,
- "The scale parameter \"b\" must be > 0, but was: %1%.", b, pol);
+ "The scale parameter \"b\" must be finite and > 0, but was: %1%.", b, pol);
return false;
}
return true;
@@ -61,6 +61,7 @@
{
RealType err;
detail::verify_scale_b("boost::math::extreme_value_distribution<%1%>::extreme_value_distribution", b, &err, Policy());
+ detail::check_finite("boost::math::extreme_value_distribution<%1%>::extreme_value_distribution", a, &err, Policy());
} // extreme_value_distribution
RealType location()const { return m_a; }
@@ -76,7 +77,9 @@
inline const std::pair<RealType, RealType> range(const extreme_value_distribution<RealType, Policy>& /*dist*/)
{ // Range of permissible values for random variable x.
using boost::math::tools::max_value;
- return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>());
+ return std::pair<RealType, RealType>(
+ std::numeric_limits<RealType>::has_infinity ? -std::numeric_limits<RealType>::infinity() : -max_value<RealType>(),
+ std::numeric_limits<RealType>::has_infinity ? std::numeric_limits<RealType>::infinity() : max_value<RealType>());
}
template <class RealType, class Policy>
@@ -92,10 +95,18 @@
{
BOOST_MATH_STD_USING // for ADL of std functions
+ static const char* function = "boost::math::pdf(const extreme_value_distribution<%1%>&, %1%)";
+
RealType a = dist.location();
RealType b = dist.scale();
RealType result = 0;
- if(0 == detail::verify_scale_b("boost::math::pdf(const extreme_value_distribution<%1%>&, %1%)", b, &result, Policy()))
+ if((boost::math::isinf)(x))
+ return 0.0f;
+ if(0 == detail::verify_scale_b(function, b, &result, Policy()))
+ return result;
+ if(0 == detail::check_finite(function, a, &result, Policy()))
+ return result;
+ if(0 == detail::check_x(function, x, &result, Policy()))
return result;
result = exp((a-x)/b) * exp(-exp((a-x)/b)) / b;
return result;
@@ -106,10 +117,20 @@
{
BOOST_MATH_STD_USING // for ADL of std functions
+ static const char* function = "boost::math::cdf(const extreme_value_distribution<%1%>&, %1%)";
+
+ if((boost::math::isinf)(x))
+ return x < 0 ? 0.0f : 1.0f;
RealType a = dist.location();
RealType b = dist.scale();
RealType result = 0;
- if(0 == detail::verify_scale_b("boost::math::cdf(const extreme_value_distribution<%1%>&, %1%)", b, &result, Policy()))
+ if(0 == detail::verify_scale_b(function, b, &result, Policy()))
+ return result;
+ if(0 == detail::check_finite(function, a, &result, Policy()))
+ return result;
+ if(0 == detail::check_finite(function, a, &result, Policy()))
+ return result;
+ if(0 == detail::check_x("boost::math::cdf(const extreme_value_distribution<%1%>&, %1%)", x, &result, Policy()))
return result;
result = exp(-exp((a-x)/b));
@@ -129,6 +150,8 @@
RealType result = 0;
if(0 == detail::verify_scale_b(function, b, &result, Policy()))
return result;
+ if(0 == detail::check_finite(function, a, &result, Policy()))
+ return result;
if(0 == detail::check_probability(function, p, &result, Policy()))
return result;
@@ -147,10 +170,18 @@
{
BOOST_MATH_STD_USING // for ADL of std functions
+ static const char* function = "boost::math::cdf(const extreme_value_distribution<%1%>&, %1%)";
+
+ if((boost::math::isinf)(c.param))
+ return c.param < 0 ? 1.0f : 0.0f;
RealType a = c.dist.location();
RealType b = c.dist.scale();
RealType result = 0;
- if(0 == detail::verify_scale_b("boost::math::cdf(const extreme_value_distribution<%1%>&, %1%)", b, &result, Policy()))
+ if(0 == detail::verify_scale_b(function, b, &result, Policy()))
+ return result;
+ if(0 == detail::check_finite(function, a, &result, Policy()))
+ return result;
+ if(0 == detail::check_x(function, c.param, &result, Policy()))
return result;
result = -boost::math::expm1(-exp((a-c.param)/b), Policy());
@@ -171,6 +202,8 @@
RealType result = 0;
if(0 == detail::verify_scale_b(function, b, &result, Policy()))
return result;
+ if(0 == detail::check_finite(function, a, &result, Policy()))
+ return result;
if(0 == detail::check_probability(function, q, &result, Policy()))
return result;
@@ -192,6 +225,8 @@
RealType result = 0;
if(0 == detail::verify_scale_b("boost::math::mean(const extreme_value_distribution<%1%>&)", b, &result, Policy()))
return result;
+ if(0 == detail::check_scale("boost::math::mean(const extreme_value_distribution<%1%>&)", a, &result, Policy()))
+ return result;
return a + constants::euler<RealType>() * b;
}
@@ -204,6 +239,8 @@
RealType result = 0;
if(0 == detail::verify_scale_b("boost::math::standard_deviation(const extreme_value_distribution<%1%>&)", b, &result, Policy()))
return result;
+ if(0 == detail::check_scale("boost::math::standard_deviation(const extreme_value_distribution<%1%>&)", dist.location(), &result, Policy()))
+ return result;
return constants::pi<RealType>() * b / sqrt(static_cast<RealType>(6));
}
Modified: trunk/boost/math/distributions/fisher_f.hpp
==============================================================================
--- trunk/boost/math/distributions/fisher_f.hpp (original)
+++ trunk/boost/math/distributions/fisher_f.hpp 2012-05-31 07:15:42 EDT (Thu, 31 May 2012)
@@ -231,12 +231,12 @@
RealType p = c.param;
// Error check:
RealType error_result = 0;
- if(false == detail::check_df(
+ if(false == (detail::check_df(
function, df1, &error_result, Policy())
&& detail::check_df(
function, df2, &error_result, Policy())
&& detail::check_probability(
- function, p, &error_result, Policy()))
+ function, p, &error_result, Policy())))
return error_result;
RealType x, y;
Modified: trunk/libs/math/test/test_extreme_value.cpp
==============================================================================
--- trunk/libs/math/test/test_extreme_value.cpp (original)
+++ trunk/libs/math/test/test_extreme_value.cpp 2012-05-31 07:15:42 EDT (Thu, 31 May 2012)
@@ -13,6 +13,7 @@
#include <boost/test/test_exec_monitor.hpp> // Boost.Test
#include <boost/test/floating_point_comparison.hpp>
+#include "test_out_of_range.hpp"
#include <iostream>
using std::cout;
@@ -124,7 +125,7 @@
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::standard_deviation(
- extreme_value_distribution<RealType>(-1, 0.5)),
+ extreme_value_distribution<RealType>(1, 0.5)),
static_cast<RealType>(0.6412749150809320477720181798355L),
tolerance); // %
BOOST_CHECK_CLOSE(
@@ -179,6 +180,17 @@
BOOST_CHECK_THROW(
quantile(dist, RealType(2)),
std::domain_error);
+ check_out_of_range<extreme_value_distribution<RealType> >(1, 2);
+ if(std::numeric_limits<RealType>::has_infinity)
+ {
+ RealType inf = std::numeric_limits<RealType>::infinity();
+ BOOST_CHECK_EQUAL(pdf(extreme_value_distribution<RealType>(), -inf), 0);
+ BOOST_CHECK_EQUAL(pdf(extreme_value_distribution<RealType>(), inf), 0);
+ BOOST_CHECK_EQUAL(cdf(extreme_value_distribution<RealType>(), -inf), 0);
+ BOOST_CHECK_EQUAL(cdf(extreme_value_distribution<RealType>(), inf), 1);
+ BOOST_CHECK_EQUAL(cdf(complement(extreme_value_distribution<RealType>(), -inf)), 1);
+ BOOST_CHECK_EQUAL(cdf(complement(extreme_value_distribution<RealType>(), inf)), 0);
+ }
} // template <class RealType>void test_spots(RealType)
int test_main(int, char* [])
Modified: trunk/libs/math/test/test_fisher_f.cpp
==============================================================================
--- trunk/libs/math/test/test_fisher_f.cpp (original)
+++ trunk/libs/math/test/test_fisher_f.cpp 2012-05-31 07:15:42 EDT (Thu, 31 May 2012)
@@ -16,6 +16,7 @@
#include <boost/test/test_exec_monitor.hpp> // for test_main
#include <boost/test/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE
+#include "test_out_of_range.hpp"
#include <iostream>
using std::cout;
@@ -498,7 +499,7 @@
fisher_f_distribution<RealType>(8, 8),
static_cast<RealType>(1.1))), std::domain_error
);
-
+ check_out_of_range<fisher_f_distribution<RealType> >(2, 3);
} // template <class RealType>void test_spots(RealType)
int test_main(int, char* [])
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