Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56419 - sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm
From: erwann.rogard_at_[hidden]
Date: 2009-09-26 20:55:01


Author: e_r
Date: 2009-09-26 20:55:00 EDT (Sat, 26 Sep 2009)
New Revision: 56419
URL: http://svn.boost.org/trac/boost/changeset/56419

Log:
m
Text files modified:
   sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/cdf_empirical_cdf_differences.hpp | 54 ++++++++++++++-------------------------
   sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/kolmogorov_smirnov_distance.hpp | 45 ++++++++++++++++++++++++--------
   sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/sequential_kolmogorov_smirnov_distance.hpp | 24 +++++++++++++----
   3 files changed, 71 insertions(+), 52 deletions(-)

Modified: sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/cdf_empirical_cdf_differences.hpp
==============================================================================
--- sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/cdf_empirical_cdf_differences.hpp (original)
+++ sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/cdf_empirical_cdf_differences.hpp 2009-09-26 20:55:00 EDT (Sat, 26 Sep 2009)
@@ -12,22 +12,21 @@
 #include <string>
 #include <stdexcept>
 #include <algorithm>
-#include <boost/type_traits/function_traits.hpp>
-#include <boost/lambda/bind.hpp>
-#include <boost/lambda/lambda.hpp>
 #include <ext/algorithm>
-#include <boost/format.hpp>
 #include <boost/range.hpp>
-#include <boost/bind.hpp>
-#include <boost/function.hpp>
-#include <boost/numeric/conversion/converter.hpp>
-#include <boost/iterator/counting_iterator.hpp>
-#include <boost/iterator/transform_iterator.hpp>
+
 #include <boost/iterator/iterator_traits.hpp>
+
+#include <boost/typeof/typeof.hpp>
 #include <boost/scalar_dist/fun_wrap/cdf.hpp>
 #include <boost/scalar_dist/meta/bind_delegate.hpp>
 #include <boost/scalar_dist/algorithm/transform.hpp>
 
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
+//#include <boost/lambda/detail/ret.hpp>
+#include <boost/statistics/empirical_cdf/algorithm/transform.hpp>
+
 namespace boost{
 namespace statistics{
 namespace empirical_cdf{
@@ -65,33 +64,20 @@
         InIt e_cdf,
         OutIt out
     ){
- typedef typename iterator_value<InIt>::type value_t;
- typedef typename iterator_difference<InIt>::type diff_t;
- diff_t diff = std::distance(b_cdf,e_cdf);
- value_t n = numeric::converter<value_t,diff_t>::convert(diff);
- typedef numeric::converter<value_t,unsigned> conv_;
-
- return std::transform(
- counting_iterator<unsigned>(0),
- counting_iterator<unsigned>(diff),
+ typedef typename iterator_value<InIt>::type val_;
+
+ BOOST_AUTO(
+ fun,
+ boost::lambda::ret<val_>(
+ boost::lambda::_2 - boost::lambda::_1
+ )
+ );
+
+ return empirical_cdf::transform<val_>(
             b_cdf,
+ e_cdf,
             out,
- // TODO lambda expression might be cleaner:
- bind<value_t>(
- &fabs,
- bind<value_t>(
- std::minus<value_t>(),
- bind<value_t>(
- std::divides<value_t>(),
- bind<value_t>(
- numeric::converter<value_t,unsigned>(),
- _1
- ),
- n
- ),
- _2
- )
- )
+ fun
         );
     }
 

Modified: sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/kolmogorov_smirnov_distance.hpp
==============================================================================
--- sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/kolmogorov_smirnov_distance.hpp (original)
+++ sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/kolmogorov_smirnov_distance.hpp 2009-09-26 20:55:00 EDT (Sat, 26 Sep 2009)
@@ -9,43 +9,64 @@
 #ifndef BOOST_STATISTICS_EMPIRICAL_CDF_ALGORITHM_KOLMOGOROV_SMIRNOV_DISTANCE_HPP_ER_2009
 #define BOOST_STATISTICS_EMPIRICAL_CDF_ALGORITHM_KOLMOGOROV_SMIRNOV_DISTANCE_HPP_ER_2009
 #include <vector>
+#include <cmath>
+#include <string>
 #include <boost/range.hpp>
 #include <boost/iterator/iterator_traits.hpp>
-#include <boost/statistics/empirical_cdf/algorithm/sequential_kolmogorov_smirnov_distance.hpp>
+#include <boost/function.hpp>
+#include <boost/format.hpp>
+#include <boost/range.hpp>
+#include <boost/statistics/empirical_cdf/algorithm/cdf_empirical_cdf_differences.hpp>
+
 
 namespace boost{
 namespace statistics{
 namespace empirical_cdf{
 
- // *[b_x,e_x) represents a random sample (not necessarily sorted)
+
+ // *[b_x,e_x) is a random sample (not sorted)
     template<typename D,typename InIt>
     typename iterator_value<InIt>::type
     kolmogorov_smirnov_distance(
         const D& dist, // e.g. D == normal_distribution<double>
         InIt b_x,
         InIt e_x
+ Out b_cdf_diff
     );
 
     // Implementation //
     
- template<typename D,typename InIt>
+ template<typename D,typename InIt,typename Out>
     typename iterator_value<InIt>::type
     kolmogorov_smirnov_distance(
         const D& dist,
         InIt b_x,
- InIt e_x
+ InIt e_x,
+ Out b_cdf_diff,
     ){
- typedef typename iterator_value<InIt>::type val_;
- typedef std::vector<val_> vals_;
- vals_ vals(1);
- sequential_kolmogorov_smirnov_distance(
+ if(!is_sorted(b_x,e_x)){
+ static const char* msg
+ = "kolmogorov_smirnov_distance : [b_x,e_x) not sorted";
+ throw std::runtime_error(
+ msg
+ );
+ }
+
+ it_val_ e_cdf_diff = cdf_empirical_cdf_differences(
             dist,
             b_x,
             e_x,
- 1,
- boost::begin(vals)
- );
- return vals.back();
+ b_cdf_diff
+ );
+ return(
+ *(
+ std::max_element(
+ make_transform_iterator(b_cdf_diff,fun)
+ make_transform_iterator(e_cdf_diff,fun)
+ )
+ )
+ );
+
     }
 
 }// empirical_cdf

Modified: sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/sequential_kolmogorov_smirnov_distance.hpp
==============================================================================
--- sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/sequential_kolmogorov_smirnov_distance.hpp (original)
+++ sandbox/statistics/empirical_cdf/boost/statistics/empirical_cdf/algorithm/sequential_kolmogorov_smirnov_distance.hpp 2009-09-26 20:55:00 EDT (Sat, 26 Sep 2009)
@@ -28,6 +28,7 @@
     //
     // Requirements:
     // [b_x,e_x) is the empirical sample as originally drawn i.e. NOT SORTED
+ //
     template<typename D,typename It,typename ItO>
     ItO sequential_kolmogorov_smirnov_distance(
         const D& dist,
@@ -39,14 +40,20 @@
 
     // Implementation //
 
+ // for each b in {b_x+dx[0],b_x+dx[1],...,b_x+dx[n-1]}
+ // computes the distance to the empir cdf [b,e_x)
     template<typename D,typename It,typename ItO>
     ItO sequential_kolmogorov_smirnov_distance(
         const D& dist,
         It b_x,
         It e_x,
+ It b_dx,
+ It e_dx,
         typename iterator_difference<It>::type k,
         ItO i_o
- ){
+ )
+ {
+ typedef std::string str_;
         typedef typename iterator_difference<It>::type diff_;
         typedef typename iterator_value<It>::type val_;
         typedef std::vector<val_> vals_;
@@ -54,10 +61,10 @@
         if( b_x == e_x ){ return i_o; }
         diff_ diff = std::distance( b_x, e_x);
         if(diff % k != 0){
- static const char* msg = strcpy(
- "sequential_kolmogorov_smirnov_distance",
+ static const str_ msg =
+ str_("sequential_kolmogorov_smirnov_distance") +
                 "diff = %1% not multiple of k = %2%."
- );
+ ;
             format f(msg); f % diff % k;
             throw std::runtime_error(f.str());
         }
@@ -70,11 +77,16 @@
             std::advance(i_x,delta);
             r_x.clear();
             std::copy(
- b_x,i_x,std::back_inserter(r_x)
+ b_x,
+ i_x,
+ std::back_inserter(r_x)
             );
             std::sort(boost::begin(r_x),boost::end(r_x));
             it_val_ e_cdf = cdf_empirical_cdf_differences(
- dist,boost::begin(r_x),boost::end(r_x),boost::begin(cdfs)
+ dist,
+ boost::begin(r_x),
+ boost::end(r_x),
+ boost::begin(cdfs)
             );
             *i_o = (
                 *(


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