|
Boost-Commit : |
From: gautamcool88_at_[hidden]
Date: 2008-07-09 08:16:20
Author: s.gautam
Date: 2008-07-09 08:16:20 EDT (Wed, 09 Jul 2008)
New Revision: 47262
URL: http://svn.boost.org/trac/boost/changeset/47262
Log:
Added Logistic distribution
Added:
sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp (contents, props changed)
Added: sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2008/parrallel_math/boost/math/distributions/gsoc_logistic.hpp 2008-07-09 08:16:20 EDT (Wed, 09 Jul 2008)
@@ -0,0 +1,256 @@
+
+
+
+
+
+#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 <boost/math/special_functions/expm1.hpp>
+
+#include <boost/math/constants/constants.hpp>
+#include <utility>
+
+namespace boost { namespace math {
+ template <class RealType = double, class Policy = policies::policy<> >
+ class logistic_distribution
+ {
+ public:
+ typedef RealType value_type;
+ typedef Policy policy_type;
+
+ logistic_distribution(RealType location=0, RealType scale=1) // Constructor.
+ : 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());
+ }
+ // Accessor functions.
+ RealType scale()const
+ {
+ return m_scale;
+ }
+
+ RealType location()const
+ {
+ return m_location;
+ }
+ private:
+ // Data members:
+ RealType m_location; // distribution location aka mu.
+ RealType m_scale; // distribution scale aka s.
+ }; // class logistic_distribution
+
+
+ typedef logistic_distribution<double> logistic;
+
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> range(const logistic_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>()); // - to + infinity
+ }
+
+ template <class RealType, class Policy>
+ inline const std::pair<RealType, RealType> support(const logistic_distribution<RealType, Policy>& dist)
+ { // Range of supported values for random variable x.
+ // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
+ using boost::math::tools::max_value;
+ return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity
+ }
+
+
+ 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))
+ {
+ 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()))
+ {
+ return result;
+ }
+
+
+ RealType power=(location-x)/scale;
+ return ( 1+expm1(power) )/ ( scale*(2+expm1(power))*(2+expm1(power) ) );
+
+
+ }
+
+ 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()))
+ {
+ return result;
+ }
+
+ if(false == detail::check_location(function, location, &result, Policy()))
+ {
+ return result;
+ }
+
+ if((boost::math::isinf)(x))
+ {
+ if(x < 0) return 0; // -infinity
+ return 1; // + infinity
+ }
+
+ if(false == detail::check_x(function, x, &result, Policy()))
+ {
+ return result;
+ }
+
+ RealType power=(location-x)/scale;
+ return 1/( 2+expm1(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;
+
+ using boost::math::tools::max_value;
+ if(p == 0)
+ {
+ 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)
+
+ 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))
+ {
+ 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;
+
+ RealType power=(x-location)/scale;
+ return 1/( 2+expm1(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 == 0)
+ {
+ return max_value<RealType>();
+ }
+ if(q == 1)
+ {
+ return -max_value<RealType>();
+ }
+
+ return location+scale*log1p((1-2*q)/(q));
+ }
+
+ template <class RealType, class Policy>
+ inline RealType mean(const logistic_distribution<RealType, Policy>& dist)
+ {
+ return dist.location();
+ } // RealType mean(const logistic_distribution<RealType, Policy>& dist)
+
+ template <class RealType, class Policy>
+ 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 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)
+ {
+
+ 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)
+ {
+
+ return static_cast<RealType>(6)/5;
+ } // RealType kurtosis_excess(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