2
0
mirror of https://github.com/boostorg/random.git synced 2026-01-19 04:22:17 +00:00

Fix inspection failures for the Random library

[SVN r60359]
This commit is contained in:
Steven Watanabe
2010-03-08 17:55:21 +00:00
parent a0be67a5fb
commit ccc442d6c8
20 changed files with 175 additions and 53 deletions

View File

@@ -3,7 +3,7 @@
# Copyright (c) 2009
# Steven Watanabe
#
# Distributed under the Boost Sofware License, Version 1.0. (See
# 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)

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[section Introduction]
Random numbers are required in a number of different problem domains, such as

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[table Distributions (Linux)
[[\[M rn/sec\]][minstd_rand][kreutzer1986][mt19937][lagged_fibonacci607]]
[[uniform_int][31.25][30.581][11.5607][16.0514]]

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[table Distributions (Windows)
[[\[M rn/sec\]][minstd_rand][kreutzer1986][mt19937][lagged_fibonacci607]]
[[uniform_int][14.7449][27.465][6.65292][28.5714]]

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
In addition to the [link boost_random.reference.generators random number generators],
this library provides distribution functions which map one distribution
(often a uniform distribution provided by some generator) to another.

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[template rand48_speed[] 68%]
[template lrand48_run_time_speed[] 12%]
[template minstd_rand0_speed[] 32%]

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[table Basic Generators (Linux)
[[generator] [M rn/sec] [time per random number \[nsec\]] [relative speed compared to fastest \[percent\]]]
[[rand48][312.5][3.2][100%]]

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[table Basic Generators (Windows)
[[generator] [M rn/sec] [time per random number \[nsec\]] [relative speed compared to fastest \[percent\]]]
[[rand48][98.5222][10.15][67%]]

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
This library provides several [prng pseudo-random number generators]. The
quality of a [prng pseudo random number generator] crucially depends on both
the algorithm and its parameters. This library implements the algorithms as

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[section Header <boost/nondet_random.hpp> Synopsis]
namespace boost {

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
For some people, performance of random number generation is an important
consideration when choosing a random number generator or a particular
distribution function. This page provides numerous performance tests with

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[template rand48_speed[] 100%]
[template lrand48_run_time_speed[] 96%]
[template lrand48__C_library__speed[] 21%]

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[section Synopsis of miscellaneous decorators in header <boost/random.hpp>]
namespace boost {

View File

@@ -1,3 +1,11 @@
[/
/ Copyright (c) 2009 Steven Watanabe
/
/ 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)
]
[section Generating integers in a range]
[import ../example/die.cpp]

View File

@@ -1,3 +1,12 @@
// die.cpp
//
// Copyright (c) 2009
// Steven Watanabe
//
// 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)
//[die
/*`
For the source of this example see

View File

@@ -1,3 +1,12 @@
// weighted_die.cpp
//
// Copyright (c) 2009
// Steven Watanabe
//
// 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)
//[weighted_die
/*`
For the source of this example see

View File

@@ -111,7 +111,7 @@ const char * const boost::random_device::default_token = "/dev/urandom";
#if defined(__GNUC__) && defined(_CXXRT_STD_NAME)
// I have severe difficulty to get the POSIX includes to work with
// -fhonor-std and Dietmar Kühl's standard C++ library. Hack around that
// -fhonor-std and Dietmar Kuhl's standard C++ library. Hack around that
// problem for now.
extern "C" {
static const int O_RDONLY = 0;

View File

@@ -163,7 +163,7 @@ INSTANT(boost::mt11213b)
#endif
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T)
// testcase by Mario R<EFBFBD>tti
// testcase by Mario Rutti
class ruetti_gen
{
public:

View File

@@ -41,7 +41,7 @@ class test_base
{
protected:
explicit test_base(test_environment & env) : environment(env) { }
void check(double val) const;
void check_(double val) const;
private:
test_environment & environment;
};
@@ -62,9 +62,9 @@ public:
std::cout << "equidistribution: " << std::flush;
equidistribution_experiment equi(classes);
variate_generator<RNG&, uniform_smallint<> > uint_linear(rng, uniform_smallint<>(0, classes-1));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(equi, uint_linear, n1), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(equi, uint_linear, n1), 2*n2));
std::cout << " 2D: " << std::flush;
@@ -72,9 +72,9 @@ public:
unsigned int root = static_cast<unsigned int>(std::sqrt(double(classes)));
assert(root * root == classes);
variate_generator<RNG&, uniform_smallint<> > uint_square(rng, uniform_smallint<>(0, root-1));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(equi_2d, uint_square, n1), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(equi_2d, uint_square, n1), 2*n2));
std::cout << std::endl;
}
@@ -104,9 +104,9 @@ public:
using namespace boost;
std::cout << "KS: " << std::flush;
kolmogorov_experiment ks(n1);
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
ks_experiment_generator(ks, rng, dist), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
ks_experiment_generator(ks, rng, dist), 2*n2));
std::cout << std::endl;
}
@@ -130,16 +130,16 @@ public:
std::cout << "runs: up: " << std::flush;
runs_experiment<true> r_up(classes);
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(r_up, rng, n1), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
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,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(r_down, rng, n1), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(r_down, rng, n1), 2*n2));
std::cout << std::endl;
@@ -175,9 +175,9 @@ public:
std::cout << "gaps: " << std::flush;
gap_experiment gap(classes, dist, 0.2, 0.8);
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(gap, rng, n1), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(gap, rng, n1), 2*n2));
std::cout << std::endl;
@@ -203,9 +203,9 @@ public:
std::cout << "poker: " << std::flush;
poker_experiment poker(8, classes);
variate_generator<RNG&, uniform_smallint<> > usmall(rng, uniform_smallint<>(0, 7));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(poker, usmall, n1), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(poker, usmall, n1), 2*n2));
std::cout << std::endl;
}
@@ -231,9 +231,9 @@ public:
coupon_collector_experiment coupon(5, classes);
variate_generator<RNG&, uniform_smallint<> > usmall(rng, uniform_smallint<>(0, 4));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(coupon, usmall, n1), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(coupon, usmall, n1), 2*n2));
std::cout << std::endl;
}
@@ -261,9 +261,9 @@ public:
// generator_reference_t<RNG> gen_ref(rng);
RNG& gen_ref(rng);
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(perm, gen_ref, n1), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(perm, gen_ref, n1), 2*n2));
std::cout << std::endl;
}
@@ -287,8 +287,8 @@ public:
using namespace boost;
std::cout << "maximum-of-t: " << std::flush;
maximum_experiment<RNG> mx(rng, n1, 5);
check(run_experiment(test_distrib_chi_square, mx, n2));
check(run_experiment(test_distrib_chi_square, mx, 2*n2));
check_(run_experiment(test_distrib_chi_square, mx, n2));
check_(run_experiment(test_distrib_chi_square, mx, 2*n2));
std::cout << std::endl;
}
private:
@@ -310,9 +310,9 @@ public:
std::cout << "birthday spacing: " << std::flush;
boost::variate_generator<RNG&, boost::uniform_int<> > uni(rng, boost::uniform_int<>(0, (1<<25)-1));
birthday_spacing_experiment bsp(4, 512, (1<<25));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(bsp, uni, n1), n2));
check(run_experiment(test_distrib_chi_square,
check_(run_experiment(test_distrib_chi_square,
experiment_generator(bsp, uni, n1), 2*n2));
std::cout << std::endl;
}
@@ -365,7 +365,7 @@ public:
return result;
}
bool check(double chi_square_value) const
bool check_(double chi_square_value) const
{
return check_confidence(chi_square_value, confidence_chi_square_quantil);
}
@@ -425,9 +425,9 @@ private:
birthday_test bday_test;
};
void test_base::check(double val) const
void test_base::check_(double val) const
{
environment.check(val);
environment.check_(val);
}
class program_args
@@ -439,7 +439,7 @@ public:
names.insert(argv + 1, argv + argc);
}
}
bool check(const std::string & test_name) const
bool check_(const std::string & test_name) const
{
return(names.empty() || names.find(test_name) != names.end());
}
@@ -453,7 +453,7 @@ int main(int argc, char* argv[])
test_environment env(0.99);
#define TEST(name) \
if(args.check(#name)) \
if(args.check_(#name)) \
env.run_test<boost::name>(#name)
TEST(minstd_rand0);
@@ -487,17 +487,17 @@ int main(int argc, char* argv[])
TEST(ranlux64_3_01);
TEST(ranlux64_4_01);
if(args.check("normal"))
if(args.check_("normal"))
env.run_test<boost::mt19937>("normal", boost::normal_distribution<>(), boost::math::normal());
if(args.check("triangle"))
if(args.check_("triangle"))
env.run_test<boost::mt19937>("triangle", boost::triangle_distribution<>(0, 1, 3), boost::math::triangular(0, 1, 3));
if(args.check("cauchy"))
if(args.check_("cauchy"))
env.run_test<boost::mt19937>("cauchy", boost::cauchy_distribution<>(), boost::math::cauchy());
if(args.check("gamma"))
if(args.check_("gamma"))
env.run_test<boost::mt19937>("gamma", boost::gamma_distribution<>(1), boost::math::gamma_distribution<>(1));
if(args.check("exponential"))
if(args.check_("exponential"))
env.run_test<boost::mt19937>("exponential", boost::exponential_distribution<>(), boost::math::exponential());
if(args.check("lognormal"))
if(args.check_("lognormal"))
env.run_test<boost::mt19937>("lognormal", boost::lognormal_distribution<>(1, 1),
boost::math::lognormal(std::log(1.0/std::sqrt(2.0)), std::sqrt(std::log(2.0))));
}

View File

@@ -44,45 +44,45 @@
*/
// own run
bool check(unsigned long x, const boost::mt11213b&) { return x == 3809585648U; }
bool check_(unsigned long x, const boost::mt11213b&) { return x == 3809585648U; }
// validation by experiment from mt19937.c
bool check(unsigned long x, const boost::mt19937&) { return x == 4123659995U; }
bool check_(unsigned long x, const boost::mt19937&) { return x == 4123659995U; }
// validation values from the publications
bool check(int x, const boost::minstd_rand0&) { return x == 1043618065; }
bool check_(int x, const boost::minstd_rand0&) { return x == 1043618065; }
// validation values from the publications
bool check(int x, const boost::minstd_rand&) { return x == 399268537; }
bool check_(int x, const boost::minstd_rand&) { return x == 399268537; }
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T)
// by experiment from lrand48()
bool check(unsigned long x, const boost::rand48&) { return x == 1993516219; }
bool check_(unsigned long x, const boost::rand48&) { return x == 1993516219; }
#endif
// ????
bool check(unsigned long x, const boost::taus88&) { return x == 3535848941U; }
bool check_(unsigned long x, const boost::taus88&) { return x == 3535848941U; }
// ????
bool check(int x, const boost::ecuyer1988&) { return x == 2060321752; }
bool check_(int x, const boost::ecuyer1988&) { return x == 2060321752; }
// validation by experiment from Harry Erwin's generator.h (private e-mail)
bool check(unsigned int x, const boost::kreutzer1986&) { return x == 139726; }
bool check_(unsigned int x, const boost::kreutzer1986&) { return x == 139726; }
bool check(double x, const boost::lagged_fibonacci607&) { return std::abs(x-0.401269) < 1e-5; }
bool check_(double x, const boost::lagged_fibonacci607&) { return std::abs(x-0.401269) < 1e-5; }
// principal operation validated with CLHEP, values by experiment
bool check(unsigned long x, const boost::ranlux3&) { return x == 5957620; }
bool check(unsigned long x, const boost::ranlux4&) { return x == 8587295; }
bool check_(unsigned long x, const boost::ranlux3&) { return x == 5957620; }
bool check_(unsigned long x, const boost::ranlux4&) { return x == 8587295; }
bool check(float x, const boost::ranlux3_01&)
bool check_(float x, const boost::ranlux3_01&)
{ return std::abs(x-5957620/std::pow(2.0f,24)) < 1e-6; }
bool check(float x, const boost::ranlux4_01&)
bool check_(float x, const boost::ranlux4_01&)
{ return std::abs(x-8587295/std::pow(2.0f,24)) < 1e-6; }
bool check(double x, const boost::ranlux64_3_01&)
bool check_(double x, const boost::ranlux64_3_01&)
{ return std::abs(x-0.838413) < 1e-6; }
bool check(double x, const boost::ranlux64_4_01&)
bool check_(double x, const boost::ranlux64_4_01&)
{ return std::abs(x-0.59839) < 1e-6; }
template<class PRNG>
@@ -94,7 +94,7 @@ void validate(const std::string & name, const PRNG &)
rng();
typename PRNG::result_type val = rng();
// make sure the validation function is a static member
bool result = check(val, rng);
bool result = check_(val, rng);
// allow for a simple eyeball check for MSVC instantiation brokenness
// (if the numbers for all generators are the same, it's obviously broken)