ibeta_derivative_data.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // (C) Copyright John Maddock 2006.
  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)
  5. #include <boost/math/special_functions/gamma.hpp>
  6. #include <boost/math/special_functions/beta.hpp>
  7. #include <boost/math/constants/constants.hpp>
  8. #include <boost/lexical_cast.hpp>
  9. #include <fstream>
  10. #include <map>
  11. #include <boost/math/tools/test_data.hpp>
  12. #include <boost/random.hpp>
  13. #include "mp_t.hpp"
  14. using namespace boost::math::tools;
  15. using namespace boost::math;
  16. using namespace std;
  17. #include <libs/math/test/table_type.hpp>
  18. #define T double
  19. #define SC_(x) static_cast<double>(x)
  20. #include <libs/math/test/ibeta_int_data.ipp>
  21. int main(int, char* [])
  22. {
  23. std::cout << "Enter name of test data file [default=ibeta_derivative_data.ipp]";
  24. std::string line;
  25. std::getline(std::cin, line);
  26. boost::algorithm::trim(line);
  27. if(line == "")
  28. line = "ibeta_derivative_data.ipp";
  29. std::ofstream ofs(line.c_str());
  30. ofs << std::scientific << std::setprecision(40);
  31. ofs <<
  32. "// (C) Copyright John Maddock 2006.\n"
  33. "// Use, modification and distribution are subject to the\n"
  34. "// Boost Software License, Version 1.0. (See accompanying file\n"
  35. "// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\n"
  36. "\n\n"
  37. "static const boost::array<boost::array<typename table_type<T>::type, 4>, " << ibeta_int_data.size() << "> ibeta_derivative_small_data = { {\n";
  38. for(unsigned i = 0; i < ibeta_int_data.size(); ++i)
  39. {
  40. mp_t a(ibeta_int_data[i][0]);
  41. mp_t b(ibeta_int_data[i][1]);
  42. mp_t x(ibeta_int_data[i][2]);
  43. std::cout << a << std::endl;
  44. std::cout << b << std::endl;
  45. std::cout << x << std::endl;
  46. mp_t bet = exp(boost::math::lgamma(a) + boost::math::lgamma(b) - boost::math::lgamma(a + b));
  47. mp_t d = pow(1 - x, b - 1) * pow(x, a - 1) / bet;
  48. ofs << "{{ SC_(" << a << "), SC_(" << b << "), SC_(" << x << "), SC_(" << d << ") }}\n";
  49. }
  50. ofs << "}};\n\n";
  51. return 0;
  52. }