Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59020 - sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example
From: erwann.rogard_at_[hidden]
Date: 2010-01-14 21:57:50


Author: e_r
Date: 2010-01-14 21:57:50 EST (Thu, 14 Jan 2010)
New Revision: 59020
URL: http://svn.boost.org/trac/boost/changeset/59020

Log:
m
Added:
   sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.cpp (contents, props changed)
   sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.h (contents, props changed)

Added: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.cpp 2010-01-14 21:57:50 EST (Thu, 14 Jan 2010)
@@ -0,0 +1,118 @@
+///////////////////////////////////////////////////////////////////////////////
+// non_parametric::kolmogorov_smirnov.cpp //
+// //
+// 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) //
+///////////////////////////////////////////////////////////////////////////////
+#include <vector>
+#include <algorithm>
+#include <iterator>
+
+#include <boost/mpl/int.hpp>
+
+#include <boost/typeof/typeof.hpp>
+#include <boost/range.hpp>
+
+#include <boost/assign/std/vector.hpp>
+#include <boost/format.hpp>
+#include <boost/foreach.hpp>
+
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+
+#include <boost/math/distributions/poisson.hpp>
+#include <boost/random/poisson_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 <libs/statistics/detail/non_parametric/example/frequency_int.h>
+
+void example_kolmogorov_smirnov(std::ostream& os)
+{
+
+ os << "-> example_kolmogorov_smirnov" << std::endl;
+
+ // This example illustrates kolmogorov smirnov for a discrete distribution
+ // (hence the presence of non-negligeable combos)
+
+ namespace np = boost::statistics::detail::non_parametric;
+
+ 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 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;
+
+ {
+ 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);
+ }
+
+ 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 << "<-" << std::endl;
+}
\ No newline at end of file

Added: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.h 2010-01-14 21:57:50 EST (Thu, 14 Jan 2010)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// non_parametric::kolmogorov_smirnov.h //
+// //
+// 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 LIBS_STATISTICS_DETAIL_NON_PARAMETRIC_KOLMOGOROV_SMIRNOV_HPP_ER_2010
+#define LIBS_STATISTICS_DETAIL_NON_PARAMETRIC_KOLMOGOROV_SMIRNOV_HPP_ER_2010
+
+void example_kolmogorov_smirnov(std::ostream& os);
+
+#endif
+
+


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