Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49485 - in sandbox/math_toolkit: boost/math boost/math/distributions libs/math/doc/sf_and_dist libs/math/doc/sf_and_dist/distributions libs/math/doc/sf_and_dist/graphs libs/math/test
From: john_at_[hidden]
Date: 2008-10-29 09:10:09


Author: johnmaddock
Date: 2008-10-29 09:10:08 EDT (Wed, 29 Oct 2008)
New Revision: 49485
URL: http://svn.boost.org/trac/boost/changeset/49485

Log:
Added logistic distribution.
Added:
   sandbox/math_toolkit/boost/math/distributions/logistic.hpp (contents, props changed)
      - copied, changed from r49389, /sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp
   sandbox/math_toolkit/libs/math/doc/sf_and_dist/distributions/logistic.qbk (contents, props changed)
   sandbox/math_toolkit/libs/math/doc/sf_and_dist/graphs/logistic_pdf.png (contents, props changed)
   sandbox/math_toolkit/libs/math/doc/sf_and_dist/graphs/logistic_pdf.svg (contents, props changed)
   sandbox/math_toolkit/libs/math/test/test_logistic_dist.cpp (contents, props changed)
      - copied, changed from r49389, /sandbox/SOC/2008/parrallel_math/libs/math/test/gsoc_test_logistic_dist.cpp
Text files modified:
   sandbox/math_toolkit/boost/math/distributions.hpp | 1
   sandbox/math_toolkit/boost/math/distributions/logistic.hpp | 304 ++++++++++++++++++---------------------
   sandbox/math_toolkit/libs/math/doc/sf_and_dist/dist_reference.qbk | 1
   sandbox/math_toolkit/libs/math/doc/sf_and_dist/roadmap.qbk | 1
   sandbox/math_toolkit/libs/math/test/test_logistic_dist.cpp | 299 ++++++++++++++++++---------------------
   5 files changed, 283 insertions(+), 323 deletions(-)

Modified: sandbox/math_toolkit/boost/math/distributions.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions.hpp 2008-10-29 09:10:08 EDT (Wed, 29 Oct 2008)
@@ -22,6 +22,7 @@
 #include <boost/math/distributions/extreme_value.hpp>
 #include <boost/math/distributions/fisher_f.hpp>
 #include <boost/math/distributions/gamma.hpp>
+#include <boost/math/distributions/logistic.hpp>
 #include <boost/math/distributions/lognormal.hpp>
 #include <boost/math/distributions/negative_binomial.hpp>
 #include <boost/math/distributions/non_central_chi_squared.hpp>

Copied: sandbox/math_toolkit/boost/math/distributions/logistic.hpp (from r49389, /sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp)
==============================================================================
--- /sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/logistic.hpp 2008-10-29 09:10:08 EDT (Wed, 29 Oct 2008)
@@ -1,31 +1,19 @@
-
-// Copyright John Maddock
-// Copyright Paul A. Bristow
-// Copyright Gautam Sewani
-
+// Copyright 2008 Gautam Sewani
+//
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt
 // or copy at http://www.boost.org/LICENSE_1_0.txt)
 
-
-
-
-
-
-
-
-
 #include <boost/math/distributions/fwd.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
 #include <boost/math/distributions/complement.hpp>
 #include <boost/math/special_functions/log1p.hpp>
-
-#include <cmath>
 #include <boost/math/constants/constants.hpp>
 #include <utility>
 
 namespace boost { namespace math {
+
     template <class RealType = double, class Policy = policies::policy<> >
     class logistic_distribution
     {
@@ -80,177 +68,174 @@
     template <class RealType, class Policy>
     inline RealType pdf(const logistic_distribution<RealType, Policy>& dist, const RealType& x)
     {
- RealType scale = dist.scale();
- RealType location = dist.location();
-
- static const char* function = "boost::math::pdf(const logistic_distribution<%1%>&, %1%)";
- if((boost::math::isinf)(x))
- {
+ RealType scale = dist.scale();
+ RealType location = dist.location();
+
+ static const char* function = "boost::math::pdf(const logistic_distribution<%1%>&, %1%)";
+ if((boost::math::isinf)(x))
+ {
           return 0; // pdf + and - infinity is zero.
- }
-
-
- RealType result;
- if(false == detail::check_scale(function, scale , &result, Policy()))
- {
- return result;
- }
- if(false == detail::check_location(function, location, &result, Policy()))
- {
- return result;
- }
- if(false == detail::check_x(function, x, &result, Policy()))
- {
+ }
+
+ RealType result;
+ if(false == detail::check_scale(function, scale , &result, Policy()))
+ {
           return result;
- }
-
- BOOST_MATH_STD_USING
- RealType exp_term=exp((location-x)/scale);
- return ( exp_term )/ ( scale*(1+exp_term)*(1+exp_term ) );
-
-
+ }
+ if(false == detail::check_location(function, location, &result, Policy()))
+ {
+ return result;
+ }
+ if(false == detail::check_x(function, x, &result, Policy()))
+ {
+ return result;
+ }
+
+ BOOST_MATH_STD_USING
+ RealType exp_term = (location - x) / scale;
+ if(fabs(exp_term) > tools::log_max_value<RealType>())
+ return 0;
+ exp_term = exp(exp_term);
+ if((exp_term * scale > 1) && (exp_term > tools::max_value<RealType>() / (scale * exp_term)))
+ return 1 / (scale * exp_term);
+ return (exp_term) / (scale * (1 + exp_term) * (1 + exp_term));
     }
     
     template <class RealType, class Policy>
     inline RealType cdf(const logistic_distribution<RealType, Policy>& dist, const RealType& x)
     {
- RealType scale = dist.scale();
- RealType location = dist.location();
- RealType result; // of checks.
- static const char* function = "boost::math::cdf(const logistic_distribution<%1%>&, %1%)";
- if(false == detail::check_scale(function, scale, &result, Policy()))
- {
+ RealType scale = dist.scale();
+ RealType location = dist.location();
+ RealType result; // of checks.
+ static const char* function = "boost::math::cdf(const logistic_distribution<%1%>&, %1%)";
+ if(false == detail::check_scale(function, scale, &result, Policy()))
+ {
           return result;
- }
-
- if(false == detail::check_location(function, location, &result, Policy()))
- {
+ }
+ if(false == detail::check_location(function, location, &result, Policy()))
+ {
           return result;
- }
-
- if((boost::math::isinf)(x))
- {
+ }
+
+ if((boost::math::isinf)(x))
+ {
           if(x < 0) return 0; // -infinity
           return 1; // + infinity
- }
-
- if(false == detail::check_x(function, x, &result, Policy()))
- {
+ }
+
+ if(false == detail::check_x(function, x, &result, Policy()))
+ {
           return result;
- }
- BOOST_MATH_STD_USING
- RealType power=(location-x)/scale;
- return 1/( 1+exp(power) );
+ }
+ BOOST_MATH_STD_USING
+ RealType power = (location - x) / scale;
+ if(power > tools::log_max_value<RealType>())
+ return 0;
+ if(power < -tools::log_max_value<RealType>())
+ return 1;
+ return 1 / (1 + exp(power));
     }
     
     template <class RealType, class Policy>
     inline RealType quantile(const logistic_distribution<RealType, Policy>& dist, const RealType& p)
     {
- RealType location = dist.location();
- RealType scale = dist.scale();
-
- static const char* function = "boost::math::quantile(const logistic_distribution<%1%>&, %1%)";
-
- RealType result;
- if(false == detail::check_scale(function, scale, &result, Policy()))
- return result;
- if(false == detail::check_location(function, location, &result, Policy()))
- return result;
- if(false == detail::check_probability(function, p, &result, Policy()))
- return result;
-
-
- if(p == 0)
- {
-
- result=policies::raise_underflow_error<RealType>(function,"probability argument is 0, must be >0 and <1",Policy());
- return result;
- }
- if(p == 1)
- {
- result=policies::raise_overflow_error<RealType>(function,"probability argument is 0, must be >0 and <1",Policy());
+ BOOST_MATH_STD_USING
+ RealType location = dist.location();
+ RealType scale = dist.scale();
+
+ static const char* function = "boost::math::quantile(const logistic_distribution<%1%>&, %1%)";
+
+ RealType result;
+ if(false == detail::check_scale(function, scale, &result, Policy()))
           return result;
-
- }
- BOOST_MATH_STD_USING
- //Expressions to try
+ if(false == detail::check_location(function, location, &result, Policy()))
+ return result;
+ if(false == detail::check_probability(function, p, &result, Policy()))
+ return result;
+
+ if(p == 0)
+ {
+ return -policies::raise_overflow_error<RealType>(function,"probability argument is 0, must be >0 and <1",Policy());
+ }
+ if(p == 1)
+ {
+ return policies::raise_overflow_error<RealType>(function,"probability argument is 1, must be >0 and <1",Policy());
+ }
+ //Expressions to try
        //return location+scale*log(p/(1-p));
        //return location+scale*log1p((2*p-1)/(1-p));
-
- //return location - scale*log( (1-p)/p);
+
+ //return location - scale*log( (1-p)/p);
        //return location - scale*log1p((1-2*p)/p);
 
- //return -scale*log(1/p-1) + location;
- return -scale*log1p(1/p-2)+location;
-
+ //return -scale*log(1/p-1) + location;
+ return location - scale * log1p((1 / p) - 2);
      } // RealType quantile(const logistic_distribution<RealType, Policy>& dist, const RealType& p)
     
     template <class RealType, class Policy>
     inline RealType cdf(const complemented2_type<logistic_distribution<RealType, Policy>, RealType>& c)
     {
- RealType location = c.dist.location();
- RealType scale = c.dist.scale();
- RealType x = c.param;
- static const char* function = "boost::math::cdf(const complement(logistic_distribution<%1%>&), %1%)";
-
- if((boost::math::isinf)(x))
- {
+ BOOST_MATH_STD_USING
+ RealType location = c.dist.location();
+ RealType scale = c.dist.scale();
+ RealType x = c.param;
+ static const char* function = "boost::math::cdf(const complement(logistic_distribution<%1%>&), %1%)";
+
+ if((boost::math::isinf)(x))
+ {
           if(x < 0) return 1; // cdf complement -infinity is unity.
           return 0; // cdf complement +infinity is zero
- }
- RealType result;
- if(false == detail::check_scale(function, scale, &result, Policy()))
- return result;
- if(false == detail::check_location(function, location, &result, Policy()))
- return result;
- if(false == detail::check_x(function, x, &result, Policy()))
- return result;
- BOOST_MATH_STD_USING
- RealType power=(x-location)/scale;
- return 1/( 1+exp(power) );
-
+ }
+ RealType result;
+ if(false == detail::check_scale(function, scale, &result, Policy()))
+ return result;
+ if(false == detail::check_location(function, location, &result, Policy()))
+ return result;
+ if(false == detail::check_x(function, x, &result, Policy()))
+ return result;
+ RealType power = (x - location) / scale;
+ if(power > tools::log_max_value<RealType>())
+ return 0;
+ if(power < -tools::log_max_value<RealType>())
+ return 1;
+ return 1 / (1 + exp(power));
     }
- template <class RealType, class Policy>
- inline RealType quantile(const complemented2_type<logistic_distribution<RealType, Policy>, RealType>& c)
- {
- RealType scale = c.dist.scale();
- RealType location = c.dist.location();
- static const char* function = "boost::math::quantile(const complement(logistic_distribution<%1%>&), %1%)";
- RealType result;
- if(false == detail::check_scale(function, scale, &result, Policy()))
- return result;
- if(false == detail::check_location(function, location, &result, Policy()))
- return result;
- RealType q = c.param;
- if(false == detail::check_probability(function, q, &result, Policy()))
- return result;
- using boost::math::tools::max_value;
-
-
- if(q == 1)
- {
- result=policies::raise_underflow_error<RealType>(function,"probability argument is 0, must be >0 and <1",Policy());
- return result;
-
- }
- if(q == 0)
- {
- result=policies::raise_overflow_error<RealType>(function,"probability argument is 0, must be >0 and <1",Policy());
- return result;
-
- }
- //Expressions to try
- BOOST_MATH_STD_USING
- //return location+scale*log((1-q)/q);
- return location+scale*log1p((1-2*q)/(q));
-
- //return location-scale*log(q/(1-q));
- //return location-scale*log1p((2*q-1)/(1-q));
-
- //return location+scale*log(1/q-1);
- //return location+scale*log1p(1/q-2);
 
- }
+ template <class RealType, class Policy>
+ inline RealType quantile(const complemented2_type<logistic_distribution<RealType, Policy>, RealType>& c)
+ {
+ BOOST_MATH_STD_USING
+ RealType scale = c.dist.scale();
+ RealType location = c.dist.location();
+ static const char* function = "boost::math::quantile(const complement(logistic_distribution<%1%>&), %1%)";
+ RealType result;
+ if(false == detail::check_scale(function, scale, &result, Policy()))
+ return result;
+ if(false == detail::check_location(function, location, &result, Policy()))
+ return result;
+ RealType q = c.param;
+ if(false == detail::check_probability(function, q, &result, Policy()))
+ return result;
+ using boost::math::tools::max_value;
+
+ if(q == 1)
+ {
+ return -policies::raise_overflow_error<RealType>(function,"probability argument is 1, but must be >0 and <1",Policy());
+ }
+ if(q == 0)
+ {
+ return policies::raise_overflow_error<RealType>(function,"probability argument is 0, but must be >0 and <1",Policy());
+ }
+ //Expressions to try
+ //return location+scale*log((1-q)/q);
+ return location + scale * log1p((1 - 2 * q) / q);
+
+ //return location-scale*log(q/(1-q));
+ //return location-scale*log1p((2*q-1)/(1-q));
+
+ //return location+scale*log(1/q-1);
+ //return location+scale*log1p(1/q-2);
+ }
     
     template <class RealType, class Policy>
     inline RealType mean(const logistic_distribution<RealType, Policy>& dist)
@@ -264,33 +249,28 @@
       BOOST_MATH_STD_USING
       RealType scale = dist.scale();
       return boost::math::constants::pi<RealType>()*boost::math::constants::pi<RealType>()*scale*scale/3;
-
     } // RealType variance(const logistic_distribution<RealType, Policy>& dist)
     
     template <class RealType, class Policy>
     inline RealType mode(const logistic_distribution<RealType, Policy>& dist)
     {
-
       return dist.location();
     }
     
     template <class RealType, class Policy>
     inline RealType median(const logistic_distribution<RealType, Policy>& dist)
     {
-
       return dist.location();
     }
     template <class RealType, class Policy>
- inline RealType skewness(const logistic_distribution<RealType, Policy>& dist)
+ inline RealType skewness(const logistic_distribution<RealType, Policy>& /*dist*/)
     {
-
       return 0;
     } // RealType skewness(const logistic_distribution<RealType, Policy>& dist)
     
     template <class RealType, class Policy>
- inline RealType kurtosis_excess(const logistic_distribution<RealType, Policy>& dist)
+ inline RealType kurtosis_excess(const logistic_distribution<RealType, Policy>& /*dist*/)
     {
-
       return static_cast<RealType>(6)/5;
     } // RealType kurtosis_excess(const logistic_distribution<RealType, Policy>& dist)
 

Modified: sandbox/math_toolkit/libs/math/doc/sf_and_dist/dist_reference.qbk
==============================================================================
--- sandbox/math_toolkit/libs/math/doc/sf_and_dist/dist_reference.qbk (original)
+++ sandbox/math_toolkit/libs/math/doc/sf_and_dist/dist_reference.qbk 2008-10-29 09:10:08 EDT (Wed, 29 Oct 2008)
@@ -13,6 +13,7 @@
 [include distributions/extreme_value.qbk]
 [include distributions/fisher.qbk]
 [include distributions/gamma.qbk]
+[include distributions/logistic.qbk]
 [include distributions/lognormal.qbk]
 [include distributions/negative_binomial.qbk]
 [include distributions/nc_beta.qbk]

Added: sandbox/math_toolkit/libs/math/doc/sf_and_dist/distributions/logistic.qbk
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/doc/sf_and_dist/distributions/logistic.qbk 2008-10-29 09:10:08 EDT (Wed, 29 Oct 2008)
@@ -0,0 +1,102 @@
+[section:logistic_dist Logistic Distribution]
+
+``#include <boost/math/distributions/logistic.hpp>``
+
+ namespace boost{ namespace math{
+
+ template <class RealType = double,
+ class ``__Policy`` = ``__policy_class`` >
+ class logistic_distribution;
+
+ template <class RealType, class Policy>
+ class logistic_distribution
+ {
+ public:
+ typedef RealType value_type;
+ typedef Policy policy_type;
+ // Construct:
+ logistic_distribution(RealType location = 0, RealType scale = 1);
+ // Accessors:
+ RealType location()const; // location.
+ RealType scale()const; // scale.
+
+ };
+
+ typedef logistic_distribution<> logistic;
+
+ }} // namespaces
+
+The logistic distribution is a continous probability distribution.
+It has two parameters - location and scale. The cumulative distribution
+function of the logistic distribution appears in logistic regression
+and feedforward neural networks. Among other applications,
+United State Chess Federation and FIDE use it to calculate chess ratings.
+
+The following graph shows how the distribution changes as the
+parameters change:
+
+[graph logistic_pdf]
+
+[h4 Member Functions]
+
+ logistic_distribution(RealType u = 0, RealType s = 1);
+
+Constructs a logistic distribution with location /u/ and scale /s/.
+
+Requires `scale > 0`, otherwise a __domain_error is raised.
+
+ RealType location()const;
+
+Returns the location of this distribution.
+
+ RealType scale()const;
+
+Returns the scale of this distribution.
+
+[h4 Non-member Accessors]
+
+All the [link math_toolkit.dist.dist_ref.nmp usual non-member accessor functions]
+that are generic to all distributions are supported: __usual_accessors.
+
+The domain of the random variable is \[-\[max_value\], +\[min_value\]\].
+However, the pdf and cdf support inputs of +[infin] and -[infin]
+as special cases if RealType permits.
+
+At `p=1` and `p=0`, the quantile function returns the result of
++__overflow_error and -__overflow_error, while the compliment
+quantile function returns the result of -__overflow_error and
++__overflow_error respectively.
+
+[h4 Accuracy]
+
+The logistic distribution is implemented in terms of the `std::exp`
+and the `std::log` functions, so it's accuracy is related to the
+accurate implementations of those functions on a given platform.
+While calculating the quantile and the inverse quantile, some
+non-zero position values might cause catastrophic cancellation errors.
+In such cases, only a low /absolute error/ can be guarenteed.
+
+[h4 Implementation]
+
+[table
+[[Function][Implementation Notes]]
+[[pdf][Using the relation: pdf = e[super -(x-u)/s] / (s*(1+e[super -(x-u)/s])[super 2])]]
+[[cdf][Using the relation: p = 1/(1+e[super -(x-u)/s])]]
+[[cdf complement][Using the relation: q = 1/(1+e[super (x-u)/s])]]
+[[quantile][Using the relation: x = u - s*log(1/p-1)]]
+[[quantile from the complement][Using the relation: x = u + s*log(p/1-p)]]
+[[mean][u]]
+[[mode][The same as the mean.]]
+[[skewness][0]]
+[[kurtosis excess][6/5]]
+[[variance][ ([pi]*s)[super 2] / 3]]
+]
+
+[endsect]
+
+[/ logistic.qbk
+ Copyright 2006, 2007 John Maddock and Paul A. Bristow.
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt).
+]

Added: sandbox/math_toolkit/libs/math/doc/sf_and_dist/graphs/logistic_pdf.png
==============================================================================
Binary file. No diff available.

Added: sandbox/math_toolkit/libs/math/doc/sf_and_dist/graphs/logistic_pdf.svg
==============================================================================
Binary file. No diff available.

Modified: sandbox/math_toolkit/libs/math/doc/sf_and_dist/roadmap.qbk
==============================================================================
--- sandbox/math_toolkit/libs/math/doc/sf_and_dist/roadmap.qbk (original)
+++ sandbox/math_toolkit/libs/math/doc/sf_and_dist/roadmap.qbk 2008-10-29 09:10:08 EDT (Wed, 29 Oct 2008)
@@ -4,6 +4,7 @@
 
 * Added support for MPFR as a bignum type.
 * Added some full specializations of the policy classes to reduce compile times.
+* Added logistic distribution, from Gautam Sewani's Google Summer of Code project.
 
 [h4 Boost-1.37.0]
 

Copied: sandbox/math_toolkit/libs/math/test/test_logistic_dist.cpp (from r49389, /sandbox/SOC/2008/parrallel_math/libs/math/test/gsoc_test_logistic_dist.cpp)
==============================================================================
--- /sandbox/SOC/2008/parrallel_math/libs/math/test/gsoc_test_logistic_dist.cpp (original)
+++ sandbox/math_toolkit/libs/math/test/test_logistic_dist.cpp 2008-10-29 09:10:08 EDT (Wed, 29 Oct 2008)
@@ -1,20 +1,14 @@
-
-
-// Copyright John Maddock
-// Copyright Paul A. Bristow
-// Copyright Gautam Sewani
+// Copyright 2008 Gautam Sewani
 
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt
 // or copy at http://www.boost.org/LICENSE_1_0.txt)
 
-
-
 #define BOOST_MATH_UNDERFLOW_ERROR_POLICY throw_on_error
 #define BOOST_MATH_OVERFLOW_ERROR_POLICY throw_on_error
 #include <boost/math/concepts/real_concept.hpp> // for real_concept
-#include <boost/math/distributions/gsoc_logistic.hpp>
+#include <boost/math/distributions/logistic.hpp>
     using boost::math::logistic_distribution;
 
 #include <boost/test/included/test_exec_monitor.hpp> // Boost.Test
@@ -32,33 +26,33 @@
 {
    BOOST_CHECK_CLOSE(
       ::boost::math::cdf(
- logistic_distribution<RealType>(location,scale),
- x),
- p,
- tolerance); // %
+ logistic_distribution<RealType>(location,scale),
+ x),
+ p,
+ tolerance); // %
    BOOST_CHECK_CLOSE(
       ::boost::math::cdf(
- complement(logistic_distribution<RealType>(location,scale),
- x)),
- q,
- tolerance); // %
+ complement(logistic_distribution<RealType>(location,scale),
+ x)),
+ q,
+ tolerance); // %
    if(p < 0.999)
    {
       BOOST_CHECK_CLOSE(
          ::boost::math::quantile(
- logistic_distribution<RealType>(location,scale),
- p),
- x,
- tolerance); // %
+ logistic_distribution<RealType>(location,scale),
+ p),
+ x,
+ tolerance); // %
    }
    if(q < 0.999)
    {
       BOOST_CHECK_CLOSE(
          ::boost::math::quantile(
- complement(logistic_distribution<RealType>(location,scale),
- q)),
- x,
- tolerance); // %
+ complement(logistic_distribution<RealType>(location,scale),
+ q)),
+ x,
+ tolerance); // %
    }
 }
 
@@ -73,15 +67,15 @@
       static_cast<RealType>(1e-33L),
       boost::math::tools::epsilon<RealType>());
    cout<<"Absolute tolerance:"<<tolerance<<endl;
-
+
    tolerance *= 50 * 100;
    // # pragma warning(disable: 4100) // unreferenced formal parameter.
    // prevent his spurious warning.
    if (T != 0)
    {
- cout << "Expect parameter T == 0!" << endl;
+ cout << "Expect parameter T == 0!" << endl;
    }
- cout << "Tolerance for type " << typeid(T).name() << " is " << tolerance << " %" << endl;
+ cout << "Tolerance for type " << typeid(T).name() << " is " << tolerance << " %" << endl;
 
    test_spot(
       static_cast<RealType>(1), // location
@@ -98,8 +92,8 @@
       static_cast<RealType>(0.281215878622547904873088053477813L), // p
       static_cast<RealType>(0.718784121377452095126911946522187L), //q
       tolerance);
-
- test_spot(
+
+ test_spot(
       static_cast<RealType>(1.2345L), // location
       static_cast<RealType>(0.12345L), // scale
       static_cast<RealType>(3.123123123L),//x
@@ -108,14 +102,12 @@
       tolerance);
 
 
- //High probability
- test_spot(
+ //High probability
+ test_spot(
       static_cast<RealType>(1), // location
       static_cast<RealType>(0.5L), // scale
       static_cast<RealType>(10), // x
       static_cast<RealType>(0.99999998477002048723965105559179L), // p
-
-
       static_cast<RealType>(1.5229979512760348944408208801237e-8L), //q
       tolerance);
 
@@ -127,8 +119,8 @@
       static_cast<RealType>(0.0724264853615177178439235061476928L), // p
       static_cast<RealType>(0.927573514638482282156076493852307L), //q
       tolerance);
-
-
+
+
    test_spot(
       static_cast<RealType>(5), // location
       static_cast<RealType>(2), // scale
@@ -138,10 +130,6 @@
       tolerance);
 
 
-
-
-
-
    //test value to check cancellation error in straight/complimented quantile
    //the subtraction in the formula location-scale*log term introduces catastrophics cancellator error if location and scale*log term are close
    //For these values, the tests fail at tolerance, but work at 100*tolerance
@@ -153,24 +141,24 @@
       static_cast<RealType>(0.3L), //q
       80*tolerance);
 
- test_spot(
+ test_spot(
       static_cast<RealType>(1.2345L), // location
       static_cast<RealType>(0.12345L), // scale
       static_cast<RealType>(0.0012345L), // x
       static_cast<RealType>(0.0000458541039469413343331170952855318L), // p
       static_cast<RealType>(0.999954145896053058665666882904714L), //q
       80*tolerance);
-
 
-
+
+
    test_spot(
       static_cast<RealType>(5L), // location
       static_cast<RealType>(2L), // scale
       static_cast<RealType>(0.0012345L), // x
       static_cast<RealType>(0.0759014628704232983512906076564256L), // p
       static_cast<RealType>(0.924098537129576701648709392343574L), //q
- 80*tolerance);
-
+ 80*tolerance);
+
    //negative location
    test_spot(
       static_cast<RealType>(-123.123123L), // location
@@ -179,49 +167,48 @@
       static_cast<RealType>(0.999999999999999999999999984171276L), // p
       static_cast<RealType>(1.58287236765203121622150720373972e-26L), //q
       tolerance);
-//PDF Testing
+ //PDF Testing
    BOOST_CHECK_CLOSE(
       ::boost::math::pdf(
- logistic_distribution<RealType>(5,2),
+ logistic_distribution<RealType>(5,2),
          static_cast<RealType>(0.125L) ),//x
          static_cast<RealType>(0.0369500730133475464584898192104821L), // probability
- tolerance); // %
+ tolerance); // %
 
    BOOST_CHECK_CLOSE(
       ::boost::math::pdf(
- logistic_distribution<RealType>(1.2345L,0.12345L),
+ logistic_distribution<RealType>(static_cast<RealType>(1.2345L), static_cast<RealType>(0.12345L)),
          static_cast<RealType>(0.0012345L) ),//x
          static_cast<RealType>(0.000371421639109700748742498671686243L), // probability
- tolerance); // %
+ tolerance); // %
    BOOST_CHECK_CLOSE(
       ::boost::math::pdf(
- logistic_distribution<RealType>(2,1),
+ logistic_distribution<RealType>(2,1),
          static_cast<RealType>(2L) ),//x
          static_cast<RealType>(0.25L), // probability
- tolerance); // %
-
-//Extreme value testing
+ tolerance); // %
 
- if(std::numeric_limits<RealType>::has_infinity)
- {
- BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), +std::numeric_limits<RealType>::infinity()), 0); // x = + infinity, pdf = 0
- BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, pdf = 0
- BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), +std::numeric_limits<RealType>::infinity()), 1); // x = + infinity, cdf = 1
- BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, cdf = 0
- BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), +std::numeric_limits<RealType>::infinity())), 0); // x = + infinity, c cdf = 0
- BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), -std::numeric_limits<RealType>::infinity())), 1); // x = - infinity, c cdf = 1
- //Does the quantile return max_value or infinity?
- /*
- BOOST_CHECK_EQUAL(quantile(logistic_distribution<RealType>(), static_cast<RealType>(1)), +std::numeric_limits<RealType>::infinity()); // x = + infinity, cdf = 1
- BOOST_CHECK_EQUAL(quantile(logistic_distribution<RealType>(), static_cast<RealType>(0)), -std::numeric_limits<RealType>::infinity()); // x = - infinity, cdf = 0
- BOOST_CHECK_EQUAL(quantile(complement(logistic_distribution<RealType>(), static_cast<RealType>(0))), +std::numeric_limits<RealType>::infinity());
-// x = + infinity, c cdf = 0
- BOOST_CHECK_EQUAL(quantile(complement(logistic_distribution<RealType>(), static_cast<RealType>(1))), -std::numeric_limits<RealType>::infinity());
- */
+ //Extreme value testing
 
- }
-
-
+ if(std::numeric_limits<RealType>::has_infinity)
+ {
+ BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), +std::numeric_limits<RealType>::infinity()), 0); // x = + infinity, pdf = 0
+ BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, pdf = 0
+ BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), +std::numeric_limits<RealType>::infinity()), 1); // x = + infinity, cdf = 1
+ BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, cdf = 0
+ BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), +std::numeric_limits<RealType>::infinity())), 0); // x = + infinity, c cdf = 0
+ BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), -std::numeric_limits<RealType>::infinity())), 1); // x = - infinity, c cdf = 1
+ }
+ BOOST_CHECK_THROW(quantile(logistic_distribution<RealType>(), static_cast<RealType>(1)), std::overflow_error); // x = + infinity, cdf = 1
+ BOOST_CHECK_THROW(quantile(logistic_distribution<RealType>(), static_cast<RealType>(0)), std::overflow_error); // x = - infinity, cdf = 0
+ BOOST_CHECK_THROW(quantile(complement(logistic_distribution<RealType>(), static_cast<RealType>(1))), std::overflow_error); // x = - infinity, cdf = 0
+ BOOST_CHECK_THROW(quantile(complement(logistic_distribution<RealType>(), static_cast<RealType>(0))), std::overflow_error); // x = + infinity, cdf = 1
+ BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), +boost::math::tools::max_value<RealType>()), 1); // x = + infinity, cdf = 1
+ BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), -boost::math::tools::max_value<RealType>()), 0); // x = - infinity, cdf = 0
+ BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), +boost::math::tools::max_value<RealType>())), 0); // x = + infinity, c cdf = 0
+ BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), -boost::math::tools::max_value<RealType>())), 1); // x = - infinity, c cdf = 1
+ BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), +boost::math::tools::max_value<RealType>()), 0); // x = + infinity, pdf = 0
+ BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), -boost::math::tools::max_value<RealType>()), 0); // x = - infinity, pdf = 0
 
    //
    // Things that are errors:
@@ -229,100 +216,90 @@
    //2. x being NAN
    //3. Probabilies being outside (0,1)
 
-
-
+ //location/scale can't be infinity
+ if(std::numeric_limits<RealType>::has_infinity) {
+ BOOST_CHECK_THROW(
+ logistic_distribution<RealType> dist(std::numeric_limits<RealType>::infinity(),0.5),
+ std::domain_error);
+ BOOST_CHECK_THROW(
+ logistic_distribution<RealType> dist(0.5,std::numeric_limits<RealType>::infinity()),
+ std::domain_error);
+ }
+ //scale can't be negative or 0
+ BOOST_CHECK_THROW(
+ logistic_distribution<RealType> dist(0.5,-0.5),
+ std::domain_error);
+ BOOST_CHECK_THROW(
+ logistic_distribution<RealType> dist(0.5,0),
+ std::domain_error);
 
+ logistic_distribution<RealType> dist(0.5,0.5);
+ //x can't be NaN,p can't be NaN
 
+ if (std::numeric_limits<RealType>::has_quiet_NaN)
+ {
+ // No longer allow x to be NaN, then these tests should throw.
+ BOOST_CHECK_THROW(pdf(dist, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
+ BOOST_CHECK_THROW(cdf(dist, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
+ BOOST_CHECK_THROW(cdf(complement(dist, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // x = + infinity
+ BOOST_CHECK_THROW(quantile(dist, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // p = + infinity
+ BOOST_CHECK_THROW(quantile(complement(dist, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // p = + infinity
+ }
 
- //location/scale can't be infinity
- if(std::numeric_limits<RealType>::has_infinity) {
- BOOST_CHECK_THROW(
- logistic_distribution<RealType> dist(std::numeric_limits<RealType>::infinity(),0.5),
- std::domain_error);
- BOOST_CHECK_THROW(
- logistic_distribution<RealType> dist(0.5,std::numeric_limits<RealType>::infinity()),
- std::domain_error);
- }
- //scale can't be negative or 0
- BOOST_CHECK_THROW(
- logistic_distribution<RealType> dist(0.5,-0.5),
- std::domain_error);
- BOOST_CHECK_THROW(
- logistic_distribution<RealType> dist(0.5,0),
- std::domain_error);
-
- logistic_distribution<RealType> dist(0.5,0.5);
- //x can't be NaN,p can't be NaN
-
- if (std::numeric_limits<RealType>::has_quiet_NaN)
- {
- // No longer allow x to be NaN, then these tests should throw.
- BOOST_CHECK_THROW(pdf(dist, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
- BOOST_CHECK_THROW(cdf(dist, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
- BOOST_CHECK_THROW(cdf(complement(dist, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // x = + infinity
- BOOST_CHECK_THROW(quantile(dist, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // p = + infinity
- BOOST_CHECK_THROW(quantile(complement(dist, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // p = + infinity
- }
-
- //p can't be outside (0,1)
- BOOST_CHECK_THROW(quantile(dist, static_cast<RealType>(1.1)), std::domain_error);
- BOOST_CHECK_THROW(quantile(dist, static_cast<RealType>(-0.1)), std::domain_error);
- BOOST_CHECK_THROW(quantile(dist, static_cast<RealType>(1)), std::overflow_error);
- BOOST_CHECK_THROW(quantile(dist, static_cast<RealType>(0)), std::underflow_error);
-
- BOOST_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(1.1))), std::domain_error);
- BOOST_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(-0.1))), std::domain_error);
- BOOST_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(1))), std::underflow_error);
- BOOST_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(0))), std::overflow_error);
-
-
- //Tests for mean,mode,median,variance,skewness,kurtosis
-
-
- //mean
- BOOST_CHECK_CLOSE(
- ::boost::math::mean(
- logistic_distribution<RealType>(2,1)
- ),//x
- static_cast<RealType>(2), // probability
- tolerance); // %
- //median
- BOOST_CHECK_CLOSE(
- ::boost::math::median(
- logistic_distribution<RealType>(2,1)
- ),//x
- static_cast<RealType>(2), // probability
- tolerance);
- //mode
- BOOST_CHECK_CLOSE(
- ::boost::math::mode(
- logistic_distribution<RealType>(2,1)
- ),//x
- static_cast<RealType>(2), // probability
- tolerance);
- //variance
- BOOST_CHECK_CLOSE(
- ::boost::math::variance(
- logistic_distribution<RealType>(2,1)
- ),//x
- static_cast<RealType>(3.28986813369645287294483033329205L), // probability
- tolerance);
- //skewness
- BOOST_CHECK_CLOSE(
- ::boost::math::skewness(
- logistic_distribution<RealType>(2,1)
- ),//x
- static_cast<RealType>(0), // probability
- tolerance);
- BOOST_CHECK_CLOSE(
- ::boost::math::kurtosis_excess(
- logistic_distribution<RealType>(2,1)
- ),//x
- static_cast<RealType>(1.2L), // probability
- tolerance);
+ //p can't be outside (0,1)
+ BOOST_CHECK_THROW(quantile(dist, static_cast<RealType>(1.1)), std::domain_error);
+ BOOST_CHECK_THROW(quantile(dist, static_cast<RealType>(-0.1)), std::domain_error);
+ BOOST_CHECK_THROW(quantile(dist, static_cast<RealType>(1)), std::overflow_error);
+ BOOST_CHECK_THROW(quantile(dist, static_cast<RealType>(0)), std::overflow_error);
+
+ BOOST_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(1.1))), std::domain_error);
+ BOOST_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(-0.1))), std::domain_error);
+ BOOST_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(1))), std::overflow_error);
+ BOOST_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(0))), std::overflow_error);
 
+ //Tests for mean,mode,median,variance,skewness,kurtosis
+ //mean
+ BOOST_CHECK_CLOSE(
+ ::boost::math::mean(
+ logistic_distribution<RealType>(2,1)
+ ),//x
+ static_cast<RealType>(2), // probability
+ tolerance); // %
+ //median
+ BOOST_CHECK_CLOSE(
+ ::boost::math::median(
+ logistic_distribution<RealType>(2,1)
+ ),//x
+ static_cast<RealType>(2), // probability
+ tolerance);
+ //mode
+ BOOST_CHECK_CLOSE(
+ ::boost::math::mode(
+ logistic_distribution<RealType>(2,1)
+ ),//x
+ static_cast<RealType>(2), // probability
+ tolerance);
+ //variance
+ BOOST_CHECK_CLOSE(
+ ::boost::math::variance(
+ logistic_distribution<RealType>(2,1)
+ ),//x
+ static_cast<RealType>(3.28986813369645287294483033329205L), // probability
+ tolerance);
+ //skewness
+ BOOST_CHECK_CLOSE(
+ ::boost::math::skewness(
+ logistic_distribution<RealType>(2,1)
+ ),//x
+ static_cast<RealType>(0), // probability
+ tolerance);
+ BOOST_CHECK_CLOSE(
+ ::boost::math::kurtosis_excess(
+ logistic_distribution<RealType>(2,1)
+ ),//x
+ static_cast<RealType>(1.2L), // probability
+ tolerance);
 
-
 } // 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