Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59181 - in sandbox/statistics/distribution_toolkit: boost/statistics/detail/distribution_toolkit/distributions/chi_squared boost/statistics/detail/distribution_toolkit/distributions/poisson libs/statistics/detail/distribution_toolkit/example
From: erwann.rogard_at_[hidden]
Date: 2010-01-20 19:47:09


Author: e_r
Date: 2010-01-20 19:47:08 EST (Wed, 20 Jan 2010)
New Revision: 59181
URL: http://svn.boost.org/trac/boost/changeset/59181

Log:
adding poisson
Added:
   sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/
   sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/description.hpp (contents, props changed)
   sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/include.hpp (contents, props changed)
   sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/os.hpp (contents, props changed)
   sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/random.hpp (contents, props changed)
Text files modified:
   sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/chi_squared/random.hpp | 2
   sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/example/distribution_function.cpp | 2
   sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/example/random.cpp | 138 ++++++++++++++++++++-------------------
   3 files changed, 73 insertions(+), 69 deletions(-)

Modified: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/chi_squared/random.hpp
==============================================================================
--- sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/chi_squared/random.hpp (original)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/chi_squared/random.hpp 2010-01-20 19:47:08 EST (Wed, 20 Jan 2010)
@@ -22,7 +22,7 @@
     struct random_distribution<
         boost::math::chi_squared_distribution<T,P>
>{
- typedef boost::math::chi_squared_distribution<T> dist_;
+ typedef boost::math::chi_squared_distribution<T,P> dist_;
         typedef boost::random::chi_squared_distribution<T> type;
         
         static type call(const dist_& d){

Added: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/description.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/description.hpp 2010-01-20 19:47:08 EST (Wed, 20 Jan 2010)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////////////
+// distribution::toolkit::distributions::poisson::description.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_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_POISSON_DESCRIPTION_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_POISSON_DESCRIPTION_HPP_ER_2009
+#include <ostream>
+#include <boost/format.hpp>
+#include <boost/math/distributions/poisson.hpp>
+
+namespace boost{
+namespace math{
+
+ template<typename T,typename P>
+ std::string
+ description(const boost::math::poisson_distribution<T,P>& dist)
+ {
+ static const char* msg = "poisson(%1%)";
+ format f(msg); f % dist.mean();
+ return f.str();
+ }
+
+}// math
+}// boost
+
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/include.hpp 2010-01-20 19:47:08 EST (Wed, 20 Jan 2010)
@@ -0,0 +1,21 @@
+//////////////////////////////////////////////////////////////////////////////////
+// distribution::toolkit::distributions::distributions::poisson::include.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_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_POISSON_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_POISSON_INCLUDE_HPP_ER_2009
+
+#include <boost/math/distributions/poisson.hpp>
+
+#include <boost/statistics/detail/distribution_toolkit/distributions/poisson/description.hpp>
+//#include <boost/statistics/detail/distribution_toolkit/distributions/poisson/derivative_log_unnormalized_pdf.hpp>
+//#include <boost/statistics/detail/distribution_toolkit/distributions/poisson/is_math_distribution.hpp>
+//#include <boost/statistics/detail/distribution_toolkit/distributions/poisson/log_unnormalized_pdf.hpp>
+#include <boost/statistics/detail/distribution_toolkit/distributions/poisson/random.hpp>
+#include <boost/statistics/detail/distribution_toolkit/distributions/poisson/os.hpp>
+
+#endif

Added: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/os.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/os.hpp 2010-01-20 19:47:08 EST (Wed, 20 Jan 2010)
@@ -0,0 +1,29 @@
+/////////////////////////////////////////////////////////////////////////////////
+// distribution::toolkit::distributions::poisson::os.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_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_POISSON_OS_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_POISSON_OS_HPP_ER_2009
+#include <boost/statistics/detail/distribution_toolkit/distributions/poisson/description.hpp>
+
+namespace boost{
+namespace math{
+
+ template<typename T,typename P>
+ std::ostream&
+ operator<<(
+ std::ostream& os,
+ const boost::math::poisson_distribution<T,P>& dist
+ )
+ {
+ return (os << description(dist));
+ }
+
+}// math
+}// boost
+
+#endif

Added: sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/random.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/distribution_toolkit/boost/statistics/detail/distribution_toolkit/distributions/poisson/random.hpp 2010-01-20 19:47:08 EST (Wed, 20 Jan 2010)
@@ -0,0 +1,39 @@
+/////////////////////////////////////////////////////////////////////////////////
+// distribution::toolkit::distributions::poisson::random.hpp //
+// //
+// (C) Copyright 2010 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_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_POISSON_RANDOM_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_DISTRIBUTION_TOOLKIT_POISSON_RANDOM_HPP_ER_2010
+#include <boost/math/distributions/poisson.hpp>
+#include <boost/random/poisson_distribution.hpp>
+#include <boost/statistics/detail/distribution_common/meta/random/distribution.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace distribution{
+namespace meta{
+
+ template<typename T,typename P>
+ struct random_distribution<
+ boost::math::poisson_distribution<T,P>
+ >{
+ typedef boost::math::poisson_distribution<T,P> dist_;
+ typedef boost::poisson_distribution<int,T> type;
+
+ static type call(const dist_& d){
+ return type(d.mean());
+ }
+ };
+
+}// meta
+}// distribution
+}// detail
+}// statistics
+}// boost
+
+#endif
\ 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 2010-01-20 19:47:08 EST (Wed, 20 Jan 2010)
@@ -26,11 +26,11 @@
 #include <boost/random/variate_generator.hpp>
 
 #include <boost/statistics/detail/distribution_common/functor/log_unnormalized_pdf.hpp>
+#include <boost/statistics/detail/distribution_common/distributions/reference/wrapper.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>
-#include <boost/statistics/detail/distribution_toolkit/distributions/wrapper/include.hpp>
 #include <boost/statistics/detail/distribution_toolkit/map_pdf/include.hpp>
 
 #include <libs/statistics/detail/distribution_toolkit/example/distribution_function.h>

Modified: sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/example/random.cpp
==============================================================================
--- sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/example/random.cpp (original)
+++ sandbox/statistics/distribution_toolkit/libs/statistics/detail/distribution_toolkit/example/random.cpp 2010-01-20 19:47:08 EST (Wed, 20 Jan 2010)
@@ -6,112 +6,119 @@
 // 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/typeof/typeof.hpp>
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/statistics/detail/distribution_toolkit/distributions/chi_squared/include.hpp>
 #include <boost/statistics/detail/distribution_toolkit/distributions/exponential/include.hpp>
 #include <boost/statistics/detail/distribution_toolkit/distributions/gamma/include.hpp>
 #include <boost/statistics/detail/distribution_toolkit/distributions/normal/include.hpp>
+#include <boost/statistics/detail/distribution_toolkit/distributions/poisson/include.hpp>
 #include <boost/statistics/detail/distribution_toolkit/distributions/students_t/include.hpp>
 #include <boost/statistics/detail/distribution_toolkit/distributions/location_scale/include.hpp>
 #include <boost/statistics/detail/distribution_common/distributions/reference/include.hpp>
-#include <boost/statistics/detail/distribution_toolkit/test/random.hpp>
+#include <boost/statistics/detail/distribution_common/meta/random/generator.hpp>
+#include <boost/statistics/detail/non_parametric/kolmogorov_smirnov/check_convergence.hpp>
+
 #include <libs/statistics/detail/distribution_toolkit/example/random.h>
 
 void example_random(std::ostream& os)
 {
- // For each distribution, dist, and the corresponding random2 engine returned
- // by make_random2(dist), this example outputs a series of kolmogorov-
- // smirnov statistics. Convergence to zero is evidence that
- // the sample agrees wit the cdf of dist
+ // Checks convergence of sample generated by make_random_generator(urng,d)
+ // to distribution b, by the kolmogorov-smirnov
 
     os << "-> test_random2 " << std::endl;
 
+ namespace ks = boost::statistics::detail::kolmogorov_smirnov;
+
     using namespace boost;
     using namespace boost::statistics;
     namespace stat = statistics::detail;
         namespace dist = stat::distribution;
- namespace test = dist::toolkit::test;
+ typedef int int_;
+ typedef double val_;
         typedef boost::mt19937 urng_;
+ typedef ks::check_convergence<val_> check_;
 
     const unsigned n_loops = 6;
     const unsigned n1 = 1e1;
     const unsigned n2 = 1e1;
-
- // Types
- typedef double val_;
-
+
     urng_ urng;
+ check_ check;
     
     {
         typedef math::chi_squared_distribution<val_> dist_;
         const val_ df = 10;
- dist_ dist( df );
- test::random2(
- dist,
- urng,
- n_loops,
- n1,
- n2,
- os
+ dist_ d( df );
+ os << d << std::endl;
+ BOOST_AUTO(
+ vg,
+ dist::make_random_generator(urng,d)
         );
+ check(n_loops,n1,n2,d,vg,os);
     }
     {
         typedef math::exponential_distribution<val_> dist_;
         const val_ lambda = 1.0;
- dist_ dist( lambda );
- test::random2(
- dist,
- urng,
- n_loops,
- n1,
- n2,
- os
+ dist_ d( lambda );
+ os << d << std::endl;
+ BOOST_AUTO(
+ vg,
+ dist::make_random_generator(urng,d)
         );
-
+ check(n_loops,n1,n2,d,vg,os);
     }
     {
         typedef math::gamma_distribution<val_> dist_;
         const val_ shape = 2.0;
         const val_ scale = 3.0;
- dist_ dist( shape, scale );
+ dist_ d( shape, scale );
+ os << d << std::endl;
             
- test::random2(
- dist,
- urng,
- n_loops,
- n1,
- n2,
- os
+ BOOST_AUTO(
+ vg,
+ dist::make_random_generator(urng,d)
         );
+ check(n_loops,n1,n2,d,vg,os);
     }
     {
         typedef math::normal_distribution<val_> dist_;
         const val_ m = 1.0;
         const val_ s = 2.0;
- dist_ dist( m, s );
+ dist_ d( m, s );
+ os << d << std::endl;
             
- test::random2(
- dist,
- urng,
- n_loops,
- n1,
- n2,
- os
+ BOOST_AUTO(
+ vg,
+ dist::make_random_generator(urng,d)
         );
+ check(n_loops,n1,n2,d,vg,os);
+
+ }
+ {
+ typedef boost::math::poisson_distribution<val_> dist_;
+ const val_ m = 10.0;
+ dist_ d( m );
+ os << d << std::endl;
+
+ BOOST_AUTO(
+ vg,
+ dist::make_random_generator(urng,d)
+ );
+ check(n_loops,n1,n2,d,vg,os);
 
     }
     {
         typedef math::students_t_distribution<val_> dist_;
         const val_ df = 4.0;
- dist_ dist( df );
- test::random2(
- dist,
- urng,
- n_loops,
- n1,
- n2,
- os
+ dist_ d( df );
+ os << d << std::endl;
+
+ BOOST_AUTO(
+ vg,
+ dist::make_random_generator(urng,d)
         );
+ check(n_loops,n1,n2,d,vg,os);
     }
     {
         typedef math::students_t_distribution<val_> dist_z_;
@@ -120,31 +127,28 @@
         const val_ m = 1.0;
         const val_ s = 2.0;
         dist_z_ dist_z( df );
- dist_ dist(m, s, dist_z);
- test::random2(
- dist,
- urng,
- n_loops,
- n1,
- n2,
- os
+ dist_ d(m, s, dist_z);
+ os << d << std::endl;
+
+ BOOST_AUTO(
+ vg,
+ dist::make_random_generator(urng,d)
         );
+ check(n_loops,n1,n2,d,vg,os);
     }
     {
         typedef math::students_t_distribution<val_> d0_;
         typedef dist::reference_wrapper<d0_> dist_;
         const val_ df = 4.0;
         d0_ d0( df );
- dist_ dist(d0);
+ dist_ d(d0);
+ os << d << std::endl;
             
- test::random2(
- dist,
- urng,
- n_loops,
- n1,
- n2,
- os
+ BOOST_AUTO(
+ vg,
+ dist::make_random_generator(urng,d)
         );
+ check(n_loops,n1,n2,d,vg,os);
     }
 
     os << "<-" << std::endl;


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