Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79836 - trunk/boost/math/distributions
From: pbristow_at_[hidden]
Date: 2012-08-01 13:11:31


Author: pbristow
Date: 2012-08-01 13:11:31 EDT (Wed, 01 Aug 2012)
New Revision: 79836
URL: http://svn.boost.org/trac/boost/changeset/79836

Log:
Back to plan A! not defined for v <= k - no infinity from moments.
(TODO use normal for df = infinity?)
Text files modified:
   trunk/boost/math/distributions/students_t.hpp | 73 ++++++++-------------------------------
   1 files changed, 15 insertions(+), 58 deletions(-)

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-01 13:11:31 EDT (Wed, 01 Aug 2012)
@@ -325,34 +325,16 @@
 { // http://en.wikipedia.org/wiki/Student%27s_t-distribution
   // Revised for https://svn.boost.org/trac/boost/ticket/7177
   RealType df = dist.degrees_of_freedom();
- if (!(boost::math::isfinite)(df))
+ if (!(boost::math::isfinite)(df) || (df <= 2))
   { // Infinity or NaN
- policies::raise_domain_error<RealType>(
- "boost::math::variance(students_t_distribution<%1%> const&, %1%)",
- "variance is undefined for nonfinite degrees of freedom, but got %1%.",
- df, Policy());
- return std::numeric_limits<RealType>::quiet_NaN(); // Undefined.
- }
- if (df > 2)
- { // normal case.
- return df / (df - 2);
- }
- if ((df > 1) && (df <= 2))
- { //
- policies::raise_overflow_error<RealType>(
- "boost::math::variance(students_t_distribution<%1%> const&, %1%)",
- "variance is infinity for 1 < degrees of freedom <= 2.",
- Policy());
- return std::numeric_limits<RealType>::infinity(); // Infinity.
- }
- else
- {
+
      policies::raise_domain_error<RealType>(
       "boost::math::variance(students_t_distribution<%1%> const&, %1%)",
- "variance is undefined for degrees of freedom <= 1, but got %1%.",
+ "variance is undefined for degrees of freedom <= 2, but got %1%.",
       df, Policy());
     return std::numeric_limits<RealType>::quiet_NaN(); // Undefined.
   }
+ return df / (df - 2);
 } // variance
 
 template <class RealType, class Policy>
@@ -376,26 +358,14 @@
    RealType df = dist.degrees_of_freedom();
    if((!(boost::math::isfinite)(df)) || (df <= 4))
    { // Undefined or infinity for moment k = 4.
- RealType result;
- if ((df > 2) && (df <= 4))
- {
- policies::raise_overflow_error<RealType>(
- "boost::math::kurtosis(students_t_distribution<%1%> const&, %1%)",
- "Kurtosis is infinity for 2 < degrees of freedom <= 4.",
- Policy());
- return std::numeric_limits<RealType>::infinity(); // Infinity.
- }
- else
- {
- policies::raise_domain_error<RealType>(
- "boost::math::kurtosis(students_t_distribution<%1%> const&, %1%)",
- "Kurtosis is undefined for degrees of freedom <= 2, but got %1%.",
- df, Policy());
+ policies::raise_domain_error<RealType>(
+ "boost::math::kurtosis(students_t_distribution<%1%> const&, %1%)",
+ "Kurtosis is undefined for degrees of freedom <= 4, but got %1%.",
+ df, Policy());
         return std::numeric_limits<RealType>::quiet_NaN(); // Undefined.
- }
- return result;
    }
- return 3 * (df - 2) / (df - 4);
+ //return 3 * (df - 2) / (df - 4);
+ return 6 / (df - 4) + 3;
 }
 
 template <class RealType, class Policy>
@@ -406,24 +376,11 @@
    RealType df = dist.degrees_of_freedom();
    if((!(boost::math::isfinite)(df)) || (df <= 4))
    { // Undefined or infinity for moment k = 4.
- RealType result;
- if ((df > 2) && (df <= 4))
- {
- policies::raise_overflow_error<RealType>(
- "boost::math::kurtosis_excess(students_t_distribution<%1%> const&, %1%)",
- "Kurtosis_excess is infinity for 2 < degrees of freedom <= 4.",
- Policy());
- return std::numeric_limits<RealType>::infinity(); // Infinity.
- }
- else
- {
- policies::raise_domain_error<RealType>(
- "boost::math::kurtosis_excess(students_t_distribution<%1%> const&, %1%)",
- "Kurtosis_excess is undefined for degrees of freedom <= 2, but got %1%.",
- df, Policy());
- return std::numeric_limits<RealType>::quiet_NaN(); // Undefined.
- }
- return result;
+ policies::raise_domain_error<RealType>(
+ "boost::math::kurtosis_excess(students_t_distribution<%1%> const&, %1%)",
+ "Kurtosis_excess is undefined for degrees of freedom <= 4, but got %1%.",
+ df, Policy());
+ return std::numeric_limits<RealType>::quiet_NaN(); // Undefined.
    }
    return 6 / (df - 4);
 }


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