Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72912 - sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example
From: erwann.rogard_at_[hidden]
Date: 2011-07-05 07:25:39


Author: e_r
Date: 2011-07-05 07:25:38 EDT (Tue, 05 Jul 2011)
New Revision: 72912
URL: http://svn.boost.org/trac/boost/changeset/72912

Log:
cleaning up directory
Text files modified:
   sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/frequency_int.cpp | 51 +++++++++++++++++------------
   sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/frequency_int.h | 1
   sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.cpp | 68 ++++++++++++++++++++++-----------------
   sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/kolmogorov_smirnov.h | 9 ++--
   4 files changed, 73 insertions(+), 56 deletions(-)

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 2011-07-05 07:25:38 EDT (Tue, 05 Jul 2011)
@@ -1,22 +1,29 @@
 ///////////////////////////////////////////////////////////////////////////////
-// empirical_distribution::frequency_int.cpp //
+// frequency_int.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 <cmath>
 #include <vector>
 #include <algorithm>
 
 #include <boost/mpl/int.hpp>
 
+#include <boost/numeric/conversion/bounds.hpp>
+
 #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/non_parametric/empirical_distribution/frequency.hpp>
+#include <boost/statistics/detail/non_parametric/empirical_distribution/ordered_sample.hpp>
+#include <boost/statistics/detail/non_parametric/empirical_distribution/cumulative_count.hpp>
+#include <boost/statistics/detail/non_parametric/empirical_distribution/cdf.hpp>
+#include <boost/statistics/detail/non_parametric/empirical_distribution/pdf.hpp>
+
 #include <libs/statistics/detail/non_parametric/example/frequency_int.h>
 
 void example_frequency_int(std::ostream& os)
@@ -31,25 +38,21 @@
         using namespace boost::assign;
     samples_ samples;
     const int n = 3;
- for(unsigned i = 0; i<n; i++){
- for(unsigned j = i; j<n; j++){
+ for(int i = 0; i<n; i++){
+ for(int j = i; j<n; j++){
                     samples.push_back(n-i);
         }
     } // 3, 3, 3, 2, 2, 1
 
         namespace ed = boost::statistics::detail::empirical_distribution;
-
- typedef ed::tag::frequency<false,val_> tag_freq_;
- typedef ed::tag::frequency<true,val_> tag_cum_freq_;
-
- typedef boost::accumulators::accumulator_set<
- sample_,
- boost::accumulators::stats<tag_freq_,tag_cum_freq_>
- > acc_;
+ typedef ed::tag::cdf<val_> tag_cdf_;
+ typedef ed::tag::pdf<val_> tag_pdf_;
+ typedef boost::accumulators::accumulator_set<
+ sample_,boost::accumulators::stats<tag_pdf_,tag_cdf_> > acc_;
 
         acc_ acc = std::for_each(
- boost::begin(samples),
- boost::end(samples),
+ boost::begin( samples ),
+ boost::end( samples ),
         acc_()
     );
 
@@ -57,16 +60,22 @@
             << (boost::format("empirical {(pdf,cdf):i=1,...,%1%} : ")%n).str()
         << std::endl;
     int sum = 0;
- for(int i = 0; i<n; i++){
- BOOST_ASSERT( ed::extract::count<false>(acc,i+1) == i+1);
+ val_ freq, cum_freq;
+ for(int i = 0; i < n; i++){
+ BOOST_ASSERT( ed::extract::count( acc, i+1 ) == i+1);
         sum += i+1;
- BOOST_ASSERT( ed::extract::count<true>(acc,i+1) == sum);
+ BOOST_ASSERT( ed::extract::cumulative_count( acc, i+1 ) == sum);
 
- val_ freq = ed::extract::frequency<false,val_>(acc,i+1);
- val_ cum_freq = ed::extract::frequency<true,val_>(acc,i+1);
+ cum_freq = ed::extract::cdf<val_>( acc, i+1 );
+ freq = ed::extract::pdf<val_>( acc, i+1 );
         os << '(' << freq << ',' << cum_freq << ')' << std::endl;
-
     }
 
+ typedef boost::numeric::bounds<val_> bounds_;
+ val_ eps = bounds_::smallest();
+ val_ one = static_cast<val_>( 1 );
+
+ BOOST_ASSERT( fabs( one - cum_freq ) < eps );
+
         os << "<-" << std::endl;
-}
\ No newline at end of file
+}

Modified: sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/frequency_int.h
==============================================================================
--- sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/frequency_int.h (original)
+++ sandbox/statistics/non_parametric/libs/statistics/detail/non_parametric/example/frequency_int.h 2011-07-05 07:25:38 EDT (Tue, 05 Jul 2011)
@@ -11,4 +11,3 @@
 void example_frequency_int(std::ostream& os);
 
 #endif
-

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 2011-07-05 07:25:38 EDT (Tue, 05 Jul 2011)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// non_parametric::kolmogorov_smirnov.cpp //
+// kolmogorov_smirnov_statistic.cpp //
 // //
 // Copyright 2010 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //
@@ -30,15 +30,18 @@
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/random/variate_generator.hpp>
 
-#include <boost/statistics/detail/non_parametric/kolmogorov_smirnov/check_convergence.hpp>
+#include <boost/statistics/detail/non_parametric/empirical_distribution/kolmogorov_smirnov_statistic/value.hpp>
+#include <boost/statistics/detail/non_parametric/empirical_distribution/kolmogorov_smirnov_statistic/series.hpp>
+
 #include <libs/statistics/detail/non_parametric/example/frequency_int.h>
 
 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
+ double mean,
+ long offset,
+ long base,
+ long first_p,
+ long last_p
 )
 {
 
@@ -47,43 +50,48 @@
         // This example illustrates kolmogorov smirnov for both a discrete
     // and a continuous distribution
 
- namespace ks = boost::statistics::detail::kolmogorov_smirnov;
-
- typedef double val_;
-
-
+ namespace ac = boost::accumulators;
+ namespace ed = boost::statistics::detail::empirical_distribution;
+ namespace ks = ed::kolmogorov_smirnov_statistic;
     typedef boost::mt19937 urng_;
- typedef std::vector<val_> vals_;
- typedef ks::check_convergence<val_> check_;
 
     urng_ urng;
- check_ check;
 
- os << "(sample size,statistic) :" << std::endl;
         {
                 typedef boost::math::poisson_distribution<> dist_;
+ typedef dist_::value_type val_;
             typedef boost::poisson_distribution<> random_;
             typedef boost::variate_generator<urng_&,random_> vg_;
- dist_ dist(mean);
- vg_ vg(urng,random_(mean));
+ dist_ dist( mean );
+ vg_ vg( urng, random_(mean) );
 
             os << "poisson(" << mean << ')' << std::endl;
- check(n_loops,n_init,n_factor,dist,vg,os);
+
+ typedef ks::series_data<val_> data_;
+
+ ks::series(
+ dist, vg,
+ offset, base, first_p, last_p,
+ std::ostream_iterator<data_>(os,"\n")
+ );
+
     }
         {
                 typedef boost::math::normal_distribution<> dist_;
- typedef boost::normal_distribution<> random_;
+ typedef dist_::value_type val_;
+ typedef boost::poisson_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);
- }
+ const val_ sd = 1.0;
+ dist_ dist( mean, sd );
+ vg_ vg( urng, random_(mean) );
+ os << "normal(" << mean << ',' << sd << ')' << std::endl;
+ typedef ks::series_data<val_> data_;
+ ks::series(
+ dist, vg,
+ offset, base, first_p, last_p,
+ std::ostream_iterator<data_>(os,"\n")
+ );
 
+ }
         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 2011-07-05 07:25:38 EDT (Tue, 05 Jul 2011)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// non_parametric::kolmogorov_smirnov.h //
+// kolmogorov_smirnov_statistic.h //
 // //
 // Copyright 2010 Erwann Rogard. Distributed under the Boost //
 // Software License, Version 1.0. (See accompanying file //
@@ -12,9 +12,10 @@
 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
+ long offset = 1,
+ long base = 10,
+ long first_p = 0,
+ long last_p = 5
 );
 
 #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