From 8e24be2ffec845b350675fd5cd56eb0650efc71f Mon Sep 17 00:00:00 2001 From: Andrew Sutton Date: Mon, 14 Jan 2008 13:36:23 +0000 Subject: [PATCH] Added stubs for new distributions. These are neither fully tested nor documented and, in some cases, incomplete. However, migrating them into the sandbox will hopefully help motivate their completion. [SVN r42760] --- .../boost/math/distributions/geometric.hpp | 138 +++++++++++++++ .../boost/math/distributions/skew_normal.hpp | 163 ++++++++++++++++++ 2 files changed, 301 insertions(+) create mode 100644 include/boost/math/distributions/geometric.hpp create mode 100644 include/boost/math/distributions/skew_normal.hpp diff --git a/include/boost/math/distributions/geometric.hpp b/include/boost/math/distributions/geometric.hpp new file mode 100644 index 000000000..0205ad147 --- /dev/null +++ b/include/boost/math/distributions/geometric.hpp @@ -0,0 +1,138 @@ +// Copyright Andrew Sutton 2007 +// +// 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) + +#ifndef BOOST_MATH_GEOMETRIC_DISTRIBUTION_HPP +#define BOOST_MATH_GEOMETRIC_DISTRIBUTION_HPP + +#include +#include +#include +#include + +namespace boost { namespace math { + + // The geometric distribution... Write docs here... + template > + class geometric_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + geometric_distribution(value_type prob) + : m_prob(prob) + + { + } + + value_type success_probability() const + { return m_prob; } + + private: + value_type m_prob; + }; + + template + inline std::pair + range(const geometric_distribution&) + { + return std::make_pair(RealType(), RealType()); + } + + template + inline std::pair + support(const geometric_distribution&) + { + return std::make_pair(RealType(), RealType()); + } + + template + inline RealType + pdf(const geometric_distribution& dist, const RealType& x) + { + using std::pow; + RealType one = 1; + RealType p = dist.success_probability(); + return pow(one - p, x - one) * p; + } + + template + inline RealType + cdf(const geometric_distribution& dist, const RealType& x) + { + using std::pow; + RealType one = 1; + RealType p = dist.success_probability(); + return one - pow(one - p, x); + } + + template + inline RealType + cdf(const complemented2_type, RealType>& dist) + { + return RealType(); + } + + template + inline RealType + quantile(const geometric_distribution& dist, const RealType& x) + { + return RealType(); + } + + template + inline RealType + quantile(const complemented2_type, RealType>& dist) + { + return RealType(); + } + + template + inline RealType + mean(const geometric_distribution& dist) + { + RealType one = 1; + RealType p = dist.success_probability(); + return one / p; + } + + template + inline RealType + variance(const geometric_distribution& dist) + { + RealType one = 1; + RealType p = dist.success_probability(); + return (one - p) / (p * p); + } + + template + inline RealType + skewness(const geometric_distribution& dist) + { + using std::sqrt; + RealType one = 1; + RealType two = 2; + RealType p = dist.success_probability(); + return (two - p) / sqrt(one - p); + } + + template + inline RealType + kurtosis(const geometric_distribution& dist) + { + return RealType(); + } + + template + inline RealType + kurtosis_excess(const geometric_distribution& dist) + { + return RealType(); + } + +} } + +#endif diff --git a/include/boost/math/distributions/skew_normal.hpp b/include/boost/math/distributions/skew_normal.hpp new file mode 100644 index 000000000..80c16dbd5 --- /dev/null +++ b/include/boost/math/distributions/skew_normal.hpp @@ -0,0 +1,163 @@ +// Copyright Edward M. Morrison 2007 +// Copyright Andrew Sutton 2007 +// +// 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) + +#ifndef BOOST_MATH_SKEW_NORMAL_DISTRIBUTION_HPP +#define BOOST_MATH_SKEW_NORMAL_DISTRIBUTION_HPP + +#include +#include +#include +#include + +namespace boost { namespace math { + +namespace skew_normal_detail { + // delta() := a / sqrt(1 + a^2) + // expectation() := d * sqrt(2/pi) + // variance() := 1 - 2*d^2 / pi +} + + +// The skew normal distribution is parameterized over location, shape and +// scale parameters. These are similar to mean and standard deviation in the +// normal distribution, but are scaled and "re-shaped". +// +// Note that we could forseeably cache a number of factors inside the distribution +// like we're doing with the correlation factor. However, these aren't really part +// of the public interface of the type. In fact, it may just be better to recompute +// them on the fly each time. Ask the math guys. +template > +class skew_normal_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + skew_normal_distribution(value_type loc = 0, value_type scale = 1, value_type shape = 0) + : m_location(loc) + , m_scale(scale) + , m_shape(shape) + , m_correlation(make_correlation(shape)) + { + } + + value_type location() const + { return m_location; } + + value_type scale() const + { return m_scale; } + + value_type shape() const + { return m_shape; } + + value_type correlation() const + { return m_correlation; } + +private: + value_type make_correlation(value_type shape) + { return shape / sqrt(1.0 + shape * shape); } + +private: + value_type m_location; + value_type m_scale; + value_type m_shape; + value_type m_correlation; +}; + +template +inline std::pair +range(const skew_normal_distribution&) +{ + return std::make_pair(RealType(), RealType()); +} + +template +inline std::pair +support(const skew_normal_distribution&) +{ + return std::make_pair(RealType(), RealType()); +} + +template +inline RealType +pdf(const skew_normal_distribution& dist, const RealType& x) +{ + return RealType(); +} + +template +inline RealType +cdf(const skew_normal_distribution& dist, const RealType& x) +{ + return RealType(); +} + +template +inline RealType +cdf(const complemented2_type, RealType>& dist) +{ + return RealType(); +} + +template +inline RealType +quantile(const skew_normal_distribution& dist, const RealType& x) +{ + return RealType(); +} + +template +inline RealType +quantile(const complemented2_type, RealType>& dist) +{ + return RealType(); +} + +template +inline RealType +mean(const skew_normal_distribution& dist) +{ + // This is the complicated way of writing dist.location() + RealType var = sqrt(dist.scale()); + RealType root = sqrt(2.0 / constants::pi()); + return dist.location() + var * root * dist.correlation(); +} + +template +inline RealType +variance(const skew_normal_distribution& dist) +{ + // This is apparently the same as dist.scale()^2. + RealType scale = dist.scale() * dist.scale(); + RealType corr = dist.correlation() * dist.correlation(); + return scale * (1.0 - 2.0 * corr / constants::pi()); +} + +template +inline RealType +skewness(const skew_normal_distribution& dist) +{ + return RealType(); +} + +template +inline RealType +kurtosis(const skew_normal_distribution& dist) +{ + return RealType(); +} + +template +inline RealType +kurtosis_excess(const skew_normal_distribution& dist) +{ + return RealType(); +} + +} } + +#endif