Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64275 - in sandbox/SOC/2010/quasi_random: boost/random/detail libs/random/test
From: jvd_at_[hidden]
Date: 2010-07-22 19:01:39


Author: qrng
Date: 2010-07-22 19:01:38 EDT (Thu, 22 Jul 2010)
New Revision: 64275
URL: http://svn.boost.org/trac/boost/changeset/64275

Log:
Added a non transforming distribution, changed tests to make use of result_of

Added:
   sandbox/SOC/2010/quasi_random/boost/random/detail/identity_distribution.hpp (contents, props changed)
Removed:
   sandbox/SOC/2010/quasi_random/libs/random/test/identity_distribution.hpp
Text files modified:
   sandbox/SOC/2010/quasi_random/libs/random/test/d_star.hpp | 31 ++++++++++++++++---------------
   sandbox/SOC/2010/quasi_random/libs/random/test/discrepancy.cpp | 31 ++++++++++++++++++-------------
   2 files changed, 34 insertions(+), 28 deletions(-)

Added: sandbox/SOC/2010/quasi_random/boost/random/detail/identity_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/quasi_random/boost/random/detail/identity_distribution.hpp 2010-07-22 19:01:38 EDT (Thu, 22 Jul 2010)
@@ -0,0 +1,35 @@
+// Copyright Justinas Vygintas Daugmaudis, 2010.
+// Use, modification and distribution is subject to the
+// Boost Software License, Version 1.0. (See accompanying
+// file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
+
+#ifndef BOOST_IDENTITY_DISTRIBUTION_HPP_INCLUDED
+#define BOOST_IDENTITY_DISTRIBUTION_HPP_INCLUDED
+
+namespace boost {
+
+namespace random {
+
+namespace detail {
+
+// To be used when no transformation of a sequence is required
+struct identity_distribution
+{
+ // makes compatible with result_of<>
+ template<typename FArgs>
+ struct result;
+
+ template<typename F, typename Engine>
+ struct result<F(Engine)>
+ {
+ typedef typename Engine::result_type type;
+ };
+
+ template<typename Engine>
+ typename Engine::result_type operator()(Engine& gen) const
+ { return gen(); }
+};
+
+}}} // namespace boost::random::detail
+
+#endif // BOOST_IDENTITY_DISTRIBUTION_HPP_INCLUDED

Modified: sandbox/SOC/2010/quasi_random/libs/random/test/d_star.hpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/libs/random/test/d_star.hpp (original)
+++ sandbox/SOC/2010/quasi_random/libs/random/test/d_star.hpp 2010-07-22 19:01:38 EDT (Thu, 22 Jul 2010)
@@ -14,6 +14,7 @@
 #include <boost/pool/pool.hpp>
 #include <boost/shared_array.hpp>
 #include <boost/random/uniform_real.hpp>
+#include <boost/utility/result_of.hpp>
 
 // The time required to compute the star discrepancy of a sequence of points
 // in a multidimensional unit cube is prohibitive and the best known upper
@@ -413,8 +414,8 @@
   typedef std::pair<T, T> bounds_t;
 
   // Initialize point table
- template<typename QRNG, typename Distribution>
- star_discrepancy(QRNG& q, Distribution d, std::size_t dimension, std::size_t n, T eps)
+ template<typename Engine, typename Distribution>
+ star_discrepancy(Engine& eng, Distribution d, std::size_t dimension, std::size_t n, T eps)
     : dim(dimension) // for non-QRNGs q.dimension() is malformed
     , n_elem(n)
     , epsilon(eps)
@@ -423,7 +424,7 @@
     // All points must be bounded by the unit hypercube.
     for(std::size_t i = 0; i != dim * n_elem; ++i)
     {
- T value = d(q);
+ T value = d(eng);
       if( value < T(0) || value > T(1) )
         boost::throw_exception( std::invalid_argument("d_star") );
       points[i] = value;
@@ -654,33 +655,33 @@
 }
 
 // Accepts a pseudo-random number generator
-template<typename PRNG, typename Distribution>
+template<typename Engine, typename Distribution>
 inline typename detail::star_discrepancy<
- typename Distribution::result_type
+ typename boost::result_of<Distribution(Engine)>::type
>::bounds_t
-d_star(PRNG& p, Distribution d, std::size_t dimension,
- std::size_t n, typename Distribution::result_type epsilon)
+d_star(Engine& eng, Distribution d, std::size_t dimension, std::size_t n,
+ typename boost::result_of<Distribution(Engine)>::type epsilon)
 {
- typedef typename Distribution::result_type value_t;
- detail::star_discrepancy<value_t> discr(p, d, dimension, n, epsilon);
+ typedef typename boost::result_of<Distribution(Engine)>::type value_t;
+ detail::star_discrepancy<value_t> discr(eng, d, dimension, n, epsilon);
   return discr.compute();
 }
 
 // Accepts a quasi-random number generator and distribution
-template<typename QRNG, typename Distribution>
+template<typename QEngine, typename Distribution>
 inline typename detail::star_discrepancy<
- typename Distribution::result_type
+ typename boost::result_of<Distribution(QEngine)>::type
>::bounds_t
-d_star(QRNG& q, Distribution d,
- std::size_t n, typename Distribution::result_type epsilon)
+d_star(QEngine& q, Distribution d, std::size_t n,
+ typename boost::result_of<Distribution(QEngine)>::type epsilon)
 {
   return d_star(q, d, q.dimension(), n, epsilon);
 }
 
 // Accepts a quasi-random number generator; distribution is uniform_real<T>
-template<typename QRNG, typename T>
+template<typename QEngine, typename T>
 inline typename detail::star_discrepancy<T>::bounds_t
-d_star(QRNG& q, std::size_t n, T epsilon)
+d_star(QEngine& q, std::size_t n, T epsilon)
 {
   return d_star(q, boost::uniform_real<T>(), n, epsilon);
 }

Modified: sandbox/SOC/2010/quasi_random/libs/random/test/discrepancy.cpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/libs/random/test/discrepancy.cpp (original)
+++ sandbox/SOC/2010/quasi_random/libs/random/test/discrepancy.cpp 2010-07-22 19:01:38 EDT (Thu, 22 Jul 2010)
@@ -4,7 +4,6 @@
 // file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
 
 #include "d_star.hpp"
-#include "identity_distribution.hpp"
 
 #include <boost/random/niederreiter_base2.hpp>
 #include <boost/random/sobol.hpp>
@@ -12,6 +11,10 @@
 
 #include <boost/random/mersenne_twister.hpp>
 
+#include <boost/random/detail/identity_distribution.hpp>
+
+#include <boost/utility/result_of.hpp>
+
 #define BOOST_TEST_MAIN
 #include <boost/test/unit_test.hpp>
 #include <boost/test/unit_test_log.hpp>
@@ -64,23 +67,25 @@
 
   std::pair<double, double> bounds = d_star(halton_seq, 0.01);
 
- BOOST_REQUIRE_CLOSE_FRACTION(bounds.first, 0.2666670000, 0.0001);
- BOOST_REQUIRE_CLOSE_FRACTION(bounds.second, 0.2724280122, 0.0001);
+ BOOST_REQUIRE_CLOSE(bounds.first, 0.2666670000, 0.0001);
+ BOOST_REQUIRE_CLOSE(bounds.second, 0.2724280122, 0.0001);
 }
 
 
-template<typename QRNG, typename Distribution, typename Bounds>
+template<typename QEngine, typename Distribution, typename Bounds>
 inline void check_discrepancy(const char* name,
     Distribution d,
- std::size_t n_vectors, typename Distribution::result_type eps,
+ std::size_t n_vectors,
+ typename boost::result_of<Distribution(QEngine)>::type epsilon,
     Bounds mersenne_twister_discrepancy)
 {
- QRNG q; // default-construct
+ QEngine q; // default-construct
 
   BOOST_TEST_MESSAGE( "Testing " << name << "[" << q.dimension() << "]" );
 
- Bounds qrng_discrepancy = d_star(q, d, n_vectors, eps);
- BOOST_CHECK( qrng_discrepancy < mersenne_twister_discrepancy );
+ Bounds qrng_discrepancy = d_star(q, d, n_vectors, epsilon);
+ BOOST_CHECK_LT( qrng_discrepancy.first, mersenne_twister_discrepancy.first );
+ BOOST_CHECK_LE( qrng_discrepancy.second, mersenne_twister_discrepancy.second );
 }
 
 template<std::size_t D>
@@ -118,7 +123,7 @@
   // Compare the discrepancy of quasi-random number generators against the Mersenne twister discrepancy
   UNIT_TEST_CHECK_QRNG_DISCREPANCY(niederreiter_base2_t, u);
   UNIT_TEST_CHECK_QRNG_DISCREPANCY(sobol_t, u);
- UNIT_TEST_CHECK_QRNG_DISCREPANCY(faure_t, identity_distribution<value_t>());
+ UNIT_TEST_CHECK_QRNG_DISCREPANCY(faure_t, boost::random::detail::identity_distribution());
 
 #undef UNIT_TEST_CHECK_QRNG_DISCREPANCY
 }
@@ -146,11 +151,11 @@
   compare_qrng_discrepancy<5>( 100, 0.06 );
   compare_qrng_discrepancy<6>( 60, 0.08 );
   compare_qrng_discrepancy<7>( 60, 0.15 );
- compare_qrng_discrepancy<8>( 60, 0.4 );
+ compare_qrng_discrepancy<8>( 100, 0.4 );
   compare_qrng_discrepancy<9> ( 60, 0.5 );
   compare_qrng_discrepancy<10>( 80, 0.3 ); // mersenne twister has good discrepancy from dim 10. :-)
   compare_qrng_discrepancy<11>( 500, 0.4 );
- compare_qrng_discrepancy<12>( 50, 0.5 );
+ compare_qrng_discrepancy<12>( 500, 0.5 );
 
   // etc.
 }
@@ -172,8 +177,8 @@
   niederreiter_base2_t q;
   std::pair<double, double> bounds = d_star(q, n_vectors, eps);
 
- BOOST_CHECK( bounds.first <= expected_discrepancy );
- BOOST_CHECK( expected_discrepancy <= bounds.second );
+ BOOST_CHECK_LE( bounds.first, expected_discrepancy );
+ BOOST_CHECK_LE( expected_discrepancy, bounds.second );
 }
 
 BOOST_AUTO_TEST_CASE( test_niederreiter_base_2_discrepancy )

Deleted: sandbox/SOC/2010/quasi_random/libs/random/test/identity_distribution.hpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/libs/random/test/identity_distribution.hpp 2010-07-22 19:01:38 EDT (Thu, 22 Jul 2010)
+++ (empty file)
@@ -1,19 +0,0 @@
-// Copyright Justinas Vygintas Daugmaudis, 2010.
-// Use, modification and distribution is subject to the
-// Boost Software License, Version 1.0. (See accompanying
-// file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
-
-#ifndef IDENTITY_DISTRIBUTION_HPP_INCLUDED
-#define IDENTITY_DISTRIBUTION_HPP_INCLUDED
-
-// To be used when no transformation of a sequence is required
-template<typename T = double>
-struct identity_distribution
-{
- typedef T result_type;
- template<typename Generator>
- result_type operator()(Generator& gen) const
- { return gen(); }
-};
-
-#endif // IDENTITY_DISTRIBUTION_HPP_INCLUDED


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