$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r56585 - in sandbox/statistics/kernel/boost/statistics/detail: . kernel kernel/bandwidth_selection kernel/bandwidth_selection/detail kernel/estimation kernel/estimation/detail kernel/kernels kernel/kernels/multivariate kernel/kernels/scalar
From: erwann.rogard_at_[hidden]
Date: 2009-10-04 18:54:21
Author: e_r
Date: 2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
New Revision: 56585
URL: http://svn.boost.org/trac/boost/changeset/56585
Log:
a
Added:
   sandbox/statistics/kernel/boost/statistics/detail/
   sandbox/statistics/kernel/boost/statistics/detail/kernel/
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/detail/
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/detail/k_fold.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/include.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/meta_k_fold_nw.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/normal_distribution.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/nw_visitor_unary.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/estimator.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/include.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/meta_nw_visitor_unary.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/nw_visitor.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/rp_visitor.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/include.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/crtp.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/include.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/mono_bw.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/crtp.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/include.hpp   (contents, props changed)
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/detail/k_fold.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/detail/k_fold.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,114 @@
+//////////////////////////////////////////////////////////////////////////////////////////
+// boost::statistics::detail::kernel::bandwidth_selection::detail::cross_validate.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_KERNEL_BANDWIDTH_SELECTION_DETAIL_K_FOLD_HPP_ER_2009           
+#define BOOST_STATISTICS_DETAIL_KERNEL_BANDWIDTH_SELECTION_DETAIL_K_FOLD_HPP_ER_2009
+#include <boost/statistics/detail/kernel/estimation/estimator.hpp>
+#include <boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp>
+#include <boost/statistics/detail/cross_validation/k_fold/partition.hpp>
+#include <boost/statistics/detail/cross_validation/k_fold/cross_validate.hpp>
+#include <boost/statistics/detail/cross_validation/k_fold/train_predict.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+namespace bandwidth_selection{
+namespace detail{
+
+    template<
+        typename U, // data-unit 
+        template<typename,typename,typename> class V,
+        typename K,
+        typename Ft,
+        typename Fi,
+        typename Fo,
+        typename A = typename 
+            kernel::detail::mean_accumulator<typename K::result_type>::type
+    >
+    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 est_t estimator_type;
+
+        // Constructor
+        k_fold(){}
+        template<typename It>
+        k_fold(
+            unsigned num_folds, 
+            It b,   //dataset
+            It e
+        ):kfp_(
+            num_folds,
+            b,e
+        ){
+            // Default constructs estimator
+        }
+
+        // TODO create a constructor with argument pack (overloading constr
+        // uctor would be cumbersome)
+
+        // Access
+
+        const estimator_type& estimator()const{ 
+            return this->est_;
+        }
+
+        // Cross validation
+        
+        template<typename T,typename It>
+        It train_predict(
+            It  it_p // predicted values
+        )
+        {
+            rkfp_ rkfp = static_cast<rkfp_>(*this);
+        
+            return cross_validation::k_fold::train_predict(
+                rkfp,
+                this->est_,
+                it_p
+            );
+        }
+
+        template<typename It,typename It1>
+        It cross_validate(
+            K k,
+            It i_p,     // predicted values
+            It1 i_o    // true values
+        ){
+            rkfp_ rkfp = static_cast<rkfp_>(*this);
+            
+            this->k_ = k;
+            
+            return cross_validation::k_fold::cross_validate(
+                rkfp,
+                this->est_,
+                i_p,
+                i_o
+            );
+        }
+    
+        private:
+        est_t est_;
+    
+    };
+    
+}// detail
+}// bandwidth_selection
+}// kernel
+}// detail
+}// statistics
+}// boost   
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/include.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,13 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::bandwidth::include.hpp                        //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_BANDWIDTH_SELECTION_INCLUDE_H_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_BANDWIDTH_SELECTION_INCLUDE_H_ER_2009
+
+#include <boost/statistics/detail/kernel/bandwidth/normal_distribution.hpp>
+
+#endif
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/meta_k_fold_nw.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/meta_k_fold_nw.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,60 @@
+////////////////////////////////////////////////////////////////////////////////
+// boost::statistics::detail::kernel::bandwidth_selection::meta_k_fold_nw.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_KERNEL_BANDWIDTH_SELECTION_META_K_FOLD_NW_HPP_ER_2009           
+#define BOOST_STATISTICS_DETAIL_KERNEL_BANDWIDTH_SELECTION_META_K_FOLD_NW_HPP_ER_2009
+#include <boost/statistics/detail/kernel/bandwidth_selection/detail/k_fold.hpp>
+#include <boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp>
+#include <boost/statistics/detail/kernel/estimation/meta_nw_visitor_unary.hpp>
+#include <boost/statistics/detail/cross_validation/extractor/identity.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+namespace bandwidth_selection{
+
+template<
+    typename F1,    // x extractor
+    typename F2     // y extractor
+>
+struct meta_k_fold_nw
+{
+
+    typedef meta_nw_visitor_unary<F1,F2> meta_;
+
+    // ft(u) has to return a training data. Here, ft(u) = (x,y),
+    // f1((x,y))=x, f2((x,y)) = y
+    
+    template<
+        typename U, // data-unit 
+        typename K,
+        typename Ft = cross_validation::extractor::identity,
+        typename A = typename 
+            kernel::detail::mean_accumulator<
+                typename K::result_type>::type
+    >
+    struct apply{
+        typedef bandwidth_selection::detail::k_fold<
+            U,
+            meta_::template apply,
+            K,
+            Ft,F1,F2
+        > type;
+    };
+
+};
+    
+}// bandwidth_selection
+}// kernel
+}// detail
+}// statistics
+}// boost   
+
+#endif
+
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/normal_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/bandwidth_selection/normal_distribution.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,52 @@
+/////////////////////////////////////////////////////////////////////////////////////
+// boost::statistics::detail::kernel::bandwidth_selection::normal_distribution.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_KERNEL_BANDWIDTH_SELECTION_NORMAL_DISRTIBUTION_HPP_ER_2009           
+#define BOOST_STATISTICS_DETAIL_KERNEL_BANDWIDTH_SELECTION_NORMAL_DISRTIBUTION_HPP_ER_2009
+#include <cmath>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+namespace bandwidth_selection{
+
+// 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.
+
+template<unsigned M, typename T>
+struct normal_distribution{
+    typedef T value_type;
+    static value_type rp_bandwidth(std::size_t n); // Assumes sigma = 1
+    static value_type rp_bandwidth(value_type sigma,unsigned n);
+    // For M == 1, bandwdith = sigma (3n/4)^(-1/5) = 1.06 sigma n^(-1/5)
+};
+template<unsigned M, typename T>
+typename normal_distribution<M,T>::value_type
+normal_distribution<M,T>::rp_bandwidth(std::size_t n){
+    static const value_type e = -static_cast<T>(1)/static_cast<T>(M+4);
+    static const value_type r = static_cast<T>(2+M)/ static_cast<T>(4);
+    value_type a =  static_cast<T>(n) * r;
+    return std::pow( a, e );
+}
+
+template<unsigned M, typename T>
+typename normal_distribution<M,T>::value_type
+normal_distribution<M,T>::rp_bandwidth(value_type sigma,unsigned n){
+    return sigma * rp_bandwidth(n);
+}
+
+}// bandwidth_selection
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,35 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::functional::detail::mean_accumulator.hpp      //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_DETAIL_MEAN_ACCUMULATOR_H_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_DETAIL_MEAN_ACCUMULATOR_H_ER_2009
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+namespace detail{
+
+    // The Rosenblatt-Parzen estimator is a density estimator
+    template<typename T>
+    struct mean_accumulator{
+        typedef accumulators::stats<
+            accumulators::tag::mean
+        >  stat_;
+        typedef accumulators::accumulator_set<T,stat_> type;
+    };
+        
+}// detail
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/nw_visitor_unary.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/detail/nw_visitor_unary.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,113 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::functional::nw_visitor_unary.hpp              //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_DETAIL_NW_VISITOR_UNARY_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_DETAIL_NW_VISITOR_UNARY_HPP_ER_2009
+#include <boost/type_traits.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp>
+#include <boost/statistics/detail/kernel/estimation/nw_visitor.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/concept/assert.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+namespace detail{
+
+// This visitor, g, when called as g(t), forwards to f(f1(t),f2(t)), where f
+// is an instance of nw_visitor, and f1(t) and f2(t) are the x and y components.
+//
+// K, X, A: See rp_visitor
+template<
+    typename K,
+    typename X,
+    typename F1,    // x extractor
+    typename F2,    // y extractor
+    typename A = typename 
+        statistics::detail::kernel::detail::mean_accumulator<
+            typename K::result_type
+        >::type 
+>
+class nw_visitor_unary : public nw_visitor<K,X,A>{
+    typedef nw_visitor<K,X,A> super_;
+    
+    public:
+    typedef F1 input_extractor_type;
+    typedef F2 output_extractor_type;
+    
+    typedef super_ nw_visitor_type;
+    typedef typename super_::result_type result_type;
+
+    // Construction
+    nw_visitor_unary(){}
+    nw_visitor_unary(
+        K k,
+        typename call_traits<X>::param_type x
+    ):super_(k,x){
+        BOOST_CONCEPT_ASSERT((
+            boost::DefaultConstructible<F1>
+        ));
+        BOOST_CONCEPT_ASSERT((
+            boost::DefaultConstructible<F2>
+        ));
+    }
+    nw_visitor_unary(
+        K k,
+        typename call_traits<X>::param_type x,
+        const A& a
+    ):super_(k,x,a)
+    {
+        BOOST_CONCEPT_ASSERT((
+            boost::DefaultConstructible<F1>
+        ));
+        BOOST_CONCEPT_ASSERT((
+            boost::DefaultConstructible<F2>
+        ));
+    }
+        
+    nw_visitor_unary(const nw_visitor_unary& that)
+    :super_(that),f1_(that.f1_),f2_(that.f2_){}
+    
+    nw_visitor_unary& operator=(const nw_visitor_unary& that)
+    {
+        if(&that!=this){
+            super_::operator=(that);
+            this->f1_ = that.f1_;
+            this->f2_ = that.f2_;
+        }
+        return *this;
+    }
+
+        
+    // Update
+    template<typename T>
+    result_type operator()(const T& t)
+    {
+        const F1& crf1 = this->f1_;
+        const F2& crf2 = this->f2_;
+        return static_cast<super_&>(*this)( 
+            crf1(t),
+            crf2(t)
+        );
+    }
+
+    private:
+    F1 f1_;
+    F2 f2_;
+
+};
+
+}// detail
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/estimator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/estimator.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,133 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::functional::rp_visitor.hpp                    //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_DENSITY_VISITOR_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_DENSITY_VISITOR_HPP_ER_2009
+#include <algorithm>
+#include <boost/concept/assert.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/type_traits/is_reference.hpp>
+#include  <boost/type_traits/is_convertible.hpp>
+#include <boost/mpl/nested_type.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+
+    // A type that models Trainer and Predictor
+    // See https://svn.boost.org/svn/boost/sandbox/statistics/cross_validation/boost/statistics/detail/cross_validation/estimator/concept/ 
+    //
+    // R:   range of a data range 
+    // V:   visitor 
+    // K:   kernel
+    // A:   accumulator
+    //
+    // V                                      ->     data range of type R
+    // rp_visitor                             ->     {x[i]:i=1,...,n}
+    // meta_nw_visitor_unary<F1,F2>::apply    ->     {(x,y)[i]:i=1,...,n}
+    //
+    // It is recommended that R derives from iterator_range because it is cheap
+    // to copy.
+    template<
+        typename R, 
+        template<typename,typename,typename> class V,
+        typename K,
+        typename A = typename 
+            detail::mean_accumulator<typename K::result_type>::type 
+    >
+    class estimator{
+    
+        public:
+        typedef R training_dataset_type;
+        typedef K kernel_type;
+        typedef A accumulator_type;
+
+        template<typename X>
+        struct visitor
+        {
+            typedef V<K,const X&,A> arg_;
+            typedef typename mpl::nested_type<arg_>::type type;
+        };
+
+        template<typename X>
+        struct result_of_predict
+        {
+            typedef typename visitor<X>::type v_;
+            typedef typename v_::result_type type;
+        };
+    
+        // Constructor
+        estimator(){}
+        estimator(K k)
+            :k_(k){}
+        estimator(K k,const A& a)
+            :k_(k),a_(a){}
+        estimator(const estimator& that)
+            :td_(that.td_),k_(that.k_),a_(that.a_){}
+        estimator& operator=(const estimator& that){
+            if(&that = this){
+                this->td_ = that.td_;
+                this->k_ = that.k_;
+                this->a_ = that.a_;
+            }
+            return *this;
+        }
+    
+        // Access
+        const R& training_dataset()const{
+            return this->td_;
+        }
+        const K& kernel()const{
+            return this->k_; 
+        }
+        const A& accumulator()const{
+            return this->a_;
+        }
+
+        void train(const R& training_dataset){
+            BOOST_CONCEPT_ASSERT((
+                boost::Assignable<R>
+            ));
+            this->td_ = training_dataset;
+        }
+
+        template<typename X> 
+        typename visitor<X>::type 
+        visit(const X& x)const{
+            typedef estimator this_type;
+            typedef typename visitor<X>::type v_;
+    
+            return std::for_each(
+                boost::begin( this->training_dataset() ),
+                boost::end( this->training_dataset() ),
+                v_( this->kernel(), x, this->a_)
+            );
+        }
+        
+        template<typename X> 
+        typename result_of_predict<X>::type 
+        predict(const X& x)const{
+            return visit(x).estimate();
+        }
+
+    protected:
+        R td_;
+        K k_;
+        A a_; // Initialized accumulator 
+    };
+
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/include.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,16 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::estimation::include.hpp                       //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_INCLUDE_H_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_INCLUDE_H_ER_2009
+
+#include <boost/statistics/detail/kernel/estimation/estimator.hpp>
+#include <boost/statistics/detail/kernel/estimation/nw_visitor.hpp>
+#include <boost/statistics/detail/kernel/estimation/meta_nw_visitor_unary.hpp>
+#include <boost/statistics/detail/kernel/estimation/rp_visitor.hpp>
+
+#endif
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/meta_nw_visitor_unary.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/meta_nw_visitor_unary.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,44 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::functional::meta_nw_visitor_unary.hpp         //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_META_NW_VISITOR_UNARY_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_META_NW_VISITOR_UNARY_HPP_ER_2009
+#include <boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp>
+#include <boost/statistics/detail/kernel/estimation/detail/nw_visitor_unary.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+
+// meta_visitor_unary<F1,F2>::apply is a valid template argument to estimator
+// See detail/nw_visitor_unary
+template<
+    typename F1,    // x extractor
+    typename F2
+>
+struct meta_nw_visitor_unary
+{
+    
+     template<
+        typename K,
+        typename X,
+        typename A = typename statistics::detail::kernel::detail::mean_accumulator<
+            typename K::result_type
+        >::type 
+    >
+     struct apply{
+       typedef detail::nw_visitor_unary<K,X,F1,F2,A> type;
+    };
+};
+
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/nw_visitor.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/nw_visitor.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,146 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::functional::nw_visitor.hpp                    //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_NW_VISITOR_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_NW_VISITOR_HPP_ER_2009
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp>
+#include <boost/statistics/detail/kernel/estimation/rp_visitor.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+   
+// This visitor, f, updates a Nadaraya-Watson estimate of E[Y|X=x0] each
+// time f(x,y) is called. 
+//
+// K,X,A : See rp_visitor 
+template<
+    typename K,
+    typename X,
+    typename A = typename 
+        statistics::detail::kernel::detail::mean_accumulator<typename K::result_type>::type 
+>
+class nw_visitor{
+    public:
+    typedef rp_visitor<K,X,A> rp_visitor_type;
+    typedef typename rp_visitor_type::result_type result_type;
+    typedef K kernel_type;
+    typedef A accumulator_type;
+        
+    //Construct
+    nw_visitor();
+    nw_visitor(typename call_traits<X>::param_type);
+    nw_visitor(
+        K k, // passing radius should call implicit conversion
+        typename call_traits<X>::param_type x  
+    );
+    nw_visitor(
+        K k,
+        typename call_traits<X>::param_type,
+        const accumulator_type&
+    );
+    nw_visitor(const nw_visitor&);
+    nw_visitor& operator=(const nw_visitor&);
+        
+    // Update
+    protected:
+    template<typename X1,typename Y1> // Training data point
+    result_type operator()(const X1& x1,const Y1& y1);
+
+    public:
+    // Access
+    result_type unnormalized_estimate()const;
+    result_type normalizing_constant()const;
+    result_type estimate()const; 
+
+    
+    const A& accumulator()const;
+    const rp_visitor_type& rp_visitor()const;
+        
+    private:
+    rp_visitor_type rp_visitor_;
+    A a_;
+};
+    
+//Construction
+template<typename K,typename X,typename A>
+nw_visitor<K,X,A>::nw_visitor():rp_visitor_(),a_(){}
+    
+template<typename K,typename X,typename A>
+nw_visitor<K,X,A>::nw_visitor(K k,typename call_traits<X>::param_type x)
+:rp_visitor_(k,x),a_(){}
+    
+template<typename K,typename X,typename A>
+nw_visitor<K,X,A>::nw_visitor(
+    K k,typename call_traits<X>::param_type x,const A& a
+):rp_visitor_(k,x,a),a_(a){}
+    
+template<typename K,typename X,typename A>
+nw_visitor<K,X,A>::nw_visitor(const nw_visitor& that)
+:rp_visitor_(that.rp_visitor_),a_(that.a_){}
+    
+template<typename K,typename X,typename A>
+typename nw_visitor<K,X,A>::nw_visitor& 
+nw_visitor<K,X,A>::operator=(const nw_visitor& that){
+    if(&that!=this){
+        rp_visitor_ = that.rp_visitor_;
+        a_ = that.a_;
+    }   
+    return *this;
+}
+    
+// Update
+template<typename K,typename X,typename A>
+template<typename X1,typename Y1>
+typename nw_visitor<K,X,A>::result_type
+nw_visitor<K,X,A>::operator()(const X1& x1,const Y1& y){
+    result_type w = (this->rp_visitor_(x1));
+    result_type wy = w * y; 
+    this->a_(wy);
+    return wy;
+}
+
+// Access
+template<typename K,typename X,typename A>
+typename nw_visitor<K,X,A>::result_type
+nw_visitor<K,X,A>::unnormalized_estimate()const{
+    return accumulators::mean(
+        this->accumulator()
+    );
+}
+
+template<typename K,typename X,typename A>
+typename nw_visitor<K,X,A>::result_type
+nw_visitor<K,X,A>::normalizing_constant()const{
+    return (this->rp_visitor_).estimate();
+}
+    
+template<typename K,typename X,typename A>
+typename nw_visitor<K,X,A>::result_type
+nw_visitor<K,X,A>::estimate()const{
+    return (this->unnormalized_estimate()/this->normalizing_constant());
+}
+    
+template<typename K,typename X,typename A>
+const A& nw_visitor<K,X,A>::accumulator()const{ return  this->a_; }
+        
+template<typename K,typename X,typename A>
+const rp_visitor<K,X,A>& 
+nw_visitor<K,X,A>::rp_visitor()const{
+    return (this->rp_visitor_);
+}
+    
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/rp_visitor.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/estimation/rp_visitor.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,156 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::functional::rp_visitor.hpp                    //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_RP_VISITOR_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_ESTIMATION_RP_VISITOR_HPP_ER_2009
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/statistics/detail/kernel/estimation/detail/mean_accumulator.hpp>
+//#include <boost/statistics/detail/kernel/estimation/detail/return_if.hpp>
+//#include <boost/statistics/detail/kernel/estimation/detail/range_difference.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+
+// This visitor, f, keeps a data point, x0, and each time f(x) is called, it 
+// updates an estimate of the density at x0, p(x0), by the Rosenblatt-Parzen 
+// method, using a given kernel k.
+//
+// The estimate is the average of the kernel evaluations over the traversed 
+// dataset. That average is implemented by an accumulator of type A.
+//
+// X can be a reference which is only recommended if the x object is expensive 
+// to copy
+template<
+    typename K,
+    typename X,
+    typename A = typename 
+        statistics::detail::kernel::detail::mean_accumulator<typename K::result_type>::type 
+>
+class rp_visitor : K{ //, addable<rp_visitor<K,X,A> >{ // 
+    typedef is_reference<X> is_ref_;
+    public:
+    typedef K kernel_type;
+    typedef A accumulator_type;
+    typedef typename K::result_type result_type;
+
+    // Construct
+    rp_visitor();
+    rp_visitor(typename call_traits<X>::param_type);
+    rp_visitor(
+        K k, // passing radius calls implicit conversion
+        typename call_traits<X>::param_type x
+    );
+    rp_visitor(
+        K k,
+        typename call_traits<X>::param_type,
+        const accumulator_type&
+    );
+    rp_visitor(const rp_visitor&);
+    rp_visitor& operator=(const rp_visitor&);
+    
+    // Update
+    // Passing the training data x1 updates the estimator
+    template<typename X1> result_type operator()(const X1& x1);
+    
+    // Access
+    typename call_traits<X>::const_reference x()const;
+    const A& accumulator()const;
+    const result_type& normalizing_constant()const;
+
+    result_type estimate()const; 
+
+    private:
+    typename call_traits<X>::value_type x_;
+    A acc_;
+};
+
+//Construction
+template<typename K,typename X,typename A>
+rp_visitor<K,X,A>::rp_visitor(){
+    BOOST_MPL_ASSERT((
+        mpl::not_<is_ref_>
+    ));
+}
+
+template<typename K,typename X,typename A>
+rp_visitor<K,X,A>::rp_visitor(K k,typename call_traits<X>::param_type x)
+:K(k),x_(x),acc_(){}
+    
+template<typename K,typename X,typename A>
+rp_visitor<K,X,A>::rp_visitor(
+    K k,
+    typename call_traits<X>::param_type x,
+    const A& a
+):K(k),x_(x),acc_(a){}
+
+template<typename K,typename X,typename A>
+rp_visitor<K,X,A>::rp_visitor(const rp_visitor& that)
+:K(static_cast<const K&>(that)),x_(that.x_),acc_(that.acc_){}
+
+template<typename K,typename X,typename A>
+typename rp_visitor<K,X,A>::rp_visitor& 
+rp_visitor<K,X,A>::operator=(const rp_visitor& that){
+    if(&that!=this){
+        BOOST_MPL_ASSERT((mpl::not_<is_ref_>));
+        K::operator=(static_cast<const K&>(*that)); 
+        x_ = that.x_;
+        acc_ = that.acc_;
+    }   
+    return *this;
+}
+
+// Evaluate
+template<typename K,typename X,typename A>
+template<typename X1>
+typename rp_visitor<K,X,A>::result_type
+rp_visitor<K,X,A>::operator()(const X1& x1){
+    const K& kernel = static_cast<const K&>(*this);
+    result_type t = kernel(x(),x1);
+    this->acc_(t);
+    return t;
+}
+
+
+// Access
+template<typename K,typename X,typename A>
+typename rp_visitor<K,X,A>::result_type
+rp_visitor<K,X,A>::estimate()const{
+    return accumulators::mean(
+        this->accumulator()
+    );
+}
+
+template<typename K,typename X,typename A>
+const A&
+rp_visitor<K,X,A>::accumulator()const{
+    return  this->acc_;
+}
+    
+template<typename K,typename X,typename A>
+const typename rp_visitor<K,X,A>::result_type&
+rp_visitor<K,X,A>::normalizing_constant()const{
+    const K& k = static_cast<const K&>(*this);
+    return k.normalizing_constant();
+}
+
+template<typename K,typename X,typename A>
+typename call_traits<X>::const_reference
+rp_visitor<K,X,A>::x()const{
+    return this->x_;
+}
+    
+
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/include.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,16 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::include.hpp                                   //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/detail/kernel/bandwidth/include.hpp>
+#include <boost/statistics/detail/kernel/estimation/include.hpp>
+#include <boost/statistics/detail/kernel/kernels/multivariate/include.hpp>
+#include <boost/statistics/detail/kernel/kernels/scalar/include.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/crtp.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/crtp.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::multivariate::crtp.hpp                        //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_MULTIVARIATE_CRTP_H_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_MULTIVARIATE_CRTP_H_ER_2009
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+namespace multivariate{
+
+    // This has no purpose other signifying that the derived class is 
+    // a kernel, and it is currently not in use, but this may change. 
+    template<typename D> struct crtp{};
+
+}// multivariate
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/include.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::multivariate::include.hpp                     //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_MULTIVARIATE_INCLUDE_H_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_MULTIVARIATE_INCLUDE_H_ER_2009
+
+#include <boost/statistics/detail/kernel/kernels/multivariate/crtp.hpp>
+#include <boost/statistics/detail/kernel/kernels/multivariate/mono_bw.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/mono_bw.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/multivariate/mono_bw.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,129 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::multivariate::mono_bw.hpp                     //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICEMSE_1_0.txt or copy at http://www.boost.org/LICEMSE_1_0.txt)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#ifndef BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_MULTIVARIATE_MONO_BW_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_MULTIVARIATE_MONO_BW_HPP_ER_2009
+#include <cmath>
+#include <numeric>
+#include <boost/lambda/lambda.hpp>
+#include <boost/vector_space/data/lazy_difference.hpp>
+#include <boost/statistics/detail/kernel/kernels/multivariate/crtp.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+namespace multivariate{
+
+// Overview: Multivariate kernel, common bandwidth across coordinates.
+//
+// Notation: Let x denote a vector of size M,
+//
+// Usage:
+// typedef mono_bw_kernel<scalar::gaussian_kernel<T>,M> mult_;
+// typedef mult_::result_type result_;
+// mult_ mult(bandwidth);
+// result_ r = mult(x);
+template<typename K,unsigned M>
+class mono_bw_kernel : K{
+    public:
+    typedef typename K::result_type result_type;
+
+    //Construction
+    mono_bw_kernel();
+    template<typename K1> mono_bw_kernel(K1 k1); //pass bandwith, or kernel
+    
+    // Evaluate
+    template<typename X> result_type profile(const X& x)const;    
+    template<typename X> result_type operator()(const X& x)const;    
+    template<typename X,typename X1> 
+    result_type operator()(const X& x,const X1& x1)const;
+    
+    // Access
+    static unsigned dimension;
+    result_type radius()const;
+    result_type normalizing_constant()const;
+    
+    private:
+    result_type normalizing_constant_; //no ambiguity because inherit K privately
+    result_type comp_nc()const; 
+};
+
+// Construction
+template<typename K,unsigned M> 
+mono_bw_kernel<K,M>::mono_bw_kernel():K(),normalizing_constant_(comp_nc()){}
+
+template<typename K,unsigned M> 
+template<typename K1>
+mono_bw_kernel<K,M>::mono_bw_kernel(K1 k1):K(k1),normalizing_constant_(comp_nc()){}
+        
+// Evaluate
+template<typename K,unsigned M> 
+template<typename X> 
+typename mono_bw_kernel<K,M>::result_type 
+mono_bw_kernel<K,M>::profile(const X& x)const{
+    static result_type init = static_cast<result_type>(0);
+    const K& k = static_cast<const K&>(*this);
+    result_type norm = std::accumulate(
+        boost::begin(x),
+        boost::end(x),
+        init,
+        ( lambda::_1 + (lambda::_2 * lambda::_2 ) )
+    );   
+    norm = std::sqrt(norm);
+    return k.profile(norm);
+}
+
+template<typename K,unsigned M> 
+template<typename X> 
+typename mono_bw_kernel<K,M>::result_type 
+mono_bw_kernel<K,M>::operator()(const X& x)const{
+    return this->profile(x) / this->normalizing_constant();
+}
+
+template<typename K,unsigned M> 
+template<typename X,typename X1> 
+typename mono_bw_kernel<K,M>::result_type 
+mono_bw_kernel<K,M>::operator()(const X& x,const X1& x1)const{
+    typedef vector_space::lazy_difference<X,X1> diff_;
+    typedef typename range_size<X>::type size_type;
+    BOOST_ASSERT(size(x) == static_cast<size_type>(size(x1)));
+    BOOST_ASSERT(size(x) == static_cast<size_type>(M));
+    diff_ diff(x,x1);
+    return (*this)(diff);
+}
+        
+// Access
+template<typename K,unsigned M> unsigned mono_bw_kernel<K,M>::dimension = M;
+
+template<typename K,unsigned M>
+typename mono_bw_kernel<K,M>::result_type 
+mono_bw_kernel<K,M>::radius()const{ 
+    const K& k = static_cast<const K&>(*this);
+    return k.radius();
+}
+
+template<typename K,unsigned M>
+typename mono_bw_kernel<K,M>::result_type 
+mono_bw_kernel<K,M>::normalizing_constant()const{ return normalizing_constant_; }
+    
+template<typename K,unsigned M>
+typename mono_bw_kernel<K,M>::result_type 
+mono_bw_kernel<K,M>::comp_nc()const{
+    const K& k = static_cast<const K&>(*this);
+    static result_type m = static_cast<result_type>(M);
+    result_type nc = k.normalizing_constant();
+    return std::pow(nc,m);
+}
+ 
+}// multivariate
+}// kernel
+}// detail
+}// statistics
+}// boost   
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/crtp.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/crtp.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,119 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::scalar::crtp.hpp                              //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_SCALAR_CRTP_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_SCALAR_CRTP_HPP_ER_2009
+#include <boost/format.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+namespace scalar{
+
+// Overview: provides common operations for a kernel whose implementation
+// is specified by a derived class, D.
+//
+// Let d note an instance of D, and T == D::result_type
+//
+// Requirements
+// crtp<D,T> is a base of D
+// D::result_type is defined
+// D::core_profile(const T&)        returns an object of type T
+// D::core_nc                       returns an object of type T (normalzing c)
+// D d;                             Constructor Forwards to crtp<D,T>
+// D d(r)                           Constructor Forwards to crtp<D,T>
+template<typename D,typename T> 
+class crtp{
+    public:
+    typedef T result_type;
+
+    // Construction
+    crtp();
+    crtp(const result_type& bandwidth);
+    
+    // Evaluate
+    template<typename X> result_type profile(const X& x)const;
+    template<typename X> result_type operator()(const X& x)const;
+    template<typename X,typename X1> 
+    result_type operator()(const X& x,const X1& x1)const;
+    
+    // Access
+    result_type bandwidth()const;
+    result_type normalizing_constant()const;
+    
+    private:
+    result_type bandwidth_;
+    result_type normalizing_constant_;
+    result_type comp_nc(result_type bandwidth);
+};
+
+template<typename D,typename T>
+std::ostream& operator<<(std::ostream& out,const crtp<D,T>& k){
+    const char* str = "(%1%,%2%)";
+    format f(str); f%k.bandwidth()%k.normalizing_constant();
+    out << f.str();
+    return out; 
+}
+
+// Construction
+template<typename D,typename T> crtp<D,T>::crtp()
+:bandwidth_(static_cast<result_type>(1)),
+normalizing_constant_(this->comp_nc(bandwidth())){}
+
+template<typename D,typename T> crtp<D,T>::crtp(const result_type& bandwidth)
+:bandwidth_(bandwidth),
+normalizing_constant_(this->comp_nc(this->bandwidth())){}
+
+
+// Evaluate
+template<typename D,typename T>    
+template<typename X>
+typename crtp<D,T>::result_type 
+crtp<D,T>::profile(const X& x)const{
+    result_type u = x / this->bandwidth();
+    return D::core_profile(u);
+} 
+
+template<typename D,typename T>    
+template<typename X>
+typename crtp<D,T>::result_type 
+crtp<D,T>::operator()(const X& x)const{
+    return ( this->profile(x) ) / ( this->normalizing_constant()) ;
+} 
+
+template<typename D,typename T>
+template<typename X,typename X1> 
+typename crtp<D,T>::result_type 
+crtp<D,T>::operator()(const X& x,const X1& x1)const{
+    return (*this)(x-x1);
+}
+  
+// Access
+template<typename D,typename T>    
+typename crtp<D,T>::result_type crtp<D,T>::bandwidth()const{ 
+    return this->bandwidth_; 
+}
+
+template<typename D,typename T>    
+typename crtp<D,T>::result_type crtp<D,T>::normalizing_constant()const{ 
+    return this->normalizing_constant_; 
+}
+
+// Implem
+template<typename D,typename T>    
+typename crtp<D,T>::result_type crtp<D,T>::comp_nc(result_type bandwidth){ 
+    return D::core_nc * bandwidth;  
+}
+
+}// scalar
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::scalar::gaussian.hpp                          //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_SCALAR_GAUSSIAN_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_SCALAR_GAUSSIAN_HPP_ER_2009
+#include <cmath>
+#include <boost/statistics/detail/kernel/kernels/scalar/crtp.hpp>
+#include <boost/math/constants/constants.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace kernel{
+namespace scalar{
+
+template<typename T>
+struct gaussian_kernel : scalar::crtp<gaussian_kernel<T>,T >{ 
+    typedef gaussian_kernel<T> this_type;
+    typedef scalar::crtp<this_type,T> crtp_;
+    public:
+    typedef typename crtp_::result_type result_type;
+    
+    gaussian_kernel();
+    gaussian_kernel(const result_type& bandwidth);
+    
+    static result_type core_profile(const result_type& x);
+    static result_type core_nc;
+};
+
+template<typename T> gaussian_kernel<T>::gaussian_kernel():crtp_(){}
+template<typename T> gaussian_kernel<T>::gaussian_kernel(
+    const result_type& bandwidth
+)
+:crtp_(bandwidth){}
+    
+template<typename T>
+typename gaussian_kernel<T>::result_type
+gaussian_kernel<T>::core_profile(const result_type& x){
+    static result_type two = static_cast<T>(2);
+    return exp(- x * x / two);
+}
+    
+template<typename T>
+typename gaussian_kernel<T>::result_type
+gaussian_kernel<T>::core_nc = math::constants::root_two_pi<T>();
+
+}// scalar
+}// kernel
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/statistics/detail/kernel/kernels/scalar/include.hpp	2009-10-04 18:54:20 EDT (Sun, 04 Oct 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::kernel::scalar::include.hpp                           //
+//                                                                           //
+//  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 BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_SCALAR_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_DETAIL_KERNEL_KERNELS_SCALAR_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/detail/kernel/kernels/scalar/crtp.hpp>
+#include <boost/statistics/detail/kernel/kernels/scalar/gaussian.hpp>
+
+#endif
\ No newline at end of file