$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r58994 - in sandbox/statistics/detail/accumulator: boost/statistics/detail/accumulator/statistics boost/statistics/detail/accumulator/statistics/keyword boost/statistics/detail/accumulator/statistics/tag libs/statistics/detail/example
From: erwann.rogard_at_[hidden]
Date: 2010-01-13 20:32:44
Author: e_r
Date: 2010-01-13 20:32:43 EST (Wed, 13 Jan 2010)
New Revision: 58994
URL: http://svn.boost.org/trac/boost/changeset/58994
Log:
adding frequency_int
Added:
   sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/count_int.hpp   (contents, props changed)
   sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/empirical_distribution_int.hpp   (contents, props changed)
   sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/frequency_int.hpp   (contents, props changed)
   sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/keyword/key.hpp   (contents, props changed)
   sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/tag/
   sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/tag/key.hpp   (contents, props changed)
   sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/tag/threshold.hpp   (contents, props changed)
   sandbox/statistics/detail/accumulator/libs/statistics/detail/example/frequency_int.cpp   (contents, props changed)
   sandbox/statistics/detail/accumulator/libs/statistics/detail/example/frequency_int.h   (contents, props changed)
Added: sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/count_int.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/count_int.hpp	2010-01-13 20:32:43 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,157 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulator::statistics::count_int.hpp     						     	 //
+//                                                                           //
+//  Copyright 2010 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_ACCUMULATOR_STATISTICS_COUNT_INT_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_ACCUMULATOR_STATISTICS_COUNT_INT_HPP_ER_2010
+#include <map>
+#include <functional>
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/bool.hpp>
+
+#include <boost/range.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/parameters/accumulator.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+#include <boost/statistics/detail/accumulator/statistics/keyword/key.hpp>
+#include <boost/statistics/detail/accumulator/statistics/empirical_distribution_int.hpp>
+
+namespace boost { 
+namespace statistics{
+namespace detail{
+namespace accumulator{
+
+namespace impl{
+
+	template<typename Int,bool Cum>
+	class count_int : public boost::accumulators::accumulator_base{
+		typedef std::less<Int> comp_;
+		typedef std::size_t size_;
+        typedef boost::accumulators::dont_care dont_care_;
+
+        public:
+
+		typedef size_ result_type;
+
+		count_int(dont_care_){}
+
+		void operator()(dont_care_){}
+		
+        template<typename Args>
+        result_type result(const Args& args)const{
+        	Int key = args[statistics::detail::accumulator::keyword::key];
+        	typedef typename boost::mpl::bool_<Cum> is_cum_;
+            typedef statistics::detail::accumulator
+            	::tag::empirical_distribution_int tag_;
+        	return this->result_impl(
+            	boost::accumulators::extract_result<tag_>(
+                	args[boost::accumulators::accumulator]
+                ),
+                key,
+                is_cum_()
+            ); 
+        }
+
+		private:
+		
+        template<typename Map,typename N>
+		result_type result_impl(
+        	Map& map,
+            const N& key,
+            boost::mpl::bool_<false> cum
+        )const{
+        	return (map[key]); 
+        }
+
+        template<typename Map,typename N>
+		result_type result_impl(
+        	Map& map, 
+            const N& key,
+            boost::mpl::bool_<true> cum
+        )const{
+        	return std::for_each(
+            	boost::begin(map),
+                map.upper_bound(key),
+            	accumulator()
+            ).value; 
+        }
+
+		struct accumulator{
+        	mutable size_ value;
+        	
+            accumulator():value(0){}
+			accumulator(const accumulator& that)
+            	:value(that.value){}
+            
+            template<typename Data>
+            void operator()(const Data& data)const{
+            	value += data.second;
+            }
+        
+        };
+	};
+    
+}
+
+namespace tag
+{
+	template<bool Cum>
+    struct count_int
+      : boost::accumulators::depends_on<
+      	statistics::detail::accumulator::tag::empirical_distribution_int
+    >
+    {
+
+// TODO compile error
+//      typedef statistics::detail::accumulator::
+//      	impl::count_int<boost::mpl::_1,Cum> impl;
+// must explicitly have:        
+        
+        struct impl{
+        	template<typename Int,typename W>
+            struct apply{
+            	typedef statistics::detail::accumulator::
+                	impl::count_int<Int,Cum> type;
+            };
+        };
+    };
+}
+
+namespace extract
+{
+
+  	template<bool Cum,typename AccumulatorSet,typename Int>
+	typename boost::mpl::apply<
+		AccumulatorSet,
+        boost::statistics::detail::accumulator::tag::count_int<Cum>
+    >::type::result_type
+  	count_int(AccumulatorSet const& acc,const Int& i)
+    {
+    	typedef boost::statistics::detail
+        	::accumulator::tag::count_int<Cum> the_tag;
+        return boost::accumulators::extract_result<the_tag>(
+            acc,
+            (boost::statistics::detail::accumulator::keyword::key = i)
+        );
+  	}
+
+}
+
+using extract::count_int;
+
+}// accumulator
+}// detail
+}// statistics
+}// boost
+
+#endif
Added: sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/empirical_distribution_int.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/empirical_distribution_int.hpp	2010-01-13 20:32:43 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,99 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulator::statistics::empirical_distribution_int.hpp     				 //
+//                                                                           //
+//  Copyright 2010 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_ACCUMULATOR_STATISTICS_EMPIRICAL_DISTRIBUTION_INT_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_ACCUMULATOR_STATISTICS_EMPIRICAL_DISTRIBUTION_INT_HPP_ER_2010
+#include <map>
+#include <functional>
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/apply.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/parameters/accumulator.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+#include <boost/statistics/detail/accumulator/statistics/keyword/key.hpp>
+
+namespace boost { 
+namespace statistics{
+namespace detail{
+namespace accumulator{
+
+namespace impl{
+
+	template<typename Int>
+	class empirical_distribution_int 
+    		: public boost::accumulators::accumulator_base{
+		typedef std::less<Int> comp_;
+		typedef std::size_t size_;
+        typedef boost::accumulators::dont_care dont_care_;
+        typedef std::map<Int,size_,comp_> map_;
+
+        public:
+
+		typedef size_ size_type;
+
+		// non-const because map::operator[](key) returns a non-const
+		typedef map_& result_type;
+
+		empirical_distribution_int(dont_care_){}
+
+		template<typename Args>
+		void operator()(const Args& args){
+        	++(this->freq[args[boost::accumulators::sample]]);
+        }
+		
+		// Returns the entire distribution, represented by a map
+        result_type result(dont_care_)const{
+        	return (this->freq); 
+        }
+
+		private:
+        mutable map_ freq;
+	};
+    
+}
+
+namespace tag
+{
+    struct empirical_distribution_int
+      : boost::accumulators::depends_on<>
+    {
+      typedef statistics::detail::accumulator::
+      	impl::empirical_distribution_int<boost::mpl::_1> impl;
+    };
+}
+
+namespace extract
+{
+
+  	template<typename AccumulatorSet>
+	typename boost::mpl::apply<
+		AccumulatorSet,
+        boost::statistics::detail::accumulator::tag::empirical_distribution_int
+    >::type::result_type
+  	empirical_distribution_int(AccumulatorSet const& acc)
+    {
+    	typedef boost::statistics::detail::accumulator::
+    		tag::empirical_distribution_int the_tag;
+        return boost::accumulators::extract_result<the_tag>(acc);
+  	}
+
+}
+
+using extract::empirical_distribution_int;
+
+}// accumulator
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/frequency_int.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/frequency_int.hpp	2010-01-13 20:32:43 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,122 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulator::statistics::frequency_int.hpp     						     //
+//                                                                           //
+//  Copyright 2010 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_ACCUMULATOR_STATISTICS_FREQUENCY_INT_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_ACCUMULATOR_STATISTICS_FREQUENCY_INT_HPP_ER_2010
+#include <iostream> // tmp
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/if.hpp>
+
+#include <boost/parameter/binding.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/parameters/accumulator.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+
+#include <boost/statistics/detail/accumulator/statistics/keyword/key.hpp>
+#include <boost/statistics/detail/accumulator/statistics/count_int.hpp>
+
+namespace boost { 
+namespace statistics{
+namespace detail{
+namespace accumulator{
+
+namespace impl{
+
+	// Same as count_int but expressed as a percentage of the sample size
+	template<typename T,typename Int,bool Cum>
+	class frequency_int : public boost::accumulators::accumulator_base{
+    	
+		typedef std::size_t size_;
+        typedef boost::accumulators::dont_care dont_care_;
+
+        public:
+
+		frequency_int(dont_care_){}
+
+		typedef size_ size_type;
+		typedef T result_type;
+
+        void operator()(dont_care_)const{}
+
+        template<typename Args>
+        result_type result(const Args& args) const
+        {
+			typedef boost::accumulators::tag::accumulator tag_acc_;        
+            typedef boost::parameter::binding<Args,tag_acc_> bind_;
+            typedef typename bind_::type cref_;
+        	typedef boost::accumulators::tag::count tag_n_;
+            cref_ acc = args[boost::accumulators::accumulator];
+            size_ i =  boost::statistics::detail::accumulator
+            	::extract::count_int<Cum>( 
+            		acc,
+                	args[statistics::detail::accumulator::keyword::key]
+            	);
+			size_ n = boost::accumulators::extract_result<tag_n_>( acc );
+            return static_cast<T>(i)/static_cast<T>(n);
+        }
+	};
+    
+}
+
+namespace tag
+{
+	template<bool Cum,typename T = double>
+    struct frequency_int
+      : boost::accumulators::depends_on<
+      	statistics::detail::accumulator::tag::count_int<Cum>,
+        boost::accumulators::tag::count
+    >
+    {
+      	// typedef statistics::detail::accumulator::
+      	// 	impl::frequency_int<T,boost::mpl::_1,Cum> impl;
+        
+        struct impl{
+        	template<typename Int,typename W>
+            struct apply{
+        		typedef statistics::detail::accumulator
+                	::impl::frequency_int<T,Int,Cum> type;    	
+            };
+        };
+    };
+}
+
+namespace extract
+{
+
+  	template<bool Cum,typename AccumulatorSet,typename Int>
+	typename boost::mpl::apply<
+		AccumulatorSet,
+        boost::statistics::detail::accumulator::tag::frequency_int<Cum>
+    >::type::result_type
+  	frequency_int(AccumulatorSet const& acc,const Int& i)
+    {
+    	typedef double T;
+    	typedef boost::statistics::detail::accumulator::
+    		tag::frequency_int<Cum,T> the_tag;
+        return boost::accumulators::extract_result<the_tag>(
+            acc,
+            (boost::statistics::detail::accumulator::keyword::key = i)
+        );
+  	}
+
+}
+
+using extract::frequency_int;
+
+}// accumulator
+}// detail
+}// statistics
+}// boost
+
+#endif
Added: sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/keyword/key.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/keyword/key.hpp	2010-01-13 20:32:43 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,30 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::accumulator::keyword::key.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_ACCUMULATOR_STATISTICS_KEYWORD_KEY_HPP_2010
+#define BOOST_STATISTICS_DETAIL_ACCUMULATOR_STATISTICS_KEYWORD_KEY_HPP_2010
+#include <boost/parameter/name.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/statistics/detail/accumulator/statistics/tag/key.hpp>
+
+namespace boost { 
+namespace statistics{
+namespace detail{
+namespace accumulator{
+namespace keyword{
+    namespace 
+    {
+        boost::parameter::keyword<tag::key>& key
+            = boost::parameter::keyword<tag::key>::get();
+    }
+}// keyword
+}// accumulator
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/tag/key.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/tag/key.hpp	2010-01-13 20:32:43 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,25 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::accumulator::tag::key.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_ACCUMULATOR_STATISTICS_TAG_KEY_HPP_2010
+#define BOOST_STATISTICS_DETAIL_ACCUMULATOR_STATISTICS_TAG_KEY_HPP_2010
+#include <boost/parameter/name.hpp>
+#include <boost/parameter/keyword.hpp>
+
+namespace boost { 
+namespace statistics{
+namespace detail{
+namespace accumulator{
+namespace tag{
+    struct key{};
+}// tag
+}// accumulator
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/tag/threshold.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/accumulator/boost/statistics/detail/accumulator/statistics/tag/threshold.hpp	2010-01-13 20:32:43 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,25 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::detail::accumulator::tag::threshold.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_ACCUMULATOR_STATISTICS_TAG_THRESHOLD_HPP_2009
+#define BOOST_STATISTICS_DETAIL_ACCUMULATOR_STATISTICS_TAG_THRESHOLD_HPP_2009
+#include <boost/parameter/name.hpp>
+#include <boost/parameter/keyword.hpp>
+
+namespace boost { 
+namespace statistics{
+namespace detail{
+namespace accumulator{
+namespace tag{
+    struct threshold{};
+}// tag
+}// accumulator
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/detail/accumulator/libs/statistics/detail/example/frequency_int.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/accumulator/libs/statistics/detail/example/frequency_int.cpp	2010-01-13 20:32:43 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,73 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulator::statistics::frequency_int.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 <vector>
+#include <algorithm>
+
+#include <boost/assign/std/vector.hpp>
+#include <boost/format.hpp>
+
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+
+#include <boost/statistics/detail/accumulator/statistics/frequency_int.hpp>
+
+void example_frequency_int(std::ostream& os)
+{
+
+	os << "-> example_frequency_int" << std::endl;
+
+	typedef int int_;
+	typedef std::vector<int_> ints_;
+
+	using namespace boost::assign;
+    ints_ ints; 
+    const int n = 3;
+    for(unsigned i = 0; i<n; i++){
+    	for(unsigned j = i; j<n; j++){
+	    	ints.push_back(n-i);
+        }
+    } // 3, 3, 3, 2, 2, 1
+
+	namespace accumulator = boost::statistics::detail::accumulator;
+	
+    typedef accumulator::tag::count_int<false> tag_count_;
+    typedef accumulator::tag::frequency_int<false> tag_freq_;
+    typedef accumulator::tag::frequency_int<true> tag_cum_freq_;
+    typedef accumulator::tag::empirical_distribution_int tag_emp_;
+    
+	typedef boost::accumulators::accumulator_set<
+    	int_,
+        boost::accumulators::stats<tag_freq_,tag_cum_freq_>
+    > acc_;
+
+	acc_ acc = std::for_each(
+    	boost::begin(ints),
+        boost::end(ints),
+        acc_()
+    );
+
+// TODO boost::format runtime bug
+//	os << (boost::format("empirical {(pdf,cdf):i=1,...,%1%} : ")%n) << std::endl;
+	os << "empirical {(pdf,cdf):i=1,...,n} : " << std::endl;
+    int sum = 0;
+    for(int i = 0; i<n; i++){
+		BOOST_ASSERT( accumulator::extract::count_int<false>(acc,i+1) == i+1);
+        sum += i+1;
+		BOOST_ASSERT( accumulator::extract::count_int<true>(acc,i+1) == sum);
+
+		boost::format f("(%1%,%2%)");
+        double freq = accumulator::extract::frequency_int<false>(acc,i+1);
+        double cum_freq = accumulator::extract::frequency_int<true>(acc,i+1);
+        //f % freq % cum_freq;
+		//os << f << std::endl;        
+        os << '(' << freq << ',' << cum_freq << ')' << std::endl;
+    }
+
+
+	os << "<-" << std::endl;
+}
\ No newline at end of file
Added: sandbox/statistics/detail/accumulator/libs/statistics/detail/example/frequency_int.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/accumulator/libs/statistics/detail/example/frequency_int.h	2010-01-13 20:32:43 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulator::statistics::frequency_int.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_ACCUMULATOR_STATISTICS_FREQUENCY_INT_HPP_ER_2009
+#define LIBS_STATISTICS_DETAIL_ACCUMULATOR_STATISTICS_FREQUENCY_INT_HPP_ER_2009
+
+void example_frequency_int(std::ostream& os);
+
+#endif
+