|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57587 - in sandbox/statistics/distribution_toolkit: boost/statistics/detail/distribution_toolkit/distributions/location_scale boost/statistics/detail/distribution_toolkit/distributions/wrapper boost/statistics/detail/distribution_toolkit/fwd_math boost/statistics/detail/distribution_toolkit/meta libs/statistics/detail/distribution_toolkit/doc libs/statistics/detail/distribution_toolkit/example libs/statistics/detail/distribution_toolkit/test
From: erwann.rogard_at_[hidden]
Date: 2009-11-11 19:35:10
Author: e_r
Date: 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
New Revision: 57587
URL: http://svn.boost.org/trac/boost/changeset/57587
Log:
m/a
Added:
sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/range.hpp (contents, props changed)
sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/support.hpp (contents, props changed)
sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/meta/result_of_support.hpp (contents, props changed)
Text files modified:
sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/location_scale/location_scale.hpp | 110 +++++++++++++++++----------------------
sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/wrapper/wrapper.hpp | 32 +++++-----
sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/include.hpp | 2
sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/doc/readme.txt | 9 +++
sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/example/distribution_function.cpp | 26 +++++++++
sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/test/functions.cpp | 1
6 files changed, 103 insertions(+), 77 deletions(-)
Modified: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/location_scale/location_scale.hpp
==============================================================================
--- sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/location_scale/location_scale.hpp (original)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/location_scale/location_scale.hpp 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
@@ -9,6 +9,7 @@
#ifndef BOOST_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_LOCATION_SCALE_LOCATION_SCALE_HPP_ER_2009
#define BOOST_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_LOCATION_SCALE_LOCATION_SCALE_HPP_ER_2009
#include <vector>
+#include <string>
#include <algorithm>
#include <iterator>
#include <boost/mpl/assert.hpp>
@@ -18,7 +19,10 @@
#include <boost/statistics/detail/distribution_common/meta/inherit_policy.hpp>
#include <boost/statistics/detail/distribution_toolkit/meta/is_scalar_distribution.hpp>
#include <boost/statistics/detail/distribution_common/meta/value.hpp>
-//#include <boost/math/policies/policy.hpp>
+#include <boost/statistics/detail/distribution_common/meta/policy.hpp>
+#include <boost/math/policies/policy.hpp> // probably not needed
+#include <boost/math/distributions/detail/common_error_handling.hpp>
+#include <boost/math/policies/error_handling.hpp>
namespace boost{
namespace statistics{
@@ -35,91 +39,75 @@
//
// TODO: range and support
template<typename Z>
- class location_scale_distribution
- : public distribution::common::meta::inherit_policy<Z>{
+ class location_scale_distribution{
+ typedef std::string str_;
+ static const str_ fun;
+
public:
typedef Z distribution_type;
- BOOST_MPL_ASSERT((
- meta::is_scalar_distribution<Z>
- ));
+ BOOST_MPL_ASSERT(( meta::is_scalar_distribution<Z> ));
typedef typename distribution::common::meta::value<
distribution_type
>::type value_type;
- location_scale_distribution();
+ typedef typename distribution::common::meta::policy<
+ distribution_type
+ >::type policy_type;
+
+ location_scale_distribution():mu_(0),sigma_(1),z_(){}
location_scale_distribution(
value_type mu,
value_type sigma,
const Z& z
- );
+ ):mu_(mu),sigma_(sigma),z_(z){
+ static const char* str
+ = (fun + "<%1%>::location_scale_distribution").c_str();
+
+ // TODO at present %1% is replaced by value_type. Write a function
+ // that is implemented in terms of check_scale but actually puts
+ // Z in its place
+
+ value_type result;
+ boost::math::detail::check_location(
+ str, mu, &result, policy_type());
+ boost::math::detail::check_scale(
+ str, sigma, &result, policy_type());
+ }
- location_scale_distribution(const location_scale_distribution& that);
+ location_scale_distribution(const location_scale_distribution& that)
+ :mu_(that.mu_),sigma_(that.sigma_),z_(that.z_){}
location_scale_distribution&
- operator=(const location_scale_distribution& that);
+ operator=(const location_scale_distribution& that){
+ if(&that!=this){
+ mu_ = that.mu_;
+ sigma_ = that.sigma_;
+ z_ = that.z_;
+ }
+ return *this;
+ }
- value_type mu()const;
- value_type sigma()const;
-
- const Z& z()const;
+ value_type mu()const{ return this->mu_; }
+ value_type sigma()const{ return this->sigma_; }
+ const Z& z()const{ return this->z_; }
private:
- value_type mu_;
- value_type sigma_;
- Z z_;
+ value_type mu_;
+ value_type sigma_;
+ Z z_;
};
-
- // Implementation //
-
template<typename Z>
- location_scale_distribution<Z>::location_scale_distribution()
- :mu_(0),sigma_(1),z_(){}
-
- template<typename Z>
- location_scale_distribution<Z>::location_scale_distribution(
- value_type mu,
- value_type sigma,
- const Z& z
- ):mu_(mu),sigma_(sigma),z_(z){}
+ const std::string location_scale_distribution<Z>::fun
+ = "distribution::toolkit::location_scale_distribution";
- template<typename Z>
- location_scale_distribution<Z>::location_scale_distribution(
- const location_scale_distribution& that
- ):mu_(that.mu_),sigma_(that.sigma_),z_(that.z_){}
- template<typename Z>
- location_scale_distribution<Z>&
- location_scale_distribution<Z>::operator=(
- const location_scale_distribution& that
- ){
- if(&that!=this){
- mu_ = that.mu_;
- sigma_ = that.sigma_;
- z_ = that.z_;
- }
- return *this;
- }
-
- template<typename Z>
- typename location_scale_distribution<Z>::value_type
- location_scale_distribution<Z>::mu()const{ return this->mu_; }
-
- template<typename Z>
- typename location_scale_distribution<Z>::value_type
- location_scale_distribution<Z>::sigma()const{ return this->sigma_; }
-
- template<typename Z>
- const Z&
- location_scale_distribution<Z>::z()const{ return this->z_; }
-
-
-}// distribution
}// toolkit
-
+}// distribution
}// detail
}// statistics
}// boost
+
#endif
Modified: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/wrapper/wrapper.hpp
==============================================================================
--- sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/wrapper/wrapper.hpp (original)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/wrapper/wrapper.hpp 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
@@ -14,8 +14,8 @@
#include <boost/mpl/not.hpp>
#include <boost/statistics/detail/distribution_common/meta/inherit_policy.hpp>
#include <boost/statistics/detail/distribution_common/meta/value.hpp>
-#include <boost/archive/text_oarchive.hpp>
-#include <boost/archive/text_iarchive.hpp>
+//#include <boost/archive/text_oarchive.hpp>
+//#include <boost/archive/text_iarchive.hpp>
namespace boost{
namespace statistics{
@@ -54,20 +54,20 @@
private:
- template<class A>
- void serialize(
- A & ar,
- const unsigned int version
- )
- {
- BOOST_MPL_ASSERT((
- mpl::not_<
- is_reference<D>
- >
- ));
-
- ar & d_;
- }
+ //template<class A>
+ //void serialize(
+ // A & ar,
+ // const unsigned int version
+ //)
+ //{
+ // BOOST_MPL_ASSERT((
+ // mpl::not_<
+ // is_reference<D>
+ // >
+ // ));
+ //
+ // ar & d_;
+ //}
typename call_traits<D>::value_type d_;
};
Modified: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/include.hpp
==============================================================================
--- sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/include.hpp (original)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/include.hpp 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
@@ -13,6 +13,8 @@
#include <boost/statistics/detail/distribution_toolkit/fwd_math/pdf.hpp>
#include <boost/statistics/detail/distribution_toolkit/fwd_math/quantile.hpp>
#include <boost/statistics/detail/distribution_toolkit/fwd_math/mean.hpp>
+#include <boost/statistics/detail/distribution_toolkit/fwd_math/range.hpp>
+#include <boost/statistics/detail/distribution_toolkit/fwd_math/support.hpp>
#include <boost/statistics/detail/distribution_toolkit/fwd_math/variance.hpp>
#endif
\ No newline at end of file
Added: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/range.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/range.hpp 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////////
+// distribution::toolkit::fwd_math::range.hpp //
+// //
+// (C) Copyright 2009 Erwann Rogard //
+// 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_DISTRIBUTION_TOOLKIT_FWD_MATH_RANGE_HPP_ER_2009
+#define BOOST_DISTRIBUTION_TOOLKIT_FWD_MATH_RANGE_HPP_ER_2009
+#include <boost/utility/enable_if.hpp>
+#include <boost/statistics/detail/distribution_toolkit/meta/is_math_distribution.hpp>
+#include <boost/statistics/detail/distribution_common/meta/result_of_support.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+
+template<typename D>
+typename lazy_enable_if<
+ distribution::toolkit::meta::is_math_distribution<D>,
+ distribution::toolkit::meta::result_of_support<D>
+>
+range(const D& dist)
+{
+ return boost::math::range(dist);
+}
+
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/support.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/fwd_math/support.hpp 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////////
+// distribution::toolkit::fwd_math::support.hpp //
+// //
+// (C) Copyright 2009 Erwann Rogard //
+// 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_DISTRIBUTION_TOOLKIT_FWD_MATH_SUPPORT_HPP_ER_2009
+#define BOOST_DISTRIBUTION_TOOLKIT_FWD_MATH_SUPPORT_HPP_ER_2009
+#include <boost/utility/enable_if.hpp>
+#include <boost/statistics/detail/distribution_toolkit/meta/is_math_distribution.hpp>
+#include <boost/statistics/detail/distribution_common/meta/result_of_support.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+
+template<typename D>
+typename lazy_enable_if<
+ distribution::toolkit::meta::is_math_distribution<D>,
+ distribution::toolkit::meta::result_of_support<D>
+>
+support(const D& dist)
+{
+ return boost::math::support(dist);
+}
+
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/meta/result_of_support.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/meta/result_of_support.hpp 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
@@ -0,0 +1,35 @@
+//////////////////////////////////////////////////////////////////////////////////
+// distribution::toolkit::meta::result_of_support.hpp //
+// //
+// (C) Copyright 2009 Erwann Rogard //
+// 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_DISTRIBUTION_TOOLKIT_META_RESULT_OF_SUPPORT_HPP_ER_2009
+#define BOOST_DISTRIBUTION_TOOLKIT_META_RESULT_OF_SUPPORT_HPP_ER_2009
+#include <utility>
+#include <boost/statistics/detail/distribution_common/meta/value.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace distribution{
+namespace common{
+namespace meta{
+
+ template<typename D>
+ struct result_of_support
+ {
+ typedef typename distribution::common::meta::value<D>::type val_;
+ typedef std::pair<val_,val_> type;
+ }
+
+}// meta
+}// toolkit
+}// distribution
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Modified: sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/doc/readme.txt
==============================================================================
--- sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/doc/readme.txt (original)
+++ sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/doc/readme.txt 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
@@ -63,6 +63,9 @@
Decouples the function, such as pdf, from the distribution D:
fun_wrap::cdf_<D>::instance
+ Note : distribution_common has functors (in the making) that achieve the
+ same goal that are easier to use
+
/fwd_math
/iterator
/map_pdf
@@ -88,6 +91,8 @@
[ History ]
+Nov 6 2009 : Added error-handling policy to location_scale
+
Oct 11 2009 :
removed /data. use instead sandbox/non_parametric/statistic
added /test
@@ -107,3 +112,7 @@
Sep 16 2009 : deleted /algorithm and added /iterator
July 2009 : First version
+[ TODO ]
+
+- range and support for location_scale
+- other distributions
\ No newline at end of file
Modified: sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/example/distribution_function.cpp
==============================================================================
--- sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/example/distribution_function.cpp (original)
+++ sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/example/distribution_function.cpp 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
@@ -12,6 +12,9 @@
#include <numeric>
#include <cmath>
#include <string>
+#include <stdexcept>
+#include <limits>
+
#include <boost/mpl/apply.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
@@ -22,6 +25,8 @@
#include <boost/random/normal_distribution.hpp>
#include <boost/random/variate_generator.hpp>
+#include <boost/statistics/detail/distribution_common/functor/log_unnormalized_pdf.hpp>
+
#include <boost/statistics/detail/distribution_toolkit/meta/include.hpp>
#include <boost/statistics/detail/distribution_toolkit/distributions/students_t/include.hpp>
#include <boost/statistics/detail/distribution_toolkit/distributions/location_scale/include.hpp>
@@ -43,6 +48,7 @@
using namespace math;
using namespace statistics::detail;
namespace st = statistics::detail;
+ namespace co = distribution::common;
namespace tk = distribution::toolkit;
namespace tk_it = tk::iterator;
@@ -53,6 +59,7 @@
typedef math::students_t_distribution<val_> stud_;
typedef tk::location_scale_distribution<stud_> ls_stud_;
typedef boost::variate_generator<urng_&,rnd_> vg_;
+ typedef boost::numeric::bounds<val_> bounds_;
// Constants
const unsigned df = 10;
@@ -67,6 +74,21 @@
stud_ stud(df);
ls_stud_ ls_stud(mu, sigma, stud);
+ out << "testing error handling : " << std::endl;
+
+ try{
+ static const val_ inf = std::numeric_limits<val_>::infinity();
+ ls_stud_ ls_stud(inf,sigma,stud);
+ }catch(std::exception& e){
+ out << e.what() << std::endl;
+ }
+
+ try{
+ ls_stud_(mu,-1.0,stud);
+ }catch(std::exception& e){
+ out << e.what() << std::endl;
+ }
+
struct float_{
static bool equal(const val_& a, const val_& b){
@@ -90,6 +112,10 @@
)
);
}
+ { // Create a delegate for log_unnormalized_pdf
+ typedef co::functor::log_unnormalized_pdf<ls_stud_> ftor_;
+ ftor_ ftor(ls_stud);
+ }
{ // make_distribution_function_iterator + fun_wrap
// Arbitrary random sample
typedef std::vector<val_> vals_;
Modified: sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/test/functions.cpp
==============================================================================
--- sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/test/functions.cpp (original)
+++ sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/test/functions.cpp 2009-11-11 19:35:08 EST (Wed, 11 Nov 2009)
@@ -9,6 +9,7 @@
#ifndef LIBS_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_TEST_FUNCTIONS_H_ER_2009
#define LIBS_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_TEST_FUNCTIONS_H_ER_2009
#include <ostream>
+
#include <boost/concept/assert.hpp>
#include <boost/statistics/detail/distribution_toolkit/distributions/chi_squared/include.hpp>
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