From e0737c56c1e384e05064a0c6e1ac46979371041b Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 19 Dec 2018 22:58:32 +0100 Subject: New upstream version 2.0.0+repack --- boost/libs/math/tools/hypergeometric_dist_data.cpp | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 boost/libs/math/tools/hypergeometric_dist_data.cpp (limited to 'boost/libs/math/tools/hypergeometric_dist_data.cpp') diff --git a/boost/libs/math/tools/hypergeometric_dist_data.cpp b/boost/libs/math/tools/hypergeometric_dist_data.cpp new file mode 100644 index 00000000..55352f03 --- /dev/null +++ b/boost/libs/math/tools/hypergeometric_dist_data.cpp @@ -0,0 +1,95 @@ +// (C) Copyright John Maddock 2009. +// Use, modification and distribution are subject to 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) + +//#define BOOST_MATH_INSTRUMENT + +#include +#include +#include +#include +#include +#include +#include +#include "mp_t.hpp" + +using namespace boost::math::tools; + +std::mt19937 rnd; + +struct hypergeometric_generator +{ + boost::math::tuple< + mp_t, + mp_t, + mp_t, + mp_t, + mp_t, + mp_t, + mp_t> operator()(mp_t rN, mp_t rr, mp_t rn) + { + using namespace std; + using namespace boost; + using namespace boost::math; + + if((rr > rN) || (rr < rn)) + throw std::domain_error(""); + + try{ + int N = itrunc(rN); + int r = itrunc(rr); + int n = itrunc(rn); + boost::uniform_int<> ui((std::max)(0, n + r - N), (std::min)(n, r)); + int k = ui(rnd); + + hypergeometric_distribution d(r, n, N); + + mp_t p = pdf(d, k); + if((p == 1) || (p == 0)) + { + // trivial case, don't clutter up our table with it: + throw std::domain_error(""); + } + mp_t c = cdf(d, k); + mp_t cc = cdf(complement(d, k)); + + std::cout << "N = " << N << " r = " << r << " n = " << n << " PDF = " << p << " CDF = " << c << " CCDF = " << cc << std::endl; + + return boost::math::make_tuple(r, n, N, k, p, c, cc); + } + catch(const std::exception& e) + { + std::cout << e.what() << std::endl; + throw std::domain_error(""); + } + } +}; + +int main(int argc, char*argv []) +{ + std::string line; + parameter_info arg1, arg2, arg3; + test_data data; + + std::cout << "Welcome.\n" + "This program will generate spot tests hypergeoemtric distribution:\n"; + + arg1 = make_power_param(mp_t(0), 1, 21); + arg2 = make_power_param(mp_t(0), 1, 21); + arg3 = make_power_param(mp_t(0), 1, 21); + + arg1.type |= dummy_param; + arg2.type |= dummy_param; + arg3.type |= dummy_param; + + data.insert(hypergeometric_generator(), arg1, arg2, arg3); + + line = "hypergeometric_dist_data2.ipp"; + std::ofstream ofs(line.c_str()); + ofs << std::scientific << std::setprecision(40); + write_code(ofs, data, "hypergeometric_dist_data2"); + + return 0; +} + -- cgit v1.2.3