|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59170 - in sandbox/statistics/non_parametric: boost/statistics/detail/non_parametric/empirical_distribution boost/statistics/detail/non_parametric/empirical_distribution/keyword boost/statistics/detail/non_parametric/empirical_distribution/tag libs/statistics/detail/non_parametric/doc libs/statistics/detail/non_parametric/example libs/statistics/detail/non_parametric/src
From: erwann.rogard_at_[hidden]
Date: 2010-01-20 18:18:17
Author: e_r
Date: 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
New Revision: 59170
URL: http://svn.boost.org/trac/boost/changeset/59170
Log:
m
Text files modified:
sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/count.hpp | 89 +++++++++++++++++++------------
sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/frequency.hpp | 52 ++++++++++-------
sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/keyword/key.hpp | 20 ++++--
sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/ordered_sample.hpp | 47 ++++++++++-----
sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/tag/key.hpp | 24 ++++----
sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/doc/readme.txt | 6 +
sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/frequency_int.cpp | 26 ++++----
sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.cpp | 113 ++++++++++++++-------------------------
sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.h | 9 ++
sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/src/main.cpp | 4 +
10 files changed, 212 insertions(+), 178 deletions(-)
Modified: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/count.hpp
==============================================================================
--- sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/count.hpp (original)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/count.hpp 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -8,7 +8,9 @@
#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_EMPIRICAL_DISTRIBUTION_COUNT_HPP_ER_2010
#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_EMPIRICAL_DISTRIBUTION_COUNT_HPP_ER_2010
#include <map>
-#include <functional>
+#include <functional> // less
+
+#include <boost/type_traits.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/apply.hpp>
@@ -32,15 +34,22 @@
namespace impl{
- template<typename Int,bool Cum>
+
+ // Count of occurences matching (or less equal than) a given value
+ //
+ // Warning : If Cum == true boost::is_float<T> affects the implementa-
+ // tion. For example, if say the samples are generated from a Poisson
+ // [Normal] distribution, T must be an integral [a float] type.
+ template<typename T,bool Cum,typename Comp = std::less<T> >
class count : public boost::accumulators::accumulator_base{
- typedef std::less<Int> comp_;
+ typedef Comp comp_;
typedef std::size_t size_;
typedef boost::accumulators::dont_care dont_care_;
public:
typedef size_ result_type;
+ typedef T sample_type;
count(dont_care_){}
@@ -48,11 +57,10 @@
template<typename Args>
result_type result(const Args& args)const{
- Int key
- = args[boost::accumulators::sample];
+ sample_type key = args[boost::accumulators::sample];
typedef typename boost::mpl::bool_<Cum> is_cum_;
- typedef statistics::detail::empirical_distribution
- ::tag::ordered_sample tag_;
+ typedef boost::statistics::detail
+ ::empirical_distribution::tag::ordered_sample tag_;
return this->result_impl(
boost::accumulators::extract_result<tag_>(
args[boost::accumulators::accumulator]
@@ -64,28 +72,37 @@
private:
- template<typename Map,typename N>
+ template<typename Map>
result_type result_impl(
Map& map,
- const N& key,
+ const sample_type& key,
boost::mpl::bool_<false> cum
)const{
return (map[key]);
}
- template<typename Map,typename N>
+ template<typename Map>
result_type result_impl(
Map& map,
- const N& key,
+ const sample_type& x,
boost::mpl::bool_<true> cum
)const{
return std::for_each(
- boost::begin(map),
- map.upper_bound(key),
+ boost::const_begin(map),
+ this->bound(map,x),
accumulator()
).value;
}
+ template<typename Map>
+ typename boost::range_iterator<const Map>::type
+ bound(
+ const Map& map,
+ const sample_type& x
+ )const{
+ return map.upper_bound(x);
+ }
+
struct accumulator{
mutable size_ value;
@@ -106,44 +123,46 @@
namespace tag
{
template<bool Cum>
- struct count
- : boost::accumulators::depends_on<
- statistics::detail
+ struct count: boost::accumulators::depends_on<
+ boost::statistics::detail
::empirical_distribution::tag::ordered_sample
>
{
-
-// TODO compile error
-// typedef statistics::detail::accumulator::empirical_distribution
-// impl::count<boost::mpl::_1,Cum> impl;
-// must explicitly have:
-
struct impl{
- template<typename Int,typename W>
+ template<typename T,typename W>
struct apply{
- typedef statistics::detail::empirical_distribution
- ::impl::count<Int,Cum> type;
+ typedef boost::statistics::detail::empirical_distribution
+ ::impl::count<T,Cum> type;
};
};
};
}
+namespace result_of{
+ template<bool Cum,typename AccSet>
+ struct count{
+ typedef boost::statistics::detail
+ ::empirical_distribution::tag::count<Cum> tag_;
+ typedef typename
+ boost::accumulators::detail::template
+ extractor_result<AccSet,tag_>::type type;
+ };
+
+}
namespace extract
{
- template<bool Cum,typename AccumulatorSet,typename Int>
- typename boost::mpl::apply<
- AccumulatorSet,
- boost::statistics::detail
- ::empirical_distribution::tag::count<Cum>
- >::type::result_type
- count(AccumulatorSet const& acc,const Int& i)
+ // Usage : count<Cum>(acc,x)
+ template<bool Cum,typename AccSet,typename T>
+ typename boost::statistics::detail
+ ::empirical_distribution::result_of::template count<Cum,AccSet>::type
+ count(AccSet const& acc,const T& x)
{
typedef boost::statistics::detail
- ::empirical_distribution::tag::count<Cum> the_tag;
- return boost::accumulators::extract_result<the_tag>(
+ ::empirical_distribution::tag::count<Cum> tag_;
+ return boost::accumulators::extract_result<tag_>(
acc,
- (boost::accumulators::sample = i)
+ (boost::accumulators::sample = x)
);
}
Modified: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/frequency.hpp
==============================================================================
--- sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/frequency.hpp (original)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/frequency.hpp 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -20,7 +20,7 @@
#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/stats.hpp>
#include <boost/accumulators/statistics/count.hpp>
#include <boost/statistics/detail/non_parametric/empirical_distribution/count.hpp>
@@ -32,8 +32,10 @@
namespace impl{
- // Same as count but expressed as a percentage of the sample size
- template<typename T,typename Int,bool Cum>
+ // Same as count but expressed as a percentage (type T1) of the sample size
+ //
+ // Warning : See empirical_distribution::impl::count.
+ template<typename T,bool Cum,typename T1>
class frequency : public boost::accumulators::accumulator_base{
typedef std::size_t size_;
@@ -44,7 +46,8 @@
frequency(dont_care_){}
typedef size_ size_type;
- typedef T result_type;
+ typedef T sample_type; // See accumulator_set
+ typedef T1 result_type;
void operator()(dont_care_)const{}
@@ -62,7 +65,7 @@
args[boost::accumulators::sample]
);
size_ n = boost::accumulators::extract_result<tag_n_>( acc );
- return static_cast<T>(i)/static_cast<T>(n);
+ return static_cast<T1>(i)/static_cast<T1>(n);
}
};
@@ -70,43 +73,50 @@
namespace tag
{
- template<bool Cum,typename T = double>
+ template<bool Cum,typename T1 = double>
struct frequency
: boost::accumulators::depends_on<
statistics::detail::empirical_distribution::tag::count<Cum>,
boost::accumulators::tag::count
>
{
- // typedef statistics::detail::accumulator::
- // impl::frequency<T,boost::mpl::_1,Cum> impl;
-
struct impl{
- template<typename Int,typename W>
+ template<typename T,typename W>
struct apply{
typedef statistics::detail::empirical_distribution
- ::impl::frequency<T,Int,Cum> type;
+ ::impl::frequency<T,Cum,T1> type;
};
};
};
}
+namespace result_of{
+
+ template<bool Cum,typename T1,typename AccSet>
+ struct frequency{
+
+ typedef boost::statistics::detail
+ ::empirical_distribution::tag::frequency<Cum,T1> tag_;
+ typedef typename boost::accumulators
+ ::detail::template extractor_result<AccSet,tag_>::type type;
+
+ };
+}
+
namespace extract
{
- template<bool Cum,typename AccumulatorSet,typename Int>
- typename boost::mpl::apply<
- AccumulatorSet,
- boost::statistics::detail
- ::empirical_distribution::tag::frequency<Cum>
- >::type::result_type
- frequency(AccumulatorSet const& acc,const Int& i)
+ // Usage : frequency<Cum,T1>(acc,x)
+ template<bool Cum,typename T1,typename AccSet,typename T>
+ typename boost::statistics::detail::empirical_distribution
+ ::result_of::template frequency<Cum,T1,AccSet>::type
+ frequency(AccSet const& acc,const T& x)
{
- typedef double T;
typedef boost::statistics::detail::empirical_distribution
- ::tag::frequency<Cum,T> the_tag;
+ ::tag::frequency<Cum,T1> the_tag;
return boost::accumulators::extract_result<the_tag>(
acc,
- (boost::accumulators::sample = i)
+ (boost::accumulators::sample = x)
);
}
Modified: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/keyword/key.hpp
==============================================================================
--- sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/keyword/key.hpp (original)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/keyword/key.hpp 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -1,28 +1,32 @@
///////////////////////////////////////////////////////////////////////////////
-// statistics::accumulator::empirical_distribution::keyword::key.hpp //
+// kolmogorov_smirnov::keyword::reference_distribution.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_NON_PARAMETRIC_EMPIRICAL_DISTRIBUTION_KEYWORD_KEY_HPP_2010
-#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_EMPIRICAL_DISTRIBUTION_KEYWORD_KEY_HPP_2010
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_KOLMOGOROV_SMIRNOV_KEYWORD_REFERENCE_DISTRIBUTION_HPP_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_KOLMOGOROV_SMIRNOV_KEYWORD_REFERENCE_DISTRIBUTION_HPP_2010
#include <boost/parameter/name.hpp>
#include <boost/parameter/keyword.hpp>
-#include <boost/statistics/detail/non_parametric/empirical_distribution/tag/key.hpp>
+#include <boost/statistics/detail/non_parametric/empirical_distribution/tag/key.hpp> // TODO rename
namespace boost {
namespace statistics{
namespace detail{
-namespace empirical_distribution{
+namespace kolmogorov_smirnov{
namespace keyword{
namespace
{
- boost::parameter::keyword<tag::key>& key
- = boost::parameter::keyword<tag::key>::get();
+ boost::parameter::keyword<
+ kolmogorov_smirnov::tag::reference_distribution
+ >& reference_distribution
+ = boost::parameter::keyword<
+ kolmogorov_smirnov::tag::reference_distribution
+ >::get();
}
}// keyword
-}// empirical_distribution
+}// kolmogorov_smirnov
}// detail
}// statistics
}// boost
Modified: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/ordered_sample.hpp
==============================================================================
--- sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/ordered_sample.hpp (original)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/ordered_sample.hpp 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -27,17 +27,20 @@
namespace impl{
- template<typename Int>
+ // Associates sample values (type T) with their number of occurences in the sample
+ template<typename T>
class ordered_sample
: public boost::accumulators::accumulator_base{
- typedef std::less<Int> comp_;
+ typedef std::less<T> comp_;
typedef std::size_t size_;
typedef boost::accumulators::dont_care dont_care_;
- typedef std::map<Int,size_,comp_> map_;
+ typedef std::map<T,size_,comp_> map_;
public:
-
- typedef size_ size_type;
+
+ // See accumulator_set for convention naming sample_type
+ typedef T sample_type;
+ typedef size_ size_type;
// non-const because map::operator[](key) returns a non-const
typedef map_& result_type;
@@ -46,7 +49,12 @@
template<typename Args>
void operator()(const Args& args){
- ++(this->freq[args[boost::accumulators::sample]]);
+ ++(this->freq[
+ static_cast<T>(
+ args[boost::accumulators::sample]
+ )
+ ]
+ );
}
// Returns the entire distribution, represented by a map
@@ -58,7 +66,7 @@
mutable map_ freq;
};
-}
+}// impl
namespace tag
{
@@ -68,25 +76,32 @@
typedef statistics::detail::empirical_distribution::
impl::ordered_sample<boost::mpl::_1> impl;
};
-}
+}// tag
+
+namespace result_of{
+
+ template<typename AccSet>
+ struct ordered_sample : boost::accumulators::detail::extractor_result<
+ AccSet,
+ boost::statistics::detail::empirical_distribution::tag::ordered_sample
+ >{};
+
+}// result_of
namespace extract
{
- template<typename AccumulatorSet>
- typename boost::mpl::apply<
- AccumulatorSet,
- boost::statistics::detail::empirical_distribution
- ::tag::ordered_sample
- >::type::result_type
- ordered_sample(AccumulatorSet const& acc)
+ template<typename AccSet>
+ typename boost::statistics::detail::empirical_distribution
+ ::result_of::template ordered_sample<AccSet>::type
+ ordered_sample(AccSet const& acc)
{
typedef boost::statistics::detail::empirical_distribution
::tag::ordered_sample the_tag;
return boost::accumulators::extract_result<the_tag>(acc);
}
-}
+}// extract
using extract::ordered_sample;
Modified: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/tag/key.hpp
==============================================================================
--- sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/tag/key.hpp (original)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/empirical_distribution/tag/key.hpp 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -1,23 +1,23 @@
-///////////////////////////////////////////////////////////////////////////////
-// statistics::accumulator::empirical_distribution::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_NON_PARAMETRIC_EMPIRICAL_DISTRIBUTION_TAG_KEY_HPP_2010
-#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_EMPIRICAL_DISTRIBUTION_TAG_KEY_HPP_2010
+////////////////////////////////////////////////////////////////////////////////
+// kolmogorov_smirnov::tag::reference_distribution.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_NON_PARAMETRIC_KOLMOGOROV_SMIRNOV_TAG_REFERENCE_DISTRIBUTION_HPP_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_KOLMOGOROV_SMIRNOV_TAG_REFERENCE_DISTRIBUTION_HPP_2010
#include <boost/parameter/name.hpp>
#include <boost/parameter/keyword.hpp>
namespace boost {
namespace statistics{
namespace detail{
-namespace empirical_distribution{
+namespace kolmogorov_smirnov{
namespace tag{
- struct key{};
+ struct reference_distribution{};
}// tag
-}// empirical_distribution
+}// kolmogorov_smirnov
}// detail
}// statistics
}// boost
Modified: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/doc/readme.txt
==============================================================================
--- sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/doc/readme.txt (original)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/doc/readme.txt 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -29,7 +29,11 @@
[ History]
-
+ January 17th, 2010.
+ - Modified non_parametric/kolmogorov_smirnov/statistic.hpp from an
+ STL-like algorithm to a (much simplified) accumulator.
+ - Added check_convergence
+
January 14th, 2010.
- Added non_parametric/empirical_distribution
- Modified non_parametric/kolmogorov_smirnov/statistic.hpp to allow
Modified: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/frequency_int.cpp
==============================================================================
--- sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/frequency_int.cpp (original)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/frequency_int.cpp 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -25,31 +25,33 @@
os << "-> example_frequency_int" << std::endl;
- typedef int int_;
- typedef std::vector<int_> ints_;
+ typedef int sample_; // sample_ x = 1;
+ typedef double val_; // val_ p = pdf(dist,x);
+ typedef std::vector<sample_> samples_;
using namespace boost::assign;
- ints_ ints;
+ samples_ samples;
const int n = 3;
for(unsigned i = 0; i<n; i++){
for(unsigned j = i; j<n; j++){
- ints.push_back(n-i);
+ samples.push_back(n-i);
}
} // 3, 3, 3, 2, 2, 1
namespace ed = boost::statistics::detail::empirical_distribution;
+// namespace ks = boost::statistics::detail::ks;
- typedef ed::tag::frequency<false> tag_freq_;
- typedef ed::tag::frequency<true> tag_cum_freq_;
+ typedef ed::tag::frequency<false,val_> tag_freq_;
+ typedef ed::tag::frequency<true,val_> tag_cum_freq_;
typedef boost::accumulators::accumulator_set<
- int_,
+ sample_,
boost::accumulators::stats<tag_freq_,tag_cum_freq_>
> acc_;
acc_ acc = std::for_each(
- boost::begin(ints),
- boost::end(ints),
+ boost::begin(samples),
+ boost::end(samples),
acc_()
);
@@ -62,9 +64,9 @@
sum += i+1;
BOOST_ASSERT( ed::extract::count<true>(acc,i+1) == sum);
- boost::format f("(%1%,%2%)");
- double freq = ed::extract::frequency<false>(acc,i+1);
- double cum_freq = ed::extract::frequency<true>(acc,i+1);
+ //boost::format f("(%1%,%2%)");
+ val_ freq = ed::extract::frequency<false,val_>(acc,i+1);
+ val_ cum_freq = ed::extract::frequency<true,val_>(acc,i+1);
//f % freq % cum_freq;
//os << f << std::endl;
os << '(' << freq << ',' << cum_freq << ')' << std::endl;
Modified: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.cpp
==============================================================================
--- sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.cpp (original)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.cpp 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -23,96 +23,67 @@
#include <boost/math/distributions/poisson.hpp>
#include <boost/random/poisson_distribution.hpp>
+
+#include <boost/math/distributions/normal.hpp>
+#include <boost/random/normal_distribution.hpp>
+
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/variate_generator.hpp>
-#include <boost/statistics/detail/non_parametric/empirical_distribution/frequency.hpp>
-#include <boost/statistics/detail/non_parametric/kolmogorov_smirnov/frequency_adaptor.hpp>
-#include <boost/statistics/detail/non_parametric/kolmogorov_smirnov/statistic.hpp>
+#include <boost/statistics/detail/non_parametric/kolmogorov_smirnov/check_convergence.hpp>
#include <libs/statistics/detail/non_parametric/example/frequency_int.h>
-void example_kolmogorov_smirnov(std::ostream& os)
+void example_kolmogorov_smirnov(
+ std::ostream& os,
+ double mean = 1.0,
+ std::size_t n_loops = 1,
+ std::size_t n_init = 10,
+ std::size_t n_factor = 10 // n_init *= n_factor at each loop
+)
{
os << "-> example_kolmogorov_smirnov" << std::endl;
- // This example illustrates kolmogorov smirnov for a discrete distribution
- // (hence the presence of non-negligeable combos)
+ // This example illustrates kolmogorov smirnov for both a discrete
+ // and a continuous distribution
- namespace np = boost::statistics::detail::non_parametric;
+ namespace ks = boost::statistics::detail::kolmogorov_smirnov;
typedef double val_;
- typedef int int_;
- const val_ mean = 1;
- const int_ n = 10 * 10;
- typedef boost::math::poisson_distribution<> dist_;
- typedef boost::poisson_distribution<> random_;
+
typedef boost::mt19937 urng_;
- typedef boost::variate_generator<urng_&,random_> vg_;
typedef std::vector<val_> vals_;
- namespace ed = boost::statistics::detail::empirical_distribution;
+ typedef ks::check_convergence<val_> check_;
- typedef ed::tag::frequency<false> tag_freq_;
- typedef ed::tag::frequency<true> tag_cum_freq_;
-
- typedef boost::accumulators::accumulator_set<
- int_,
- boost::accumulators::stats<tag_freq_,tag_cum_freq_>
- > acc_;
-
- typedef boost::mpl::int_<0> k_x_;
- typedef boost::mpl::int_<1> k_cdf_;
- typedef boost::mpl::int_<2> k_cnt_;
-
- typedef np::kolmogorov_smirnov::statistic<val_,k_x_,k_cdf_,k_cnt_> ks_;
- typedef np::frequency_adaptor<k_x_,k_cdf_,k_cnt_,int_,val_> adaptor_;
- typedef adaptor_::type elem_;
- typedef std::vector<elem_> elems_;
-
- urng_ urng;
- vals_ random_sample;
- std::generate_n(
- std::back_inserter(random_sample),
- n,
- vg_(urng,random_(mean))
- );
-
- dist_ dist(mean);
- elems_ adapted_sample;
+ urng_ urng;
+ check_ check;
+ os << "(sample size,statistic) :" << std::endl;
{
- acc_ acc = std::for_each(
- boost::begin(random_sample),
- boost::end(random_sample),
- acc_()
- );
- BOOST_AUTO(
- tmp,
- adaptor_::call(acc,dist)
- );
- // A physical copy is necessary because ks(b,e) sorts [b,e)
- std::copy(
- boost::begin(tmp),
- boost::end(tmp),
- std::back_inserter(adapted_sample)
- );
- int_ nn = 0;
- BOOST_FOREACH(const elem_& e,adapted_sample){
- nn += boost::fusion::at_key<k_cnt_>(e);
- }
- BOOST_ASSERT(nn == n);
- }
+ typedef boost::math::poisson_distribution<> dist_;
+ typedef boost::poisson_distribution<> random_;
+ typedef boost::variate_generator<urng_&,random_> vg_;
+ dist_ dist(mean);
+ vg_ vg(urng,random_(mean));
- ks_ ks;
- ks(boost::begin(adapted_sample),boost::end(adapted_sample));
-
- os
- << ks_::description_header << '('
-// << ks.description() // boost::format bug
- << ks.count() << ','
- << ks.value() << ')'
- << std::endl;
+ os << "poisson(" << mean << ')' << std::endl;
+ check(n_loops,n_init,n_factor,dist,vg,os);
+ }
+ {
+ typedef boost::math::normal_distribution<> dist_;
+ typedef boost::normal_distribution<> random_;
+ typedef boost::variate_generator<urng_&,random_> vg_;
+ const val_ sd = 1.0;
+ dist_ dist(mean,sd);
+ vg_ vg(urng,random_(mean,sd));
+ os << "normal(" << mean
+ << ','
+ << sd
+ << ')'
+ << std::endl;
+ check(n_loops,n_init,n_factor,dist,vg,os);
+ }
os << "<-" << std::endl;
}
\ No newline at end of file
Modified: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.h
==============================================================================
--- sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.h (original)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.h 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -7,8 +7,15 @@
///////////////////////////////////////////////////////////////////////////////
#ifndef LIBS_STATISTICS_DETAIL_NON_PARAMETRIC_KOLMOGOROV_SMIRNOV_HPP_ER_2010
#define LIBS_STATISTICS_DETAIL_NON_PARAMETRIC_KOLMOGOROV_SMIRNOV_HPP_ER_2010
+#include <ostream>
-void example_kolmogorov_smirnov(std::ostream& os);
+void example_kolmogorov_smirnov(
+ std::ostream& os,
+ double poisson_mean = 1.0,
+ std::size_t n_loops = 1,
+ std::size_t n_init = 10,
+ std::size_t n_factor = 10 // n_init *= n_factor at each loop
+);
#endif
Modified: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/src/main.cpp
==============================================================================
--- sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/src/main.cpp (original)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/src/main.cpp 2010-01-20 18:18:16 EST (Wed, 20 Jan 2010)
@@ -6,7 +6,9 @@
int main()
{
example_frequency_int(std::cout);
- example_kolmogorov_smirnov(std::cout);
+ //example_kolmogorov_smirnov(std::cout,0.1,6,10,10);
+ example_kolmogorov_smirnov(std::cout,10.0,6,10,10);
+ //example_kolmogorov_smirnov(std::cout,100.0,6,10,10);
return 0;
}
\ No newline at end of file
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk