Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62310 - in sandbox/statistics/non_parametric: boost/statistics/detail/non_parametric/empirical_distribution boost/statistics/detail/non_parametric/kolmogorov_smirnov libs/statistics/detail/non_parametric/doc libs/statistics/detail/non_parametric/src
From: erwann.rogard_at_[hidden]
Date: 2010-05-30 11:11:05


Author: e_r
Date: 2010-05-30 11:11:04 EDT (Sun, 30 May 2010)
New Revision: 62310
URL: http://svn.boost.org/trac/boost/changeset/62310

Log:
m
Text files modified:
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/frequency.hpp | 26 +++-------
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/kolmogorov_smirnov/check_convergence.hpp | 7 +-
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/kolmogorov_smirnov/statistic.hpp | 94 ++++++++++++++++++++-------------------
   sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/doc/readme.txt | 33 ++-----------
   sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/src/main.cpp | 14 +++--
   5 files changed, 74 insertions(+), 100 deletions(-)

Modified: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/frequency.hpp
==============================================================================
--- sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/frequency.hpp (original)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/frequency.hpp 2010-05-30 11:11:04 EDT (Sun, 30 May 2010)
@@ -62,18 +62,6 @@
         template<typename Args>
         result_type result(const Args& args) const
         {
- typedef boost::accumulators::tag::accumulator tag_acc_;
- typedef boost::parameter::binding<Args,tag_acc_> bind_;
- typedef typename bind_::type cref_;
- typedef boost::accumulators::tag::count tag_n_;
- cref_ acc = args[boost::accumulators::accumulator];
- size_ i = boost::statistics::detail::empirical_distribution
- ::extract::count<Cum>(
- acc,
- args[boost::accumulators::sample]
- );
- size_ n = boost::accumulators::extract_result<tag_n_>( acc );
- return static_cast<T1>(i)/static_cast<T1>(n);
         }
     };
     
@@ -120,12 +108,14 @@
             ::result_of::template frequency<Cum,T1,AccSet>::type
     frequency(AccSet const& acc,const T& x)
     {
- typedef boost::statistics::detail::empirical_distribution
- ::tag::frequency<Cum,T1> the_tag;
- return boost::accumulators::extract_result<the_tag>(
- acc,
- (boost::accumulators::sample = x)
- );
+ typedef std::size_t size_;
+ typedef boost::accumulators::tag::count tag_n_;
+
+ namespace ns = boost::statistics::detail::empirical_distribution;
+
+ size_ i = ns::extract::count<Cum>( acc, x );
+ size_ n = boost::accumulators::extract_result<tag_n_>( acc );
+ return static_cast<T1>(i)/static_cast<T1>(n);
     }
 
 }

Modified: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/kolmogorov_smirnov/check_convergence.hpp
==============================================================================
--- sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/kolmogorov_smirnov/check_convergence.hpp (original)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/kolmogorov_smirnov/check_convergence.hpp 2010-05-30 11:11:04 EDT (Sun, 30 May 2010)
@@ -21,6 +21,7 @@
 #include <boost/accumulators/framework/accumulator_set.hpp>
 #include <boost/accumulators/statistics/stats.hpp>
 
+#include <boost/statistics/detail/non_parametric/empirical_distribution/ordered_sample.hpp>
 #include <boost/statistics/detail/non_parametric/kolmogorov_smirnov/statistic.hpp>
 
 namespace boost{
@@ -41,7 +42,7 @@
     struct check_convergence{
     
             typedef T1 value_type;
- typedef kolmogorov_smirnov::tag::statistic<value_type> tag_;
+ typedef kolmogorov_smirnov::tag::kolmogorov_smirnov tag_;
             typedef boost::accumulators::stats<tag_> state_;
             typedef boost::mpl::push_back<boost::mpl::_,boost::mpl::_> op_;
     
@@ -135,8 +136,8 @@
                 
             template<typename AccSet>
             void operator()(const AccSet& acc,const D& d,std::ostream& os)const{
- value_type ks
- = kolmogorov_smirnov::extract::statistic<value_type>(acc,d);
+ namespace ns = kolmogorov_smirnov;
+ value_type ks = ns::statistic<value_type>( acc, d );
                 os
                     << '('
                     << boost::accumulators::extract::count(acc)

Modified: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/kolmogorov_smirnov/statistic.hpp
==============================================================================
--- sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/kolmogorov_smirnov/statistic.hpp (original)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/kolmogorov_smirnov/statistic.hpp 2010-05-30 11:11:04 EDT (Sun, 30 May 2010)
@@ -33,36 +33,29 @@
 namespace detail{
 namespace kolmogorov_smirnov{
 
- // Usage:
- // namespace ns = kolmogorov_smirnov;
- // accumulator_set<T,stats<ns::tag::statistic<T1> > acc;
- // acc = boost:for_each(samples,acc);
- // ns::extract::statistic<T1>(acc,normal_distribution<T1>(0,1));
- // In this example, the kolmogorov-statistic between the samples and the
- // standard normal distribution is computed.
-
 namespace impl{
 
     // Warning : See empirical_distribution::impl::count
- template<typename T,typename T1>
- class statistic : public boost::accumulators::accumulator_base{
+ template<typename T>
+ class kolmogorov_smirnov : public boost::accumulators::accumulator_base{
             
         typedef std::size_t size_;
         typedef boost::accumulators::dont_care dont_care_;
 
         public:
 
- statistic(dont_care_){};
+ kolmogorov_smirnov(dont_care_){};
 
         typedef size_ size_type;
         typedef T sample_type;
- typedef T1 result_type;
+ typedef void result_type;
 
         void operator()(dont_care_)const{}
 
         template<typename Args>
- result_type result(const Args& args) const
+ result_type result(dont_care_) const
         {
+/*
             typedef T1 val_;
             typedef boost::accumulators::tag::accumulator tag_acc_;
             typedef boost::accumulators::tag::count tag_n_;
@@ -105,6 +98,7 @@
             }
             
             return m1;
+*/
         }
         };
     
@@ -112,8 +106,7 @@
 
 namespace tag
 {
- template<typename T1 = double>
- struct statistic
+ struct kolmogorov_smirnov
       : boost::accumulators::depends_on<
               statistics::detail::empirical_distribution::tag::ordered_sample,
         boost::accumulators::tag::count
@@ -122,52 +115,63 @@
         struct impl{
             template<typename T,typename W>
             struct apply{
- typedef boost::statistics::detail::kolmogorov_smirnov
- ::impl::statistic<T,T1> type;
+ typedef detail::kolmogorov_smirnov::impl::kolmogorov_smirnov<T> type;
             };
         };
     };
 }
-
 namespace result_of{
-
- template<typename T1,typename AccSet>
- struct statistic{
- typedef boost::statistics::detail
- ::kolmogorov_smirnov::tag::statistic<T1> tag_;
- typedef typename boost::accumulators::detail::extractor_result<
- AccSet,
- tag_
- >::type type;
+
+ template<typename T1,typename AccSet,typename D>
+ struct statistic
+ {
+ typedef T1 type;
     };
 
 }
 
-namespace extract
-{
-
     // Usage : statistic<T1>(acc,dist)
     template<typename T1,typename AccSet,typename D>
- typename boost::statistics::detail::kolmogorov_smirnov
- ::result_of::template statistic<T1,AccSet>::type
+ typename kolmogorov_smirnov
+ ::result_of::template statistic<T1,AccSet,D>::type
     statistic(AccSet const& acc,const D& dist)
     {
- typedef boost::statistics::detail
- ::kolmogorov_smirnov::tag::statistic<T1> the_tag;
- return boost::accumulators::extract_result<the_tag>(
- acc,
- (
- boost::statistics::detail::kolmogorov_smirnov
- ::keyword::reference_distribution = dist
- )
- );
- }
+ namespace ed = boost::statistics::detail::empirical_distribution;
+ namespace ks = boost::statistics::detail::kolmogorov_smirnov;
+ typedef T1 val_;
+ typedef std::size_t size_;
+ typedef boost::accumulators::tag::count tag_n_;
+ typedef ed::tag::ordered_sample tag_os_;
 
-}
+ typedef typename ed::result_of::ordered_sample<
+ AccSet>::type ref_os_;
+ typedef typename boost::remove_const< //in case ref changed to cref
+ typename boost::remove_reference<
+ ref_os_
+ >::type
+ >::type os_;
+ typedef typename boost::range_reference<os_>::type ref_elem_;
+
+ ref_os_ ref_os
+ = boost::accumulators::extract_result<tag_os_>( acc );
 
-using extract::statistic;
+ val_ m1 = static_cast<val_>(0);
+ size_ i = 0;
+ size_ n = boost::accumulators::extract::count( acc );
+
+ BOOST_FOREACH(ref_elem_ e,ref_os){
+ i += e.second;
+ val_ ecdf = static_cast<val_>(i) / static_cast<val_>(n);
+ val_ true_cdf = cdf( dist, e.first );
+ val_ m2
+ = (true_cdf > ecdf)?(true_cdf - ecdf) : (ecdf - true_cdf);
+ if(m2 > m1){ m1 = m2; }
+ }
+
+ return m1;
+ }
 
-}// kolmogorov_smirnov
+}// empirical_distribution
 }// detail
 }// statistics
 }// boost

Modified: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/doc/readme.txt
==============================================================================
--- sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/doc/readme.txt (original)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/doc/readme.txt 2010-05-30 11:11:04 EDT (Sun, 30 May 2010)
@@ -1,7 +1,7 @@
 //////////////////////////////////////////////////////////////////////////////
 // non_parametric::doc::readme //
 // //
-// (C) Copyright 2009 Erwann Rogard //
+// (C) Copyright 2009-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) //
@@ -13,34 +13,11 @@
 
 [ Overview ]
 
- C++ classes for non-parametric estimation.
+ C++ classes for non-parametric estimation using the Boost.Accumulator
+ framework.
 
-[ Also see ]
-
- http://boost-sandbox.sourceforge.net/libs/accumulators/doc/html/index.html
-
-[ Compiler ]
-
- gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
 
 [ Dependencies ]
 
- /boost_1_40_0
-
-
-[ History]
- January 20th, 2010
- - Miscellanea reorganization of the files
-
- January 17th, 2010.
- - Modified non_parametric/kolmogorov_smirnov/statistic.hpp from an
- STL-like algorithm to a simpler accumulator.
- - Added check_convergence
-
- January 14th, 2010.
- - Added non_parametric/empirical_distribution
- - Modified non_parametric/kolmogorov_smirnov/statistic.hpp to allow
- combos
-
- October 11th 2009. First version. Implementation of kolmogorov_smirnov
- transfered from distribution_toolkit
+ /boost_1_41_0
+ /sandbox/statistics/detail/support

Modified: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/src/main.cpp
==============================================================================
--- sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/src/main.cpp (original)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/src/main.cpp 2010-05-30 11:11:04 EDT (Sun, 30 May 2010)
@@ -2,15 +2,17 @@
 
 #include <libs/statistics/detail/non_parametric/example/frequency_int.h>
 #include <libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.h>
-#include <libs/statistics/detail/non_parametric/example/contingency_table.h>
+#include <libs/statistics/detail/non_parametric/test/contingency_table1.h>
+#include <libs/statistics/detail/non_parametric/test/contingency_table2.h>
 
 int main()
 {
- //example_frequency_int(std::cout);
- //example_kolmogorov_smirnov(std::cout,0.1,6,10,10);
- //example_kolmogorov_smirnov(std::cout,10.0,6,10,10);
- //example_kolmogorov_smirnov(std::cout,100.0,6,10,10);
- example_contingency_table(std::cout);
+ example_frequency_int(std::cout);
+ example_kolmogorov_smirnov(std::cout,0.1,6,10,10);
+ example_kolmogorov_smirnov(std::cout,10.0,6,10,10);
+ example_kolmogorov_smirnov(std::cout,100.0,6,10,10);
+ test_contingency_table1();
+ test_contingency_table2();
 
     return 0;
 }
\ No newline at end of file


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