|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80156 - trunk/boost/math/distributions
From: pbristow_at_[hidden]
Date: 2012-08-23 09:43:44
Author: pbristow
Date: 2012-08-23 09:43:44 EDT (Thu, 23 Aug 2012)
New Revision: 80156
URL: http://svn.boost.org/trac/boost/changeset/80156
Log:
Use normal distribution for v > 1/eps
Text files modified:
trunk/boost/math/distributions/non_central_t.hpp | 11 ++++++++++-
trunk/boost/math/distributions/students_t.hpp | 22 ++++------------------
2 files changed, 14 insertions(+), 19 deletions(-)
Modified: trunk/boost/math/distributions/non_central_t.hpp
==============================================================================
--- trunk/boost/math/distributions/non_central_t.hpp (original)
+++ trunk/boost/math/distributions/non_central_t.hpp 2012-08-23 09:43:44 EDT (Thu, 23 Aug 2012)
@@ -520,7 +520,16 @@
return delta;
}
BOOST_MATH_STD_USING
- return delta * sqrt(v / 2) * tgamma_delta_ratio((v - 1) * 0.5f, T(0.5f), pol);
+ if (v > 1 / boost::math::tools::epsilon<T>() )
+ {
+ normal_distribution<T, Policy> n(delta, 1);
+ return boost::math::mean(n);
+ }
+ else
+ {
+ return delta * sqrt(v / 2) * tgamma_delta_ratio((v - 1) * 0.5f, T(0.5f), pol);
+ }
+ // Other moments use mean so using normal distribution is propagated.
}
template <class T, class Policy>
Modified: trunk/boost/math/distributions/students_t.hpp
==============================================================================
--- trunk/boost/math/distributions/students_t.hpp (original)
+++ trunk/boost/math/distributions/students_t.hpp 2012-08-23 09:43:44 EDT (Thu, 23 Aug 2012)
@@ -27,20 +27,6 @@
namespace boost{ namespace math{
-template <class RealType, class Policy>
-inline bool check_df(const char* function, RealType const& df, RealType* result, const Policy& pol)
-{ // df > 0 or +infinity are allowed.
- // if((df <= 0) || (boost::math::isnan)(df)) // but use signbit to ensure catch -inf and -NaN.
- if(((boost::math::signbit)(df) != 0) || (boost::math::isnan)(df))
- { // is bad df <= 0 or NaN or -infinity.
- *result = policies::raise_domain_error<RealType>(
- function,
- "Degrees of freedom argument is %1%, but must be > 0 !", df, pol);
- return false;
- }
- return true;
-} // check_df
-
template <class RealType = double, class Policy = policies::policy<> >
class students_t_distribution
{
@@ -51,7 +37,7 @@
students_t_distribution(RealType df) : df_(df)
{ // Constructor.
RealType result;
- check_df( // Checks that df > 0 or df == inf.
+ detail::check_df_gt0_to_inf( // Checks that df > 0 or df == inf.
"boost::math::students_t_distribution<%1%>::students_t_distribution", df_, &result, Policy());
} // students_t_distribution
@@ -102,7 +88,7 @@
"boost::math::pdf(const students_t_distribution<%1%>&, %1%)", x, &error_result, Policy()))
return error_result;
RealType df = dist.degrees_of_freedom();
- if(false == check_df( // Check that df > 0 or == +infinity.
+ if(false == detail::check_df_gt0_to_inf( // Check that df > 0 or == +infinity.
"boost::math::pdf(const students_t_distribution<%1%>&, %1%)", df, &error_result, Policy()))
return error_result;
@@ -150,7 +136,7 @@
RealType df = dist.degrees_of_freedom();
// Error check:
- if(false == check_df( // Check that df > 0 or == +infinity.
+ if(false == detail::check_df_gt0_to_inf( // Check that df > 0 or == +infinity.
"boost::math::cdf(const students_t_distribution<%1%>&, %1%)", df, &error_result, Policy()))
return error_result;
@@ -224,7 +210,7 @@
RealType df = dist.degrees_of_freedom();
static const char* function = "boost::math::quantile(const students_t_distribution<%1%>&, %1%)";
RealType error_result;
- if(false == (check_df( // Check that df > 0 or == +infinity.
+ if(false == (detail::check_df_gt0_to_inf( // Check that df > 0 or == +infinity.
function, df, &error_result, Policy())
&& detail::check_probability(function, probability, &error_result, Policy())))
return error_result;
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