Boost logo

Boost-Commit :

From: gautamcool88_at_[hidden]
Date: 2008-08-05 12:18:30


Author: s.gautam
Date: 2008-08-05 12:18:29 EDT (Tue, 05 Aug 2008)
New Revision: 47992
URL: http://svn.boost.org/trac/boost/changeset/47992

Log:
removed bug in variance. Added Copyright and License information. Used spaces instead of tabs to adhere to the Boost guidelines.
Text files modified:
   sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp | 152 +++++++++++++++++++++++----------------
   1 files changed, 91 insertions(+), 61 deletions(-)

Modified: sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp
==============================================================================
--- sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp (original)
+++ sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp 2008-08-05 12:18:29 EDT (Tue, 05 Aug 2008)
@@ -1,4 +1,17 @@
 
+// Copyright John Maddock
+// Copyright Paul A. Bristow
+// Copyright 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)
+
+
+
+
+
 
 
 
@@ -21,23 +34,23 @@
       typedef Policy policy_type;
       
       logistic_distribution(RealType location=0, RealType scale=1) // Constructor.
- : m_location(location), m_scale(scale)
+ : m_location(location), m_scale(scale)
       {
- static const char* function = "boost::math::logistic_distribution<%1%>::logistic_distribution";
-
- RealType result;
- detail::check_scale(function, scale, &result, Policy());
- detail::check_location(function, location, &result, Policy());
+ static const char* function = "boost::math::logistic_distribution<%1%>::logistic_distribution";
+
+ RealType result;
+ detail::check_scale(function, scale, &result, Policy());
+ detail::check_location(function, location, &result, Policy());
       }
       // Accessor functions.
       RealType scale()const
       {
- return m_scale;
+ return m_scale;
       }
       
       RealType location()const
       {
- return m_location;
+ return m_location;
       }
     private:
       // Data members:
@@ -72,24 +85,24 @@
       
       static const char* function = "boost::math::pdf(const logistic_distribution<%1%>&, %1%)";
       if((boost::math::isinf)(x))
- {
- return 0; // pdf + and - infinity is zero.
- }
+ {
+ return 0; // pdf + and - infinity is zero.
+ }
       
       
       RealType result;
       if(false == detail::check_scale(function, scale , &result, Policy()))
- {
- return result;
- }
+ {
+ return result;
+ }
       if(false == detail::check_location(function, location, &result, Policy()))
- {
- return result;
- }
+ {
+ return result;
+ }
       if(false == detail::check_x(function, x, &result, Policy()))
- {
- return result;
- }
+ {
+ return result;
+ }
       
       
       RealType exp_term=exp((location-x)/scale);
@@ -106,25 +119,25 @@
       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;
- }
+ {
+ return result;
+ }
       
       if(false == detail::check_location(function, location, &result, Policy()))
- {
- return result;
- }
+ {
+ return result;
+ }
       
       if((boost::math::isinf)(x))
- {
- if(x < 0) return 0; // -infinity
- return 1; // + infinity
- }
+ {
+ if(x < 0) return 0; // -infinity
+ return 1; // + infinity
+ }
       
       if(false == detail::check_x(function, x, &result, Policy()))
- {
- return result;
- }
+ {
+ return result;
+ }
       
       RealType power=(location-x)/scale;
       return 1/( 1+exp(power) );
@@ -140,23 +153,32 @@
       
       RealType result;
       if(false == detail::check_scale(function, scale, &result, Policy()))
- return result;
+ return result;
       if(false == detail::check_location(function, location, &result, Policy()))
- return result;
+ return result;
       if(false == detail::check_probability(function, p, &result, Policy()))
- return result;
+ return result;
       
       using boost::math::tools::max_value;
       if(p == 0)
- {
- return -max_value<RealType>();
- }
+ {
+ return -max_value<RealType>();
+ }
       if(p == 1)
- {
- return max_value<RealType>();
- }
- return scale*log1p((2*p-1)/(1-p)) + location;
- } // RealType quantile(const logistic_distribution<RealType, Policy>& dist, const RealType& p)
+ {
+ return max_value<RealType>();
+ }
+ //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*log1p((1-2*p)/p);
+
+ //return -scale*log(1/p-1) + location;
+ return -scale*log1p(1/p-2)+location;
+
+ } // 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)
@@ -167,17 +189,17 @@
       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
- }
+ {
+ 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;
+ return result;
       if(false == detail::check_location(function, location, &result, Policy()))
- return result;
+ return result;
       if(false == detail::check_x(function, x, &result, Policy()))
- return result;
+ return result;
       
       RealType power=(x-location)/scale;
       return 1/( 1+exp(power) );
@@ -201,15 +223,23 @@
 
 
       if(q == 0)
- {
- return max_value<RealType>();
- }
+ {
+ return max_value<RealType>();
+ }
       if(q == 1)
- {
- return -max_value<RealType>();
- }
-
- return location+scale*log1p((1-2*q)/(q));
+ {
+ return -max_value<RealType>();
+ }
+ //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>
@@ -222,8 +252,8 @@
     inline RealType variance(const logistic_distribution<RealType, Policy>& dist)
     {
       BOOST_MATH_STD_USING
- RealType location = dist.location();
- return boost::math::constants::pi<RealType>()*boost::math::constants::pi<RealType>()*location*location/3;
+ 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)
     


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