Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56642 - in sandbox/statistics/cross_validation: boost/statistics/detail/cross_validation boost/statistics/detail/cross_validation/data boost/statistics/detail/cross_validation/estimator/concept boost/statistics/detail/cross_validation/estimator/meta boost/statistics/detail/cross_validation/extractor boost/statistics/detail/cross_validation/k_fold libs/statistics/detail/cross_validation/doc libs/statistics/detail/cross_validation/example
From: erwann.rogard_at_[hidden]
Date: 2009-10-07 22:25:08


Author: e_r
Date: 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
New Revision: 56642
URL: http://svn.boost.org/trac/boost/changeset/56642

Log:
a/m
Added:
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/data/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/data/input_output.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/data/input_output_generator.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/predictor2.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/estimator.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/input_data.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/output_data.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/training_dataset.hpp (contents, props changed)
Text files modified:
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_iterator.hpp | 12 +++++++++---
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/include.hpp | 6 +++---
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/cross_validate.hpp | 4 ++--
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/partition.hpp | 16 ++++++++++++++--
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/doc/readme.txt | 5 +----
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.cpp | 24 ++++++++++++------------
   6 files changed, 41 insertions(+), 26 deletions(-)

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/data/input_output.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/data/input_output.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -0,0 +1,78 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::data::input_output.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_CROSS_VALIDATION_DATA_INPUT_OUTPUT_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_DATA_INPUT_OUTPUT_HPP_ER_2009
+#include <boost/mpl/int.hpp>
+#include <boost/utility/result_of.hpp>
+#include <boost/fusion/sequence/intrinsic/at_key.hpp>
+#include <boost/fusion/include/at_key.hpp>
+
+#include <boost/fusion/support/pair.hpp>
+#include <boost/fusion/include/pair.hpp>
+
+#include <boost/fusion/container/map.hpp>
+#include <boost/fusion/include/map.hpp>
+#include <boost/fusion/include/map_fwd.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace data{
+
+ // Data-type for (x,f(x))
+ //
+ // Note: the library does not require a specific data-type; this one is
+ // provided as a convenience
+ template<
+ typename X,
+ typename F,
+ typename Kx = mpl::int_<1>,
+ typename Ky = mpl::int_<2>
+ >
+ struct meta_input_output{
+
+ struct input{
+ typedef Kx key_type;
+ typedef X data_type;
+ typedef boost::fusion::pair<key_type,data_type> type;
+ };
+ struct output{
+ typedef Ky key_type;
+ typedef typename boost::result_of<F(const X&)>::type data_type;
+ typedef boost::fusion::pair<key_type,data_type> type;
+ };
+
+ typedef boost::fusion::map<
+ typename input::type,
+ typename output::type
+ > type;
+
+ template<typename X1>
+ static type make(const X1& x,const F& f){
+ typedef typename input::key_type k_x_;
+ typedef typename output::key_type k_y_;
+
+ return type(
+ boost::fusion::make_pair<k_x_>(x),
+ boost::fusion::make_pair<k_y_>(
+ f(x)
+ )
+ );
+ }
+
+ };
+
+}// data
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/data/input_output_generator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/data/input_output_generator.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -0,0 +1,80 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::data::input_output_generator.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_CROSS_VALIDATION_DATA_INPUT_OUTPUT_GENERATOR_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_DATA_INPUT_OUTPUT_GENERATOR_HPP_ER_2009
+
+#include <boost/statistics/detail/cross_validation/data/input_output.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace data{
+
+ // Maps x to a data-type representing (x,f(x))
+ //
+ // Note: the library does not require a specific data-type; this one is
+ // provided as a convenience
+ template<
+ typename X,typename F,
+ typename Kx = mpl::int_<1>,
+ typename Ky = mpl::int_<2>
+ >
+ class input_output_generator {// : protected F{
+ typedef meta_input_output<X,F,Kx,Ky> meta_;
+
+ public:
+
+ typedef meta_ meta_input_output;
+
+ typedef typename meta_::type result_type;
+
+ input_output_generator(){}
+// input_output_generator(const F& f):F(f){}
+// input_output_generator(const input_output_generator& that)
+// :F(static_cast<const F&>(that)){}
+// input_output_generator&
+// operator=(const input_output_generator& that)
+// {
+// if(&that!=this){
+// static_cast<F&>(*this) = static_cast<const F&>(that);
+// }
+// return (*this);
+// }
+
+ input_output_generator(const F& f):f_(f){}
+ input_output_generator(const input_output_generator& that)
+ :f_(that.f_){}
+ input_output_generator&
+ operator=(const input_output_generator& that)
+ {
+ if(&that!=this){
+ this->f_ = that.f_;
+ }
+ return (*this);
+ }
+
+ template<typename X1>
+ result_type operator()(const X1& x)const{
+// return meta_::make(x,static_cast<const F&>(*this));
+ return meta_::make(x,this->f_);
+ }
+
+ protected:
+ mutable F f_;
+
+ };
+
+}// data
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/predictor2.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/predictor2.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -0,0 +1,52 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::concept::predictor.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_CROSS_VALIDATION_ESTIMATOR_CONCEPT_PREDICTOR_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_CONCEPT_PREDICTOR_HPP_ER_2009
+#include <boost/concept_check.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/meta/estimator.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/meta/input_data_type.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/meta/output_data_type.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace concept{
+
+ // Refines Predictor with a return type
+ template <typename B>
+ class Predictor2 : public B
+ {
+ typedef typename B::estimator_type e_;
+ typedef typename B::input_data_type i_;
+ typedef typename B::output_data_type o_;
+
+ public:
+
+ BOOST_CONCEPT_USAGE(Predictor2)
+ {
+ o = e.predict( i );
+ }
+
+ private:
+ e_ e;
+ i_ i;
+ o_ o;
+
+ };
+
+}// concept
+}// estimator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/estimator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/estimator.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -0,0 +1,32 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::meta::estimator.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_CROSS_VALIDATION_ESTIMATOR_META_ESTIMATOR_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_META_ESTIMATOR_HPP_ER_2009
+#include <boost/mpl/empty_base.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace meta{
+
+ template<typename I,typename B = mpl::empty_base>
+ struct estimator : B{
+ typedef I estimator_type;
+ };
+
+}// meta
+}// estimator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/input_data.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/input_data.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::meta::input.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_CROSS_VALIDATION_ESTIMATOR_META_INPUT_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_META_INPUT_HPP_ER_2009
+#include <boost/mpl/empty_base.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace meta{
+
+ template<typename T,typename B = mpl::empty_base>
+ struct input_data : B{
+ typedef T input_data_type;
+ };
+
+}// meta
+}// estimator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+
+#endif

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/output_data.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/output_data.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -0,0 +1,32 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::meta::output_data.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_CROSS_VALIDATION_ESTIMATOR_META_OUTPUT_DATA_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_META_OUTPUT_DATA_HPP_ER_2009
+#include <boost/mpl/empty_base.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace meta{
+
+ template<typename T,typename B = mpl::empty_base>
+ struct output_data : B{
+ typedef T output_data_type;
+ };
+
+}// meta
+}// estimator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/training_dataset.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/meta/training_dataset.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -0,0 +1,32 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::meta::training_datset.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_CROSS_VALIDATION_ESTIMATOR_META_TRAINING_DATASET_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_META_TRAINING_DATASET_HPP_ER_2009
+#include <boost/mpl/empty_base.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace meta{
+
+ template<typename T,typename B = mpl::empty_base>
+ struct training_dataset : B{
+ typedef T training_dataset_type;
+ };
+
+}// meta
+}// estimator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif

Modified: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_iterator.hpp
==============================================================================
--- sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_iterator.hpp (original)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_iterator.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -9,6 +9,7 @@
 #ifndef BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_EXTRACTOR_META_ITERATOR_HPP_ER_2009
 #define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_EXTRACTOR_META_ITERATOR_HPP_ER_2009
 #include <boost/concept/assert.hpp>
+#include <boost/utility/result_of.hpp>
 #include <boost/iterator/iterator_traits.hpp>
 #include <boost/iterator/transform_iterator.hpp>
 #include <boost/statistics/detail/cross_validation/extractor/concept.hpp>
@@ -23,8 +24,13 @@
 
     template<typename F,typename It>
     struct iterator{
-
- typedef transform_iterator<F,It> type;
+
+ // Rationale: boost.user mailing list
+ // Subject: [transform_iterator]'s reference
+ // 10/05/2009
+ typedef typename iterator_reference<It>::type ref1_;
+ typedef typename result_of<F(ref1_)>::type ref2_;
+ typedef boost::transform_iterator<F,It,ref2_> type;
         
         typedef typename iterator_value<It>::type unit_;
         
@@ -34,7 +40,7 @@
                 Concept<F,unit_>
             ));
         
- return make_tranform_iterator(i,f);
+ return type(i,f);
         };
     };
     

Modified: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/include.hpp
==============================================================================
--- sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/include.hpp (original)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/include.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -1,13 +1,13 @@
 //////////////////////////////////////////////////////////////////////////////
-// statistics::goodness_of_fit::include.hpp //
+// cross_validation::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_CROSS_VALIDATION_EXTRACTOR_INCLUDE_HPP_ER_2009
-#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_EXTRACTOR_INCLUDE_HPP_ER_2009
+#ifndef BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_INCLUDE_HPP_ER_2009
 
 #include <boost/statistics/detail/cross_validation/algorithm/include.hpp>
 #include <boost/statistics/detail/cross_validation/data/include.hpp>

Modified: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/cross_validate.hpp
==============================================================================
--- sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/cross_validate.hpp (original)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/cross_validate.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -27,10 +27,10 @@
         partition<U,Ft,Fi,Fo>& kfp,
         E estimator,
         It i_p, // predicted values
- It1 i_o // output values
+ It1 i_o // true values
     ){
         kfp.initialize();
- while(kfp.j()<kfp.k()){
+ while(kfp.index()<kfp.n_folds()){
             i_p = train_predict(
                 kfp,
                 estimator,

Modified: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/partition.hpp
==============================================================================
--- sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/partition.hpp (original)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/partition.hpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -98,11 +98,20 @@
         typename meta_input_range::type input_range()const;
         typename meta_output_range::type output_range()const;
 
+
+ static str_ description_header;
+
+ const int_& n_test()const{ return this->n(); }
+ const int_& index()const{ return this->j(); }
+ const int_& n_folds()const{ return this->k(); }
+
+ int_ n_training()const{ return this->n() * (this->k()-1); }
+
+ protected:
         const int_& n()const; // size of test data
         const int_& j()const; // index of current iteration
         const int_& k()const; // number of iterations
 
- //private:
         int_ k_;
         int_ j_;
         int_ n_;
@@ -112,12 +121,15 @@
         Fi fi_;
         Fo fo_;
     };
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ typename partition<U,Ft,Fi,Fo>::str_
+ partition<U,Ft,Fi,Fo>::description_header ="(n_test,n_index,n_folds)";
 
     template<typename U,typename Ft,typename Fi,typename Fo>
     std::ostream& operator<<(
         std::ostream& out,const partition<U,Ft,Fi,Fo>& that){
         format f("partition(%1%,%2%,%3%)");
- f % that.n() % that.j() % that.k();
+ f % that.n_test() % that.index() % that.n_folds();
         return (out << f.str());
     }
 

Modified: sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/doc/readme.txt
==============================================================================
--- sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/doc/readme.txt (original)
+++ sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/doc/readme.txt 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -36,15 +36,12 @@
 
 [ History ]
 
+October 6 2009 Added a convenient data-type representing (x,y) and a generator
 September 2009 - Two packages below merged into cross_validation with a better
                 interface.
 August 2009 - Creation of goodness_of_fit
                 - Creating of estimator_concept
 
-[ TODO ]
-
-Currently, k_fold_data makes a copy of a dataset. Intrusive or range
-(pair of iterator) alternatives may need to be considered.
 
 [ Sources ]
 

Modified: sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.cpp
==============================================================================
--- sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.cpp (original)
+++ sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.cpp 2009-10-07 22:25:07 EDT (Wed, 07 Oct 2009)
@@ -16,11 +16,8 @@
 #include <boost/random/normal_distribution.hpp>
 #include <boost/random/variate_generator.hpp>
 
-//#include <boost/math/distributions/normal.hpp>
 #include <boost/math/tools/precision.hpp>
 
-//#include <boost/mpl/nested_type.hpp>
-
 #include <boost/accumulators/accumulators.hpp>
 #include <boost/accumulators/statistics/mean.hpp>
 #include <boost/accumulators/statistics/stats.hpp>
@@ -37,6 +34,9 @@
     os << "-> example_k_fold :" << std::endl;
 
     // This example shows how to perform K train/predict cycles.
+ // The estimator is built upon a Boost.Accumulator for the mean.
+ // The input (x) equals the input (y), in this case, and has type double
+
     using namespace boost;
     namespace stat = boost::statistics::detail;
     namespace cv = stat::cross_validation;
@@ -47,7 +47,6 @@
     typedef mt19937 urng_;
     typedef double val_;
     typedef std::vector<val_> vals_;
- typedef range_iterator<const vals_>::type const_vals_it_;
     typedef range_iterator<vals_>::type vals_it_;
     typedef boost::normal_distribution<val_> nd_;
     typedef boost::variate_generator<urng_&,nd_> vg_;
@@ -59,6 +58,7 @@
> stat_;
     typedef accumulators::accumulator_set<val_,stat_> acc_;
 
+ // Boost.Accumulators cannot be used directly. An adaptor is needed.
     typedef cv_es::adaptor::meta::nullary_predictor<acc_,tag_> meta_p_;
     typedef cv_es::adaptor::joined<
         cv_es::adaptor::unary_trainer,
@@ -72,25 +72,25 @@
     const unsigned k = 5e0;
     BOOST_ASSERT(n % k == 0);
 
- vals_ vec_x;
-// dist_ dist;
     nd_ nd;
     urng_ urng;
     vg_ vg(urng,nd);
 
+ vals_ vec_x;
     std::generate_n(
         std::back_inserter(vec_x),
         n,
         vg
     );
-
- kf_p_ kf_p(
+
+ // vec_x is duplicated in kf_p, which is intenteded in this example.
+ // example_k_fold in sandbox/kernel shows how to avoid duplication
+
+ kf_p_ kf_p(
         k,
         boost::begin(vec_x),
         boost::end(vec_x)
     );
-
-// os << kf_p;
     
     struct float_{
             
@@ -110,7 +110,7 @@
         }
     
         vals_it_ vec_x_it = boost::begin( vec_x );
- while(kf_p.j()<kf_p.k()){
+ while(kf_p.index()<kf_p.n_folds()){
             os << kf_p << std::endl;
             BOOST_FOREACH(const val_& t,kf_p.subset2())
             {
@@ -129,7 +129,7 @@
     vals_it_ preds_e;
     BOOST_ASSERT(n / k > 1);
     kf_p.initialize();
- while(kf_p.j()<kf_p.k()){
+ while(kf_p.index()<kf_p.n_folds()){
         acc_ acc;
         joined_ joined(acc);
         preds_e = train_predict(


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