Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56479 - in sandbox/statistics/cross_validation: . boost boost/statistics boost/statistics/detail boost/statistics/detail/cross_validation boost/statistics/detail/cross_validation/error boost/statistics/detail/cross_validation/estimator boost/statistics/detail/cross_validation/estimator/adaptor boost/statistics/detail/cross_validation/estimator/concept boost/statistics/detail/cross_validation/extractor boost/statistics/detail/cross_validation/k_fold libs libs/statistics libs/statistics/detail libs/statistics/detail/cross_validation libs/statistics/detail/cross_validation/doc libs/statistics/detail/cross_validation/example libs/statistics/detail/cross_validation/src
From: erwann.rogard_at_[hidden]
Date: 2009-09-29 19:09:49


Author: e_r
Date: 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
New Revision: 56479
URL: http://svn.boost.org/trac/boost/changeset/56479

Log:
adding cross_validation
Added:
   sandbox/statistics/cross_validation/
   sandbox/statistics/cross_validation/boost/
   sandbox/statistics/cross_validation/boost/statistics/
   sandbox/statistics/cross_validation/boost/statistics/detail/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/include.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/mean_abs_error.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/sqrt_mse.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/include.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/joined.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/nullary_predictor.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/unary_trainer.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/wrapper.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/include.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/predictor.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/trainer.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/concept.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/identity.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_iterator.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_range.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/include.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/include.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/partition.hpp (contents, props changed)
   sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/train_predict.hpp (contents, props changed)
   sandbox/statistics/cross_validation/libs/
   sandbox/statistics/cross_validation/libs/statistics/
   sandbox/statistics/cross_validation/libs/statistics/detail/
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/doc/
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/doc/readme.txt (contents, props changed)
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.cpp (contents, props changed)
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.h (contents, props changed)
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/src/
   sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/src/main.cpp (contents, props changed)

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/include.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::error::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_ERROR_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ERROR_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/detail/cross_validation/error/mean_abs_error.hpp>
+#include <boost/statistics/detail/cross_validation/error/sqrt_mse.hpp>
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/mean_abs_error.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/mean_abs_error.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,58 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::error::mean_abs_error.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_ERROR_MEAN_ABS_ERROR_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ERROR_MEAN_ABS_ERROR_HPP_ER_2009
+#include <cmath>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/range.hpp>
+#include <boost/vector_space/functional/l1_distance.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace error{
+
+ template<typename It,typename It1>
+ typename iterator_value<It>::type
+ mean_abs_error(
+ It b,
+ It e,
+ It1 b1
+ ){
+
+ typedef iterator_range<It> range_;
+ typedef typename iterator_difference<It>::type diff_;
+ typedef iterator_range<It1> range1_;
+ typedef typename iterator_value<It>::type val_;
+ typedef vector_space::template l1_distance<range_> l1_;
+
+ diff_ d = std::distance(b,e);
+
+ l1_ l1(range_(b,e));
+ range1_ range1(
+ b1,
+ boost::next(
+ b1,
+ d
+ )
+ );
+ val_ res = l1(range1);
+ res /= static_cast<val_>(d);
+ res = sqrt( res );
+ return res;
+ };
+
+}// error
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/sqrt_mse.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/error/sqrt_mse.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,58 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::error::sqrt_mse.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_ERROR_SQRT_MSE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ERROR_SQRT_MSE_HPP_ER_2009
+#include <cmath>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/range.hpp>
+#include <boost/vector_space/functional/l2_distance_squared.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace error{
+
+ template<typename It,typename It1>
+ typename iterator_value<It>::type
+ sqrt_mse(
+ It b,
+ It e,
+ It1 b1
+ ){
+
+ typedef iterator_range<It> range_;
+ typedef typename iterator_difference<It>::type diff_;
+ typedef iterator_range<It1> range1_;
+ typedef typename iterator_value<It>::type val_;
+ typedef vector_space::l2_distance_squared<range_> l2_;
+
+ diff_ d = std::distance(b,e);
+
+ l2_ l2(range_(b,e));
+ range1_ range1(
+ b1,
+ boost::next(
+ b1,
+ d
+ )
+ );
+ val_ res = l2(range1);
+ res /= static_cast<val_>(d);
+ res = sqrt( res );
+ return res;
+ };
+
+}// error
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/include.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::adaptor::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_ESTIMATOR_ADAPTOR_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_ADAPTOR_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/detail/cross_validation/estimator/adaptor/unary_trainer.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/adaptor/nullary_predictor.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/adaptor/wrapper.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/adaptor/joined.hpp>
+
+#endif

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/joined.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/joined.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,74 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::adaptor::joined.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_ADAPTOR_JOINED_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_ADAPTOR_JOINED_HPP_ER_2009
+//#include <boost/mpl/empty_base.hpp>
+#include <boost/mpl/nested_type.hpp>
+#include <boost/foreach.hpp>
+#include <boost/range.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/adaptor/wrapper.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace adaptor{
+
+ // A/a and T/t type/object pairs for accumulator an training value.
+ // Expression
+ // a(x)
+ template<
+ template<typename> class T, // trainer
+ template<typename> class P, // predictor
+ typename A
+ >
+ class joined : public
+ mpl::nested_type<
+ T<
+ typename mpl::nested_type<
+ P<
+ wrapper<A>
+ >
+ >::type
+ >
+ >::type
+ {
+ typedef wrapper<A> w_;
+ typedef typename mpl::nested_type<
+ P<
+ wrapper<A>
+ >
+ >::type p_;
+ typedef typename mpl::nested_type<
+ T<
+ p_
+ >
+ >::type t_;
+ public:
+
+ joined(A& a): t_(
+ p_(
+ w_(a)
+ )
+ ){}
+ joined(const joined& that): t_(that){}
+
+ private:
+ joined();
+ };
+
+}// adaptor
+}// estimator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/nullary_predictor.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/nullary_predictor.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,79 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::adaptor::nullary_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_ADAPTOR_NULLARY_PREDICTOR_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_ADAPTOR_NULLARY_PREDICTOR_HPP_ER_2009
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/empty_base.hpp>
+// #include <boost/typeof/typeof.hpp>
+#include <boost/accumulators/accumulators.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace adaptor{
+
+ // A is an accumulator_set in Boost.Accumulator
+ // Expression
+ // a(x)
+ template<
+ typename A,
+ typename Tag,
+ typename B
+ >
+ class nullary_predictor : public B
+ {
+ public:
+ nullary_predictor(const B& b):B(b){}
+ nullary_predictor(const nullary_predictor& that):B(that){}
+
+ typedef typename mpl::apply<
+ A,
+ Tag
+ >::type::result_type result_type;
+
+ // This should be equivalent, up to add_reference
+ //typedef BOOST_TYPEOF_TPL(
+ // boost::accumulators::extract_result<Tag>(A())
+ //) result_type;
+
+ template<typename X>
+ result_type predict(const X&)const{
+ return boost::accumulators::extract_result<Tag>(
+ this->const_reference()
+ );
+ }
+
+ private:
+ nullary_predictor(){}
+ };
+
+namespace meta{
+ template<typename A,typename Tag>
+ struct nullary_predictor{
+
+ template<typename B>
+ struct apply{
+ typedef adaptor::nullary_predictor<A,Tag,B> type;
+ };
+
+ };
+}
+
+}// adaptor
+}// estimator
+}// cross_validation
+}// detail
+
+
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/unary_trainer.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/unary_trainer.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,57 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::adaptor::unary_trainer.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_ADAPTOR_UNARY_TRAINER_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_ADAPTOR_UNARY_TRAINER_HPP_ER_2009
+//#include <boost/mpl/empty_base.hpp>
+#include <boost/foreach.hpp>
+#include <boost/range.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/adaptor/wrapper.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace adaptor{
+
+ template<typename B>
+ class unary_trainer : public B{
+ public:
+
+ unary_trainer(const B& b): B(b){}
+ unary_trainer(const unary_trainer& that): B(that){}
+
+ template<typename R>
+ void train(R training_range){
+ typedef typename range_value<R>::type t_;
+ typedef typename call_traits<t_>::param_type par_;
+
+ BOOST_FOREACH(par_ t,training_range){
+ this->accumulate(t);
+ }
+
+ }
+
+ private:
+ template<typename M>
+ void accumulate(const M& m)const{
+ this->reference()(m);
+ }
+ unary_trainer();
+ };
+
+}// adaptor
+}// estimator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/wrapper.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/adaptor/wrapper.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,40 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::estimator::adaptor::wrapper.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_ADAPTOR_WRAPPER_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_ADAPTOR_WRAPPER_HPP_ER_2009
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace adaptor{
+
+ template<typename A>
+ struct wrapper{
+
+ wrapper(A& a):a_(a){}
+
+ A& reference()const{ return this->a_; }
+ const A& const_reference()const{ return this->a_; }
+
+ private:
+ wrapper();
+ A& a_;
+
+ };
+
+}// adaptor
+}// estimator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/include.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// 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_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_CONCEPT_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/detail/cross_validation/estimator/concept/trainer.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/concept/predictor.hpp>
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/predictor.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/predictor.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////////
+// 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/mpl/empty_base.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace concept{
+
+ // Type Object
+ // E estimator
+ // T test point
+ template <typename E,typename T, typename B = mpl::empty_base>
+ class Predictor : B
+ {
+ public:
+
+ BOOST_CONCEPT_USAGE(Predictor)
+ {
+ e.predict( t );
+ }
+
+ private:
+ E e;
+ T t;
+ };
+
+}// 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/concept/trainer.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/trainer.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,45 @@
+//////////////////////////////////////////////////////////////////////////////
+// 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_TRAINER_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_ESTIMATOR_CONCEPT_TRAINER_HPP_ER_2009
+#include <boost/concept_check.hpp>
+#include <boost/mpl/empty_base.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace estimator{
+namespace concept{
+
+ // Type Object
+ // E estimator type
+ // R range of training points
+ template <typename E,typename R,typename B = mpl::empty_base>
+ class Trainer : B
+ {
+ public:
+ BOOST_CONCEPT_USAGE(Trainer)
+ {
+ e.train( r );
+ }
+
+ private:
+ E e;
+ R r;
+ };
+
+}// concept
+}// estimator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/concept.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/concept.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,38 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::extractor::concept.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_CONCEPT_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_EXTRACTOR_CONCEPT_HPP_ER_2009
+#include <boost/concept_check.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace extractor{
+
+ template<typename F,typename U>
+ struct Concept{
+
+ BOOST_CONCEPT_USAGE(Concept){
+ f(u);
+ }
+
+ private:
+ F f;
+ U u; // data unit
+
+ };
+
+}// extractor
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/identity.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/identity.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,42 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::extractor::identity.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_IDENTITY_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_EXTRACTOR_IDENTITY_HPP_ER_2009
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace extractor{
+
+ struct identity{
+
+ identity(){}
+
+ template<typename T>
+ struct result{};
+
+ template<typename T>
+ struct result<identity(const T&)>{
+ typedef const T& type;
+ };
+
+ template<typename T>
+ const T&
+ operator()(const T& t)const{ return t; }
+
+ };
+
+}// iterator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_iterator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_iterator.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,58 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::extractor::meta_iterator.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_META_ITERATOR_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_EXTRACTOR_META_ITERATOR_HPP_ER_2009
+#include <boost/concept/assert.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/statistics/detail/cross_validation/extractor/concept.hpp>
+#include <boost/statistics/detail/cross_validation/extractor/identity.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace extractor{
+namespace meta{
+
+ template<typename F,typename It>
+ struct iterator{
+
+ typedef transform_iterator<F,It> type;
+
+ typedef typename iterator_value<It>::type unit_;
+
+ static type make(const F& f, It i){
+
+ BOOST_CONCEPT_ASSERT((
+ Concept<F,unit_>
+ ));
+
+ return make_tranform_iterator(i,f);
+ };
+ };
+
+ template<typename It>
+ struct iterator<identity,It>{
+ typedef It type;
+
+ static type make(const identity&,It i){
+ return i;
+ };
+
+ };
+
+}// meta
+}// iterator
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_range.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/extractor/meta_range.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,44 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::extractor::meta_iterator.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_META_RANGE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_EXTRACTOR_META_RANGE_HPP_ER_2009
+#include <boost/range.hpp>
+#include <boost/statistics/detail/cross_validation/extractor/meta_iterator.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace extractor{
+namespace meta{
+
+ template<typename F,typename S>
+ struct range{
+ typedef typename range_iterator<S>::type seq_iter_;
+ typedef typename meta::iterator<F,seq_iter_> meta_;
+ typedef typename meta_::type ex_iter_;
+ typedef typename iterator_range<ex_iter_>::type type;
+
+ static type make(const F& f, seq_iter_ b, seq_iter_ e){
+ return type(
+ meta_::make(f,b),
+ meta_::make(f,e)
+ );
+ }
+
+ };
+
+}// meta
+}// extractor
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/include.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,16 @@
+//////////////////////////////////////////////////////////////////////////////
+// statistics::goodness_of_fit::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
+
+#include <boost/statistics/detail/cross_validation/algorithm/include.hpp>
+#include <boost/statistics/detail/cross_validation/data/include.hpp>
+#include <boost/statistics/detail/cross_validation/functional/include.hpp>
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/include.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,16 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::k_fold::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_K_FOLD_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_K_FOLD_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/detail/cross_validation/k_fold/partition.hpp>
+#include <boost/statistics/detail/cross_validation/k_fold/train_predict.hpp>
+
+#endif
+

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/partition.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/partition.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,317 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::k_fold::partition.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_K_FOLD_PARTITION_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_DATA_K_FOLD_PARTITION_HPP_ER_2009
+#include <stdexcept>
+#include <iterator>
+#include <vector>
+#include <ostream>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/range.hpp>
+#include <boost/format.hpp>
+#include <boost/utility.hpp>
+#include <boost/circular_buffer.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+
+#include <boost/statistics/detail/cross_validation/extractor/meta_range.hpp>
+//#include <boost/statistics/detail/tuple/meta/include.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace k_fold{
+
+
+ // k = 4
+ // train test
+ // [0][1][2] (3) j = 3
+ // -------------
+ // [1][2][3] (0) j = 0
+ // [2][3][0] (1) j = 1
+ // [3][0][1] (2) j = 2
+ // [0][1][2] (3) j = 3
+
+ // Partitions a dataset into 2 disjoint subsets, of size n(k-1) and n.
+ //
+ // U is the type of one observation unit, u, which must contain enough
+ // information to train and test an estimator. For example, t = (x,y)
+ // is needed to train a regression estimator, x is the input to the
+ // predictor, and y is a value against which the output is compared
+ // Each of t, x, and y are extracted are extracted from u using instances
+ // of Ft, Fi, and Fo, respectively.
+ template<
+ typename U,
+ typename Ft = extractor::identity,
+ typename Fi = extractor::identity,
+ typename Fo = extractor::identity
+ >
+ class partition{
+
+ // Warning:
+ // Since the dataset is kept internally, U must not be a reference or
+ // contain a reference
+
+ typedef std::string str_;
+ public:
+ typedef boost::circular_buffer<U> subset1_type;
+ typedef std::vector<U> subset2_type;
+ typedef long int int_;
+
+ struct meta_training_range
+ : extractor::meta::range<Ft,const subset1_type>{};
+ struct meta_input_range
+ : extractor::meta::range<Fi,const subset2_type>{};
+ struct meta_output_range
+ : extractor::meta::range<Fo,const subset2_type>{};
+
+ partition();
+ template<typename It>
+ partition(int_ k, It b,It e);
+ template<typename It>
+ partition(
+ const Ft& ft,
+ const Fi& fi,
+ const Fo& fo,
+ int_ k, It b,It e
+ );
+ partition(const partition&);
+ partition& operator=(const partition&);
+
+ template<typename It>
+ void initialize(int_ k, It b,It e); // j = 0
+ void initialize(); //restores state to j = 0
+ void increment(); // ++j
+
+ // Access
+ const subset1_type& subset1()const;
+ const subset2_type& subset2()const;
+
+ typename meta_training_range::type training_range()const;
+ typename meta_input_range::type input_range()const;
+ typename meta_output_range::type output_range()const;
+
+ 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_;
+ subset1_type subset1_;
+ subset2_type subset2_;
+ Ft ft_;
+ Fi fi_;
+ Fo fo_;
+ };
+
+ 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();
+ return (out << f.str());
+ }
+
+ // Implementation //
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ partition<U,Ft,Fi,Fo>::partition()
+ :k_(0),j_(0),n_(0){}
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ template<typename It>
+ partition<U,Ft,Fi,Fo>::partition(int_ k, It b,It e)
+ {
+ this->initialize(k,b,e);
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ template<typename It>
+ partition<U,Ft,Fi,Fo>::partition(
+ const Ft& ft,
+ const Fi& fi,
+ const Fo& fo,
+ int_ k, It b,It e
+ )
+ :ft_(ft),fi_(fi),fo_(fo)
+ {
+ this->initialize(k,b,e);
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ partition<U,Ft,Fi,Fo>::partition(const partition& that)
+ :k_(that.k_),j_(that.j_),n_(that.n_),
+ subset1_(that.subset1_),
+ subset2_(that.subset2_),
+ ft_(that.ft_),
+ fi_(that.fi_),
+ fo_(that.fo_){}
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ partition<U,Ft,Fi,Fo>& partition<U,Ft,Fi,Fo>::operator=(const partition& that)
+ {
+ this->k_ = that.k_;
+ this->j_ = that.j_;
+ this->n_ = that.n_;
+ this->subset1_ = that.subset1_;
+ this->subset2_ = that.subset2_;
+ this->ft_ = that.ft_;
+ this->fi_ = that.fi_;
+ this->fo_ = that.fo_;
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ template<typename It>
+ void partition<U,Ft,Fi,Fo>::initialize(int_ k,It b,It e)
+ {
+ BOOST_ASSERT(k>1);
+ typedef typename iterator_difference<It>::type diff_;
+ this->k_ = k;
+ this->j_ = -1;
+ diff_ d = std::distance( b, e);
+ if(d % this->k() != 0){
+ static const str_ msg
+ = str_("k_fold_estimate : distance(b,e)")
+ + "%1% not a multiple of k = %2%";
+ throw std::runtime_error( ( format(msg) % d % k ).str() );
+ }
+ this->n_ = d / this->k();
+
+ It i = boost::next( b, this->n() * (k-1) );
+ this->subset2_.clear();
+ this->subset2_.reserve(this->n());
+ std::copy(
+ i,
+ e,
+ std::back_inserter(this->subset2_)
+ );
+ this->subset1_.assign(
+ this->n() * (k-1),
+ b,
+ i
+ );
+ this->increment();
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ void partition<U,Ft,Fi,Fo>::initialize()
+ {
+ while(this->j()<this->k()){
+ this->increment();
+ }
+ this->j_ = 0;
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ void partition<U,Ft,Fi,Fo>::increment(){
+ static subset2_type tmp;
+ if( !( this->j()<this->k() ) )
+ {
+ static const char* msg = "partition: !j<k=%1%";
+ throw std::runtime_error(
+ ( format( msg ) % this->k() ).str()
+ );
+ }
+ tmp.clear();
+ std::copy(
+ boost::begin(this->subset1()),
+ boost::next(
+ boost::begin(this->subset1()),
+ this->n()
+ ),
+ std::back_inserter(tmp)
+ );
+ this->subset1_.insert(
+ boost::end( this->subset1_ ),
+ boost::begin( this->subset2() ),
+ boost::end( this->subset2() )
+ );
+ this->subset2_ = tmp;
+ ++this->j_;
+ }
+
+ // Access
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ const typename partition<U,Ft,Fi,Fo>::subset1_type&
+ partition<U,Ft,Fi,Fo>::subset1()const
+ {
+ return this->subset1_;
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ const typename partition<U,Ft,Fi,Fo>::subset2_type&
+ partition<U,Ft,Fi,Fo>::subset2()const
+ {
+ return this->subset2_;
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ typename partition<U,Ft,Fi,Fo>::meta_training_range::type
+ partition<U,Ft,Fi,Fo>::training_range()const
+ {
+ return meta_training_range::make(
+ this->ft_,
+ boost::begin(this->subset1()),
+ boost::end(this->subset1())
+ );
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ typename partition<U,Ft,Fi,Fo>::meta_input_range::type
+ partition<U,Ft,Fi,Fo>::input_range()const
+ {
+ return meta_input_range::make(
+ this->fi_,
+ boost::begin(this->subset2()),
+ boost::end(this->subset2())
+ );
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ typename partition<U,Ft,Fi,Fo>::meta_output_range::type
+ partition<U,Ft,Fi,Fo>::output_range()const
+ {
+ return meta_output_range::make(
+ this->fo_,
+ boost::begin(this->subset2()),
+ boost::end(this->subset2())
+ );
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ const typename partition<U,Ft,Fi,Fo>::int_&
+ partition<U,Ft,Fi,Fo>::n()const
+ {
+ return this->n_;
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ const typename partition<U,Ft,Fi,Fo>::int_&
+ partition<U,Ft,Fi,Fo>::j()const
+ {
+ return this->j_;
+ }
+
+ template<typename U,typename Ft,typename Fi,typename Fo>
+ const typename partition<U,Ft,Fi,Fo>::int_&
+ partition<U,Ft,Fi,Fo>::k()const
+ {
+ return this->k_;
+ }
+
+}// k_fold
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/train_predict.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/k_fold/train_predict.hpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,73 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::k_fold::train_predict.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_K_FOLD_TRAIN_PREDICT_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_K_FOLD_TRAIN_PREDICT_HPP_ER_2009
+#include <string>
+#include <stdexcept>
+#include <boost/concept/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/foreach.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/iterator/iterator_concepts.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/concept/predictor.hpp>
+#include <boost/statistics/detail/cross_validation/estimator/concept/trainer.hpp>
+#include <boost/statistics/detail/cross_validation/k_fold/partition.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace cross_validation{
+namespace k_fold{
+
+ template<
+ typename U,typename Ft,typename Fi,typename Fo,typename E,typename It
+ >
+ It train_predict(
+ partition<U,Ft,Fi,Fo>& kfp,
+ E estimator,
+ It out_iter
+ )
+ {
+ typedef partition<U,Ft,Fi,Fo> part_;
+ typedef typename part_::meta_training_range::type tr_;
+ typedef typename part_::meta_input_range::type ir_;
+ typedef typename range_value<ir_>::type i_;
+
+ BOOST_CONCEPT_ASSERT(( estimator::concept::Trainer<E,tr_> ));
+ BOOST_CONCEPT_ASSERT((
+ cross_validation::estimator::concept::Predictor<E,i_>
+ ));
+
+ // std::back_inserter cannot work
+ BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<It>));
+ BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<It>));
+
+ estimator.train( kfp.training_range() );
+
+ // typedef typename add_reference<i_>::type ref_i_;
+ typedef typename call_traits<i_>::param_type ref_i_;
+
+ BOOST_FOREACH(ref_i_ i, kfp.input_range())
+ {
+
+ *out_iter = estimator.predict(i);
+ ++out_iter;
+ }
+
+ return out_iter;
+ }
+
+}// k_fold
+}// cross_validation
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/doc/readme.txt 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,50 @@
+//////////////////////////////////////////////////////////////////////////////
+// goodness_of_fit::doc::readme //
+// //
+// (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) //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+C++ tools for cross validation.
+
+The data structure k_fold::partition keeps a dataset partitioned between train
+and test subset. The mf increment() changes the partition to the next of K
+partitions. Parameterized functors take care of extracting the training, input
+and output data.
+
+The function train_predict automates the task of producing estimates for each
+element of the test sample of a client supplied estimator.
+
+[ Compiler ]
+
+Mac OS Leopard 10.5 gcc version 4.0.1
+ Intel C++ compiler 11.1
+
+[ Dependencies ]
+
+/usr/local/boost_1_39_0/
+/sandbox/statistics/vector_space/
+/sandbox/statistics/mpl/
+
+[ History ]
+
+September 2009 - goodness_of_fit superseded by cross_validation with a better
+ interface.
+August 2009 - Creation of goodness_of_fit
+
+[ TODO ]
+
+Currently, k_fold_data makes a copy of a dataset. Intrusive or range
+(pair of iterator) alternatives may need to be considered.
+
+[ Sources ]
+
+http://en.wikipedia.org/wiki/Cross-validation_%28statistics%29

Added: sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.cpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,174 @@
+//////////////////////////////////////////////////////////////////////////////
+// cross_validation::example::k_fold.cpp //
+// //
+// (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) //
+//////////////////////////////////////////////////////////////////////////////
+#include <algorithm>
+#include <iterator>
+#include <boost/tuple/tuple.hpp>
+#include <boost/foreach.hpp>
+#include <boost/format.hpp>
+#include <boost/typeof/typeof.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#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>
+
+#include <boost/statistics/detail/cross_validation/estimator/adaptor/include.hpp>
+#include <boost/statistics/detail/cross_validation/k_fold/include.hpp>
+#include <boost/statistics/detail/cross_validation/error/include.hpp>
+
+#include <libs/statistics/detail/cross_validation/example/k_fold.h>
+
+void example_k_fold(std::ostream& os)
+{
+
+ os << "-> example_k_fold :" << std::endl;
+
+ // This example shows how to perform K train/predict cycles.
+ using namespace boost;
+ namespace stat = boost::statistics::detail;
+ namespace cv = stat::cross_validation;
+ namespace cv_es = cv::estimator;
+ namespace cv_ex = cv::extractor;
+ namespace cv_kf = cv::k_fold;
+
+ 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_;
+
+ // This comes up often, so this metafunction saves a bit of time
+ typedef accumulators::tag::mean tag_;
+ typedef accumulators::stats<
+ tag_
+ > stat_;
+ typedef accumulators::accumulator_set<val_,stat_> acc_;
+
+ typedef cv_es::adaptor::meta::nullary_predictor<acc_,tag_> meta_p_;
+ typedef cv_es::adaptor::joined<
+ cv_es::adaptor::unary_trainer,
+ meta_p_::apply,
+ acc_
+ > joined_;
+
+ typedef cv_kf::partition<val_,cv_ex::identity> kf_p_;
+
+ const unsigned n = 1e1;
+ const unsigned k = 5e0;
+ BOOST_ASSERT(n % k == 0);
+
+ vals_ vec_x;
+// dist_ dist;
+ nd_ nd;
+ urng_ urng;
+ vg_ vg(urng,nd);
+
+ std::generate_n(
+ std::back_inserter(vec_x),
+ n,
+ vg
+ );
+
+ kf_p_ kf_p(
+ k,
+ boost::begin(vec_x),
+ boost::end(vec_x)
+ );
+
+// os << kf_p;
+
+ struct float_{
+
+ static bool equal(const val_& a, const val_& b){
+ static val_ e = boost::math::tools::epsilon<val_>();;
+ return fabs(a-b)< e;
+ }
+
+ };
+
+ // Tests that concatenating the test-data over all k increments, is
+ // identical to vec_x.
+ for(unsigned i = 0; i<2; i++){
+ if(i>0){
+ // 2nd pass to check that resets properly
+ kf_p.initialize();
+ }
+
+ vals_it_ vec_x_it = boost::begin( vec_x );
+ while(kf_p.j()<kf_p.k()){
+ os << kf_p << std::endl;
+ BOOST_FOREACH(const val_& t,kf_p.subset2())
+ {
+ val_ t1 = *vec_x_it;
+ BOOST_ASSERT( float_::equal(t,t1) );
+ ++vec_x_it;
+ };
+ kf_p.increment();
+ }
+ }
+ kf_p.initialize();
+ os << std::endl;
+
+ vals_ est_vec_x(n);
+ vals_it_ est_vec_b = boost::begin(est_vec_x);
+ vals_it_ est_vec_e;
+ BOOST_ASSERT(n / k > 1);
+ while(kf_p.j()<kf_p.k()){
+ acc_ acc;
+ joined_ joined(acc);
+ est_vec_e = train_predict(
+ kf_p,
+ joined,
+ est_vec_b
+ );
+ val_ tmp = *est_vec_b;
+ BOOST_AUTO(
+ r,
+ make_iterator_range(boost::next(est_vec_b),est_vec_e)
+ );
+ BOOST_FOREACH(const val_& v, r)
+ {
+ // Because we use a nullary_estimator
+ // a.k.a. marginal estimator in statistical terminology.
+ BOOST_ASSERT(tmp == v);
+ }
+
+ val_ sqrt_mse = cv::error::sqrt_mse(
+ est_vec_b,
+ est_vec_e,
+ boost::begin(kf_p.output_range())
+ );
+
+ val_ mae = cv::error::mean_abs_error(
+ est_vec_b,
+ est_vec_e,
+ boost::begin(kf_p.output_range())
+ );
+
+ os << "sqrt_mse = " << sqrt_mse << std::endl;
+ os << "mae = " << mae << std::endl;
+
+ est_vec_b = est_vec_e;
+ kf_p.increment();
+ }
+
+ os << "<-" << std::endl;
+
+}
+
+

Added: sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/example/k_fold.h 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// statistics::goodness_of_fit::example::k_fold.h //
+// //
+// (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 LIBS_STATISTICS_DETAIL_CROSS_VALIDATION_EXAMPLE_K_FOLD_H_ER_2009
+#define LIBS_STATISTICS_DETAIL_CROSS_VALIDATION_EXAMPLE_K_FOLD_H_ER_2009
+#include <ostream>
+
+void example_k_fold(std::ostream&);
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/cross_validation/libs/statistics/detail/cross_validation/src/main.cpp 2009-09-29 19:09:47 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,18 @@
+//////////////////////////////////////////////////////////////////////////////
+// statistics::goodness_of_fit::src::main.cpp //
+// //
+// (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) //
+//////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <libs/statistics/detail/cross_validation/example/k_fold.h>
+
+int main()
+{
+
+ example_k_fold(std::cout);
+
+ 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