1 // (C) Copyright John Maddock 2009.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //#define BOOST_MATH_INSTRUMENT
8 #include <boost/math/distributions/hypergeometric.hpp>
9 #include <boost/math/special_functions/trunc.hpp>
10 #include <boost/math/constants/constants.hpp>
11 #include <boost/lexical_cast.hpp>
12 #include <boost/random/uniform_int.hpp>
14 #include <boost/math/tools/test_data.hpp>
17 using namespace boost::math::tools;
21 struct hypergeometric_generator
30 mp_t> operator()(mp_t rN, mp_t rr, mp_t rn)
33 using namespace boost;
34 using namespace boost::math;
36 if((rr > rN) || (rr < rn))
37 throw std::domain_error("");
43 boost::uniform_int<> ui((std::max)(0, n + r - N), (std::min)(n, r));
46 hypergeometric_distribution<mp_t> d(r, n, N);
49 if((p == 1) || (p == 0))
51 // trivial case, don't clutter up our table with it:
52 throw std::domain_error("");
55 mp_t cc = cdf(complement(d, k));
57 std::cout << "N = " << N << " r = " << r << " n = " << n << " PDF = " << p << " CDF = " << c << " CCDF = " << cc << std::endl;
59 return boost::math::make_tuple(r, n, N, k, p, c, cc);
61 catch(const std::exception& e)
63 std::cout << e.what() << std::endl;
64 throw std::domain_error("");
69 int main(int argc, char*argv [])
72 parameter_info<mp_t> arg1, arg2, arg3;
75 std::cout << "Welcome.\n"
76 "This program will generate spot tests hypergeoemtric distribution:\n";
78 arg1 = make_power_param(mp_t(0), 1, 21);
79 arg2 = make_power_param(mp_t(0), 1, 21);
80 arg3 = make_power_param(mp_t(0), 1, 21);
82 arg1.type |= dummy_param;
83 arg2.type |= dummy_param;
84 arg3.type |= dummy_param;
86 data.insert(hypergeometric_generator(), arg1, arg2, arg3);
88 line = "hypergeometric_dist_data2.ipp";
89 std::ofstream ofs(line.c_str());
90 ofs << std::scientific << std::setprecision(40);
91 write_code(ofs, data, "hypergeometric_dist_data2");