Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60357 - trunk/libs/random/test
From: steven_at_[hidden]
Date: 2010-03-08 12:16:58


Author: steven_watanabe
Date: 2010-03-08 12:16:57 EST (Mon, 08 Mar 2010)
New Revision: 60357
URL: http://svn.boost.org/trac/boost/changeset/60357

Log:
Enable the gap test for distributions
Text files modified:
   trunk/libs/random/test/Jamfile.v2 | 5 ++++-
   trunk/libs/random/test/statistic_tests.cpp | 31 ++++++++++++++++++++-----------
   trunk/libs/random/test/statistic_tests.hpp | 17 ++++++++---------
   3 files changed, 32 insertions(+), 21 deletions(-)

Modified: trunk/libs/random/test/Jamfile.v2
==============================================================================
--- trunk/libs/random/test/Jamfile.v2 (original)
+++ trunk/libs/random/test/Jamfile.v2 2010-03-08 12:16:57 EST (Mon, 08 Mar 2010)
@@ -44,5 +44,8 @@
 # run random_speed.cpp ;
 # run statistic_tests.cpp ;
 
-exe statistic_tests : statistic_tests.cpp ;
+exe statistic_tests.exe : statistic_tests.cpp ;
 explicit statistics_tests ;
+
+install statistic_tests : statistic_tests.exe : <install-type>EXE <location>. ;
+explicit statistic_tests ;

Modified: trunk/libs/random/test/statistic_tests.cpp
==============================================================================
--- trunk/libs/random/test/statistic_tests.cpp (original)
+++ trunk/libs/random/test/statistic_tests.cpp 2010-03-08 12:16:57 EST (Mon, 08 Mar 2010)
@@ -129,19 +129,18 @@
     using namespace boost;
     std::cout << "runs: up: " << std::flush;
     runs_experiment<true> r_up(classes);
- // generator_reference_t<RNG> gen_ref(rng);
- RNG& gen_ref(rng);
+
     check(run_experiment(test_distrib_chi_square,
- experiment_generator(r_up, gen_ref, n1), n2));
+ experiment_generator(r_up, rng, n1), n2));
     check(run_experiment(test_distrib_chi_square,
- experiment_generator(r_up, gen_ref, n1), 2*n2));
+ experiment_generator(r_up, rng, n1), 2*n2));
 
     std::cout << " down: " << std::flush;
     runs_experiment<false> r_down(classes);
     check(run_experiment(test_distrib_chi_square,
- experiment_generator(r_down, gen_ref, n1), n2));
+ experiment_generator(r_down, rng, n1), n2));
     check(run_experiment(test_distrib_chi_square,
- experiment_generator(r_down, gen_ref, n1), 2*n2));
+ experiment_generator(r_down, rng, n1), 2*n2));
 
     std::cout << std::endl;
   }
@@ -162,15 +161,24 @@
   template<class RNG>
   void run(RNG & rng, int n1, int n2)
   {
+ boost::math::uniform ud(
+ static_cast<double>((rng.min)()),
+ static_cast<double>((rng.max)()) +
+ (std::numeric_limits<typename RNG::result_type>::is_integer? 0.0 : 1.0));
+ run(rng, ud, n1, n2);
+ }
+
+ template<class RNG, class Dist>
+ void run(RNG & rng, const Dist& dist, int n1, int n2)
+ {
     using namespace boost;
     std::cout << "gaps: " << std::flush;
- gap_experiment gap(classes, 0.2, 0.8);
- // generator_reference_t<RNG> gen_ref(rng);
- RNG& gen_ref(rng);
+ gap_experiment gap(classes, dist, 0.2, 0.8);
+
     check(run_experiment(test_distrib_chi_square,
- experiment_generator(gap, gen_ref, n1), n2));
+ experiment_generator(gap, rng, n1), n2));
     check(run_experiment(test_distrib_chi_square,
- experiment_generator(gap, gen_ref, n1), 2*n2));
+ experiment_generator(gap, rng, n1), 2*n2));
 
     std::cout << std::endl;
   }
@@ -396,6 +404,7 @@
     
     ksdist_test.run(vgen, expected_dist, 5000, 250);
     rns_test.run(vgen, 100000, 250);
+ gp_test.run(vgen, expected_dist, 10000, 250);
     perm_test.run(vgen, 1200, 250);
 
     std::cout << std::endl;

Modified: trunk/libs/random/test/statistic_tests.hpp
==============================================================================
--- trunk/libs/random/test/statistic_tests.hpp (original)
+++ trunk/libs/random/test/statistic_tests.hpp 2010-03-08 12:16:57 EST (Mon, 08 Mar 2010)
@@ -226,19 +226,17 @@
 class gap_experiment : public experiment_base
 {
 public:
- gap_experiment(unsigned int classes, double alpha, double beta)
- : experiment_base(classes), alpha(alpha), beta(beta) { }
+ template<class Dist>
+ gap_experiment(unsigned int classes, const Dist & dist, double alpha, double beta)
+ : experiment_base(classes), alpha(alpha), beta(beta), low(quantile(dist, alpha)), high(quantile(dist, beta)) {}
   
- template<class UniformRandomNumberGenerator, class Counter>
- void run(UniformRandomNumberGenerator & f, Counter & count, int n) const
+ template<class NumberGenerator, class Counter>
+ void run(NumberGenerator & f, Counter & count, int n) const
   {
- typedef typename UniformRandomNumberGenerator::result_type result_type;
- double range = (f.max)() - (f.min)() + 1.0;
- result_type low = static_cast<result_type>(alpha * range);
- result_type high = static_cast<result_type>(beta * range);
+ typedef typename NumberGenerator::result_type result_type;
     unsigned int length = 0;
     for(int i = 0; i < n; ) {
- result_type value = f() - (f.min)();
+ result_type value = f();
       if(value < low || value > high)
         ++length;
       else {
@@ -258,6 +256,7 @@
   }
 private:
   double alpha, beta;
+ double low, high;
 };
 
 // poker experiment


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