Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56646 - in sandbox/statistics/kernel: boost/statistics/detail/kernel boost/statistics/detail/kernel/bandwidth_selection boost/statistics/detail/kernel/bandwidth_selection/detail boost/statistics/detail/kernel/estimation boost/statistics/detail/kernel/estimation/detail boost/statistics/detail/kernel/kernels/multivariate boost/statistics/detail/kernel/kernels/scalar libs/statistics/detail/kernel/doc libs/statistics/detail/kernel/example libs/statistics/detail/kernel/src libs/statistics/detail/kernel/test
From: erwann.rogard_at_[hidden]
Date: 2009-10-07 22:53:38


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

Log:
m/d
Removed:
   sandbox/statistics/kernel/libs/statistics/detail/kernel/example/benchmark_scalar.cpp
   sandbox/statistics/kernel/libs/statistics/detail/kernel/example/benchmark_scalar.h
Text files modified:
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/detail/k_fold.hpp | 19 +--
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/include.hpp | 5
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/meta_k_fold_nw.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/normal_distribution.hpp | 4
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/nw_visitor_unary.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/estimator.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/include.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/meta_nw_visitor_unary.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/nw_visitor.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/rp_visitor.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/include.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/crtp.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/include.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/mono_bw.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/crtp.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp | 2
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/include.hpp | 2
   sandbox/statistics/kernel/libs/statistics/detail/kernel/doc/readme.txt | 33 ++-----
   sandbox/statistics/kernel/libs/statistics/detail/kernel/src/main.cpp | 7
   sandbox/statistics/kernel/libs/statistics/detail/kernel/test/scalar_nw.cpp | 163 ++++++++++++++++++++++++---------------
   sandbox/statistics/kernel/libs/statistics/detail/kernel/test/scalar_nw.h | 2
   22 files changed, 146 insertions(+), 117 deletions(-)

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/detail/k_fold.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/detail/k_fold.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/detail/k_fold.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 //////////////////////////////////////////////////////////////////////////////////////////
-// boost::statistics::detail::kernel::bandwidth_selection::detail::cross_validate.hpp //
+// kernel::bandwidth_selection::detail::cross_validate.hpp //
 // //
 // (C) Copyright 2009 Erwann Rogard //
 // Use, modification and distribution are subject to the //
@@ -34,12 +34,14 @@
     class k_fold :
         public cross_validation::k_fold::partition<U,Ft,Fi,Fo>
     {
+
         typedef cross_validation::k_fold::partition<U,Ft,Fi,Fo> kfp_;
         typedef typename kfp_::meta_training_range::type tr_;
         typedef estimator<tr_,V,K,A> est_t;
         typedef kfp_& rkfp_;
         
         public:
+ typedef kfp_ super_;
         typedef est_t estimator_type;
 
         // Constructor
@@ -61,14 +63,11 @@
 
         // Access
 
- const estimator_type& estimator()const{
- return this->est_;
- }
-
         // Cross validation
         
         template<typename T,typename It>
         It train_predict(
+ K k,
             It it_p // predicted values
         )
         {
@@ -76,7 +75,7 @@
         
             return cross_validation::k_fold::train_predict(
                 rkfp,
- this->est_,
+ est_t(k),
                 it_p
             );
         }
@@ -89,20 +88,16 @@
         ){
             rkfp_ rkfp = static_cast<rkfp_>(*this);
             
- this->k_ = k;
-
             return cross_validation::k_fold::cross_validate(
                 rkfp,
- this->est_,
+ est_t(k),
                 i_p,
                 i_o
             );
         }
     
- private:
- est_t est_;
-
     };
+
     
 }// detail
 }// bandwidth_selection

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/include.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/include.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/include.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::bandwidth::include.hpp //
+// kernel::bandwidth::include.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //
@@ -9,5 +9,8 @@
 #define BOOST_STATISTICS_DETAIL_KERNEL_BANDWIDTH_SELECTION_INCLUDE_H_ER_2009
 
 #include <boost/statistics/detail/kernel/bandwidth/normal_distribution.hpp>
+#include <boost/statistics/detail/kernel/bandwidth/meta_k_fold_nw.hpp>
+
+// TODO meta_k_fold_rp
 
 #endif

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/meta_k_fold_nw.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/meta_k_fold_nw.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/meta_k_fold_nw.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ////////////////////////////////////////////////////////////////////////////////
-// boost::statistics::detail::kernel::bandwidth_selection::meta_k_fold_nw.hpp //
+// kernel::bandwidth_selection::meta_k_fold_nw.hpp //
 // //
 // (C) Copyright 2009 Erwann Rogard //
 // Use, modification and distribution are subject to the //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/normal_distribution.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/normal_distribution.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/normal_distribution.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////////////
-// boost::statistics::detail::kernel::bandwidth_selection::normal_distribution.hpp //
+// kernel::bandwidth_selection::normal_distribution.hpp //
 // //
 // (C) Copyright 2009 Erwann Rogard //
 // Use, modification and distribution are subject to the //
@@ -19,7 +19,7 @@
 // Finds the optimal bandwidth for density estimation (Rosenblatt-Parzen)
 // assuming
 // 1) The data is a normal vector each coordinate having stddev sigma
-// 2) The kernel is Gaussian.
+// 2) The kernel is Gaussian with dimension M
 
 template<unsigned M, typename T>
 struct normal_distribution{

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::functional::detail::mean_accumulator.hpp //
+// kernel::functional::detail::mean_accumulator.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/nw_visitor_unary.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/nw_visitor_unary.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/nw_visitor_unary.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::functional::nw_visitor_unary.hpp //
+// kernel::functional::nw_visitor_unary.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/estimator.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/estimator.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/estimator.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::functional::rp_visitor.hpp //
+// kernel::functional::rp_visitor.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/include.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/include.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/include.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::estimation::include.hpp //
+// kernel::estimation::include.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/meta_nw_visitor_unary.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/meta_nw_visitor_unary.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/meta_nw_visitor_unary.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::functional::meta_nw_visitor_unary.hpp //
+// kernel::functional::meta_nw_visitor_unary.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/nw_visitor.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/nw_visitor.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/nw_visitor.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::functional::nw_visitor.hpp //
+// kernel::functional::nw_visitor.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/rp_visitor.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/rp_visitor.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/rp_visitor.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::functional::rp_visitor.hpp //
+// kernel::functional::rp_visitor.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/include.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/include.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/include.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::include.hpp //
+// kernel::include.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/crtp.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/crtp.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/crtp.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::multivariate::crtp.hpp //
+// kernel::multivariate::crtp.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/include.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/include.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/include.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::multivariate::include.hpp //
+// kernel::multivariate::include.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/mono_bw.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/mono_bw.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/mono_bw.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::multivariate::mono_bw.hpp //
+// kernel::multivariate::mono_bw.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/crtp.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/crtp.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/crtp.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::scalar::crtp.hpp //
+// kernel::scalar::crtp.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::scalar::gaussian.hpp //
+// kernel::scalar::gaussian.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/include.hpp
==============================================================================
--- sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/include.hpp (original)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/include.hpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::scalar::include.hpp //
+// kernel::scalar::include.hpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //

Modified: sandbox/statistics/kernel/libs/statistics/detail/kernel/doc/readme.txt
==============================================================================
--- sandbox/statistics/kernel/libs/statistics/detail/kernel/doc/readme.txt (original)
+++ sandbox/statistics/kernel/libs/statistics/detail/kernel/doc/readme.txt 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 //////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::doc::readme //
+// kernel::doc::readme //
 // //
 // (C) Copyright 2009 Erwann Rogard //
 // Use, modification and distribution are subject to the //
@@ -52,8 +52,8 @@
     - Replaced namespace statistics by statistics::detail
     - Finer directory structure
     - nw_visitor_tuple replaced by nw_visitor_unary which no longer constrains
- the training data to be a tuple (our preference is a fusion::map).
- - added cross_validation
+ the training data to be a tuple.
+ - Added cross_validation
 
 July 2009 : Creation
 March 2009: : improved_fast_gauss_transform (now deprecated)
@@ -127,26 +127,17 @@
     K[d,h](x) : exp(-||x/h||^2)/(c * h)^d
                         = Ku(||x||/h) / (c * h)^d
 
-[Output]
+[ main.cpp output ]
 
-Here's a copy of the output from libs/src/main.cpp:
-
--> example_scalar_rp : 0.256009 0.390986 0.229151 0.261866 0.232843 0.228334
-0.185519 0.382394 0.388576 0.383203 <-
+-> example_scalar_rp : <-
 -> example_scalar_nw : <-
 -> example_mono_bw_kernel_rp : <-
--> example_benchmark_scalar : m = 10000
-rp : (n, avg_t,e)nw : (n, avg_t,e_p,e_y)
-rp : (2, 4.0672e-06, 0.173297) nw : (2, 8.3822e-06, 0.173297, 1.2265)
-rp : (4, 2.859e-06, 0.138165) nw : (4, 5.86085e-06, 0.138165, 1.06847)
-rp : (8, 3.01747e-06, 0.104602) nw : (8, 6.289e-06, 0.104602, 0.831601)
-rp : (16, 3.96233e-06, 0.0978568) nw : (16, 8.16075e-06, 0.0978568, 0.702637)
-rp : (32, 5.94066e-06, 0.0818718) nw : (32, 1.20646e-05, 0.0818718, 0.595622)
-rp : (64, 9.40283e-06, 0.0719671) nw : (64, 1.95258e-05, 0.0719671, 0.531848)
-rp : (128, 1.57752e-05, 0.0634377) nw : (128, 3.26977e-05, 0.0634377, 0.477009)
-rp : (256, 2.72618e-05, 0.0565864) nw : (256, 5.64065e-05, 0.0565864, 0.432414)
-rp : (512, 4.81542e-05, 0.0511678) nw : (512, 0.00010056, 0.0511678, 0.398781)
-rp : (1024, 8.67954e-05, 0.0469132) nw : (1024, 0.000179972, 0.0469132, 0.371483)
+-> test_scalar_nw :
+((n_test,index,n_folds),bandwidth,sqrt_mse)
+(partition(10,10,10),0.668325,0.268464)
+(partition(100,10,10),0.421685,0.19132)
+(partition(1000,10,10),0.266065,0.0698525)
+(partition(10000,10,10),0.167876,0.0282646)
+(partition(100000,10,10),0.105922,0.0112862)
 <-
 
-

Deleted: sandbox/statistics/kernel/libs/statistics/detail/kernel/example/benchmark_scalar.cpp
==============================================================================
--- sandbox/statistics/kernel/libs/statistics/detail/kernel/example/benchmark_scalar.cpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
+++ (empty file)
@@ -1,273 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-// kernel::example::benchmark_scalar.cpp //
-// //
-// Copyright 2009 Erwann Rogard. Distributed under 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 <cmath>
-#include <vector>
-#include <algorithm>
-#include <iterator>
-#include <boost/function.hpp>
-#include <boost/range.hpp>
-#include <boost/foreach.hpp>
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/normal_distribution.hpp>
-#include <boost/random/variate_generator.hpp>
-#include <boost/math/special_functions/fpclassify.hpp> //needed?
-#include <boost/math/tools/precision.hpp>
-
-// Order of the files matters!
-#include <boost/statistics/detail/distribution_toolkit/distributions/normal.hpp>
-#include <boost/statistics/detail/distribution_toolkit/fwd_math/cdf.hpp>
-
-
-#include <boost/binary_op/data/tuple_range.hpp>
-
-#include <boost/statistics/detail/kernel/include.hpp>
-
-//#include <boost/statistics/detail/kernel/bandwidth/normal_distribution.hpp>
-//#include <boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp>
-//#include <boost/statistics/detail/kernel/estimation/nw_visitor_tuple.hpp>
-//#include <boost/statistics/detail/kernel/estimation/estimator.hpp>
-
-#include <boost/statistics/goodness_of_fit/include.hpp>
-
-#include <libs/statistics/detail/kernel/example/benchmark_scalar.h>
-
-void example_benchmark_scalar(std::ostream& out){
- out << "-> example_benchmark_scalar : ";
- out.flush();
-
- using namespace boost;
- namespace stat = statistics;
- namespace gof = stat::goodness_of_fit;
-
- // Types
- typedef double val_;
- typedef function<val_(const val_&)> y_fun_;
- typedef std::vector<val_> vals_;
- typedef std::vector<unsigned> uints_;
- typedef mt19937 urng_;
- typedef normal_distribution<val_> rnorm_;
- typedef variate_generator<urng_&,rnorm_> gen_;
- typedef statistics::detail::kernel::scalar::gaussian_kernel<val_> gauss_k_;
- typedef statistics::detail::kernel::rp_visitor<gauss_k_,val_> rp_visitor_;
- typedef math::normal_distribution<val_> mnorm_;
-
- // Constants
- const unsigned max_j = 5; // # partitions, k = 2^j
- const unsigned dim = 1;
- typedef statistics::detail::kernel::normal_distribution<dim,val_> opt_;
-
- const unsigned total_n = 1e4;
- const val_ mu = 0.0;
- const val_ sigma = 2.0;
-
- // Initialization
- y_fun_ y_fun = fabs;
-
- vals_ vec_x( total_n );
- vals_ vec_y( total_n );
- vals_ vec_pdf( total_n );
- urng_ urng;
- rnorm_ rnorm(mu,sigma);
- gen_ gen(urng,rnorm);
-
- { // Data generation
- mnorm_ mnorm(mu,sigma);
- generate_function_n<math::fun_wrap::pdf_>(
- boost::begin(vec_x),
- boost::begin(vec_pdf),
- total_n,
- mnorm,
- urng
- );
- transform(
- boost::begin(vec_x),
- boost::end(vec_x),
- boost::begin(vec_y),
- y_fun
- );
- }
- { // K-fold NW-estimation
- typedef binary_op::tuple_range<const vals_&,const vals_&>
- meta_range_xy_;
- typedef meta_range_xy_::type range_xy_;
- typedef range_value<range_xy_>::type xy_ref_cv_;
- typedef binary_op::tuple_remove_ref_cv<
- xy_ref_cv_
- >::type xy_;
-
- range_xy_ range_xy = meta_range_xy_::make(vec_x,vec_y);
- typedef gof::k_fold_data< xy_ > k_fold_;
- typedef k_fold_::range_train_data_type range_train_;
-
- typedef statistics::detail::kernel::estimator<
- range_train_,
- statistics::detail::kernel::nw_visitor_tuple,
- gauss_k_
- > estimator_;
-
- vals_ mse;
- vals_ mae;
- uints_ ns;
- vals_ bandwidths;
- vals_ vec_est_y( total_n );
- unsigned k = 1;
- for(unsigned j = 1; j<max_j; j++){
- k *= 2;
- k_fold_ k_fold(
- k,
- boost::begin(range_xy),
- boost::end(range_xy)
- );
- ns.push_back( k_fold.n() );
- // Warning: This bandwidth is not optimal for nw (but better than
- // a wild guess).
- bandwidths.push_back(
- opt_::rp_bandwidth(sigma, k_fold.n())
- );
- estimator_ e(
- bandwidths.back()
- );
- gof::regression_estimate(
- k_fold,
- e,
- boost::begin( vec_est_y )
- );
- mse.push_back(
- gof::sqrt_mse(
- boost::begin( vec_est_y ),
- boost::end( vec_est_y ),
- boost::begin( vec_y )
- )
- );
- mae.push_back(
- gof::mean_abs_error(
- boost::begin( vec_est_y ),
- boost::end( vec_est_y ),
- boost::begin( vec_y )
- )
- );
- }
-
- out << std::endl << "NW estimation";
- out << std::endl <<"bandwidth : ";
- std::copy(
- boost::rbegin( bandwidths ),
- boost::rend( bandwidths ),
- std::ostream_iterator<val_>(out," ")
- );
- out << std::endl <<"n : ";
- std::copy(
- boost::rbegin( ns ),
- boost::rend( ns ),
- std::ostream_iterator<val_>(out," ")
- );
- out << std::endl <<"sqrt_mse : ";
- std::copy(
- boost::rbegin( mse ),
- boost::rend( mse ),
- std::ostream_iterator<val_>(out," ")
- );
- out << std::endl <<"mae : ";
- std::copy(
- boost::rbegin( mae ),
- boost::rend( mae ),
- std::ostream_iterator<val_>(out," ")
- );
-
- }
- { // K-fold RP-estimation
-
- typedef gof::k_fold_data< val_ > k_fold_;
- typedef k_fold_::range_train_data_type range_train_;
-
- typedef statistics::detail::kernel::estimator<
- range_train_,
- statistics::detail::kernel::rp_visitor,
- gauss_k_
- > estimator_;
-
- vals_ mse;
- vals_ mae;
- uints_ ns;
- vals_ bandwidths;
- vals_ vec_est_pdf( total_n );
- unsigned k = 1;
- for(unsigned j = 1; j<max_j; j++){
- k *= 2;
- k_fold_ k_fold(
- k,
- boost::begin( vec_x ),
- boost::end( vec_x )
- );
- ns.push_back( k_fold.n() );
- // Note: This bandwidth is not optimal for density estimation
- // using a gaussian_kernel kernel, under normality of data
- bandwidths.push_back(
- opt_::rp_bandwidth(sigma, k_fold.n())
- );
- estimator_ e(
- bandwidths.back()
- );
- gof::marginal_estimate(
- k_fold,
- e,
- boost::begin( vec_est_pdf )
- );
- mse.push_back(
- gof::sqrt_mse(
- boost::begin( vec_est_pdf ),
- boost::end( vec_est_pdf ),
- boost::begin( vec_pdf )
- )
- );
- mae.push_back(
- gof::mean_abs_error(
- boost::begin( vec_est_pdf ),
- boost::end( vec_est_pdf ),
- boost::begin( vec_pdf )
- )
- );
- }
- out << std::endl << "RP estimation ";
- out << std::endl <<"bandwidth : ";
- std::copy(
- boost::rbegin( bandwidths ),
- boost::rend( bandwidths ),
- std::ostream_iterator<val_>(out," ")
- );
- out << std::endl <<"n : ";
- std::copy(
- boost::rbegin( ns ),
- boost::rend( ns ),
- std::ostream_iterator<val_>(out," ")
- );
- out << std::endl <<"sqrt_mse : ";
- std::copy(
- boost::rbegin( mse ),
- boost::rend( mse ),
- std::ostream_iterator<val_>(out," ")
- );
- out << std::endl <<"mae : ";
- std::copy(
- boost::rbegin( mae ),
- boost::rend( mae ),
- std::ostream_iterator<val_>(out," ")
- );
-
- }
- // DO the same for rp
-
- out << "<-" << std::endl;
-
-}
-*/
-
-
-

Deleted: sandbox/statistics/kernel/libs/statistics/detail/kernel/example/benchmark_scalar.h
==============================================================================
--- sandbox/statistics/kernel/libs/statistics/detail/kernel/example/benchmark_scalar.h 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
+++ (empty file)
@@ -1,14 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-// kernel::example::benchmark_scalar.h //
-// //
-// Copyright 2009 Erwann Rogard. Distributed under 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_KERNEL_EXAMPLE_BENCHMARK_SCALAR_H_ER_2009
-#define LIBS_STATISTICS_DETAIL_KERNEL_EXAMPLE_BENCHMARK_SCALAR_H_ER_2009
-#include <ostream>
-
-void example_benchmark_scalar(std::ostream&);
-
-#endif
\ No newline at end of file

Modified: sandbox/statistics/kernel/libs/statistics/detail/kernel/src/main.cpp
==============================================================================
--- sandbox/statistics/kernel/libs/statistics/detail/kernel/src/main.cpp (original)
+++ sandbox/statistics/kernel/libs/statistics/detail/kernel/src/main.cpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::src::main.cpp //
+// kernel::src::main.cpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //
@@ -9,7 +9,7 @@
 #include <libs/statistics/detail/kernel/example/scalar_rp.h>
 #include <libs/statistics/detail/kernel/example/scalar_nw.h>
 #include <libs/statistics/detail/kernel/example/mv_mono_bw_rp.h>
-#include <libs/statistics/detail/kernel/example/benchmark_scalar.h>
+#include <libs/statistics/detail/kernel/test/scalar_nw.h>
 
 
 int main(){
@@ -17,7 +17,8 @@
     example_scalar_rp(std::cout);
     example_scalar_nw(std::cout);
     example_mv_mono_bw_rp(std::cout);
- //example_benchmark_scalar(std::cout);
+
+ test_scalar_nw(std::cout);
     
     return 0;
 }
\ No newline at end of file

Modified: sandbox/statistics/kernel/libs/statistics/detail/kernel/test/scalar_nw.cpp
==============================================================================
--- sandbox/statistics/kernel/libs/statistics/detail/kernel/test/scalar_nw.cpp (original)
+++ sandbox/statistics/kernel/libs/statistics/detail/kernel/test/scalar_nw.cpp 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::test::scalar_nw.cpp //
+// kernel::test::scalar_nw.cpp //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //
@@ -13,15 +13,16 @@
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/random/normal_distribution.hpp>
 #include <boost/random/variate_generator.hpp>
-#include <boost/math/special_functions/fpclassify.hpp> //needed?
 #include <boost/math/tools/precision.hpp>
-#include <boost/typeof/typeof.hpp>
 
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
 #include <boost/lambda/construct.hpp>
 
 #include <boost/iterator/transform_iterator.hpp>
+#include <boost/iterator/counting_iterator.hpp>
+
+#include <boost/function.hpp>
 
 #include <boost/fusion/sequence/intrinsic/at_key.hpp>
 #include <boost/fusion/include/at_key.hpp>
@@ -30,98 +31,136 @@
 #include <boost/fusion/include/map_fwd.hpp>
 
 #include <boost/statistics/detail/fusion/functor/at_key.hpp>
+#include <boost/statistics/detail/cross_validation/error/sqrt_mse.hpp>
+#include <boost/statistics/detail/cross_validation/data/input_output_generator.hpp>
 
 #include <boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp>
+#include <boost/statistics/detail/kernel/bandwidth_selection/normal_distribution.hpp>
 #include <boost/statistics/detail/kernel/bandwidth_selection/meta_k_fold_nw.hpp>
+
 #include <libs/statistics/detail/kernel/test/scalar_nw.h>
 
-void test_scalar_nw(std::ostream& out){
+void test_scalar_nw(std::ostream& os){
+
+ os << "-> test_scalar_nw : " << std::endl;
+ os.flush();
+
+ // Runs K-fold cross-validation for a sequence of datasets of
+ // increasing size and reports the sqrt mse. Each data unit is
+ // of the form (x,f(y)).
 
- out << "-> test_scalar_nw : ";
     using namespace boost;
 
     namespace kernel = boost::statistics::detail::kernel;
+ namespace cv = boost::statistics::detail::cross_validation;
     
     // Types
     typedef double val_;
     typedef std::vector<val_> vals_;
- typedef mpl::int_<0> key_x_;
- typedef mpl::int_<1> key_y_;
- typedef fusion::pair<key_x_,val_> x_;
- typedef fusion::pair<key_y_,val_> y_;
+ typedef boost::function<val_(const val_&)> x_to_y_;
+ typedef cv::data::input_output_generator<
+ val_,
+ x_to_y_
+ > x_to_u_;
+ typedef x_to_u_::meta_input_output meta_io_;
+ typedef meta_io_::type u_; // data-unit
+ typedef meta_io_::input meta_x_;
+ typedef meta_io_::output meta_y_;
+ typedef meta_x_::key_type key_x_;
+ typedef meta_y_::key_type key_y_;
+ typedef meta_x_::data_type data_x_;
+ typedef meta_y_::data_type data_y_;
+
     typedef statistics::detail::fusion::functor::at_key<key_x_> at_key_x_;
     typedef statistics::detail::fusion::functor::at_key<key_y_> at_key_y_;
- typedef fusion::map<x_,y_> data_unit_;
- typedef std::vector<data_unit_> dataset_;
- // The rationale for data_range_ is it's cheap to copy
- typedef sub_range<dataset_> data_range_;
-
+
     typedef mt19937 urng_;
     typedef normal_distribution<val_> norm_;
     typedef variate_generator<urng_&,norm_> gen_;
     typedef kernel::scalar::gaussian_kernel<val_> gauss_k_;
+ typedef kernel::bandwidth_selection::normal_distribution<1,val_> bw_sel_;
     typedef kernel::bandwidth_selection::meta_k_fold_nw<
         at_key_x_,
         at_key_y_
> meta_k_fold_nw_;
     
     typedef meta_k_fold_nw_::apply<
- data_unit_,
+ u_,
         gauss_k_
>::type k_fold_nw_;
     
-
- // Constants
- const val_ bandwidth = 0.5;
- const val_ eps = math::tools::epsilon<val_>();
- const unsigned n = 10;
- const unsigned num_fold = 5;
-
+ typedef unsigned n_;
+
+ // num_fold * n_per_fold units at each iteration
+ n_ n_per_fold = 1;
+ const n_ n_folds = 10;
+ const n_ n_loops = 5;
+ const n_ n_factor = 10; // n_per_fold *= n_factor at each iteration
+
     // Initialization
- vals_ pred_nw_s(n);
- vals_ true_nw_s(n);
- dataset_ dataset;
- dataset.reserve(n);
-
- k_fold_nw_ k_fold_nw;
- {
- urng_ urng;
- norm_ norm;
- gen_ gen(urng,norm);
- val_ one = static_cast<val_>(1);
- for(unsigned i = 0; i<n; i++){
- dataset.push_back(
- data_unit_(
- fusion::make_pair<key_x_>(gen()),
- fusion::make_pair<key_y_>(one)
- )
- );
- }
- BOOST_AUTO(
- f,
- boost::lambda::bind(
- boost::lambda::constructor<data_unit_>(),
- boost::lambda::bind(
- boost::lambda::constructor<x_>(),
- boost::lambda::bind(
- gen
- )
- ),
- fusion::make_pair<key_y_>(one)
+ vals_ pred_nw_s;
+ vals_ true_nw_s;
+
+ urng_ urng;
+ norm_ norm;
+ gen_ gen(urng,norm);
+
+ typedef function<u_(const n_&)> index_to_u_;
+
+ x_to_y_ x_to_y =
+ boost::lambda::_1 * boost::lambda::_1;
+
+ index_to_u_ index_to_u = boost::lambda::bind(
+ x_to_u_(x_to_y),
+ boost::lambda::bind(
+ boost::ref(gen)
+ )
+ );
+
+ os << '(' << k_fold_nw_::description_header
+ << ',' << "bandwidth"
+ << ',' << "sqrt_mse"
+ << ')' << std::endl;
+
+ for(n_ i = 0; i<n_loops; i++){
+ n_ n = n_per_fold * n_folds;
+ pred_nw_s.resize( n );
+ true_nw_s.resize( n );
+
+ k_fold_nw_ k_fold_nw(
+ n_folds,
+ make_transform_iterator(
+ make_counting_iterator<n_>(0),
+ index_to_u
+ ),
+ make_transform_iterator(
+ make_counting_iterator<n_>(n),
+ index_to_u
             )
         );
         
-
- }
-
-
- //k_fold_nw_ k_fold_nw(
- // num_fold,
- // make_transform_iterator
- //);
+ // This bandwidth is not optimal for rp, not nw, but it should not
+ // matter too much
+ val_ bandwidth = bw_sel_::rp_bandwidth(n);
+ k_fold_nw.cross_validate(
+ bandwidth,
+ boost::begin(pred_nw_s),
+ boost::begin(true_nw_s)
+ );
 
-
+ val_ smse = cv::error::sqrt_mse(
+ boost::begin(pred_nw_s),
+ boost::end(pred_nw_s),
+ boost::begin(true_nw_s)
+ );
 
+ os << '(' << k_fold_nw
+ << ',' << bandwidth
+ << ',' << smse
+ << ')' << std::endl;
+
+ n_per_fold *= n_factor;
+ }
 
- out << "<-" << std::endl;
+ os << "<-" << std::endl;
 }
\ No newline at end of file

Modified: sandbox/statistics/kernel/libs/statistics/detail/kernel/test/scalar_nw.h
==============================================================================
--- sandbox/statistics/kernel/libs/statistics/detail/kernel/test/scalar_nw.h (original)
+++ sandbox/statistics/kernel/libs/statistics/detail/kernel/test/scalar_nw.h 2009-10-07 22:53:35 EDT (Wed, 07 Oct 2009)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// statistics::detail::kernel::test::scalar_nw.h //
+// kernel::test::scalar_nw.h //
 // //
 // Copyright 2009 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying 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