test_distributions.cpp 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. // Copyright John Maddock 2015.
  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. #ifdef _MSC_VER
  6. # pragma warning (disable : 4224)
  7. #endif
  8. #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
  9. #define DISTRIBUTIONS_TEST
  10. #include <boost/math/distributions.hpp>
  11. #include <boost/array.hpp>
  12. #include <boost/lexical_cast.hpp>
  13. #include "../../test/table_type.hpp"
  14. #include "table_helper.hpp"
  15. #include "performance.hpp"
  16. #include <iostream>
  17. #ifdef TEST_GSL
  18. #include <gsl/gsl_cdf.h>
  19. #endif
  20. class distribution_tester
  21. {
  22. std::string distro_name;
  23. static const double quantiles[19];
  24. double sum;
  25. struct param_info
  26. {
  27. std::vector<double> params;
  28. std::vector<double> x_values;
  29. };
  30. std::vector<param_info> tests;
  31. double sanitize_x(double x)
  32. {
  33. if(x > boost::math::tools::max_value<float>() / 2)
  34. return boost::math::tools::max_value<float>() / 2;
  35. if(x < -boost::math::tools::max_value<float>() / 2)
  36. return -boost::math::tools::max_value<float>() / 2;
  37. return x;
  38. }
  39. public:
  40. distribution_tester(const char* name) : distro_name(name), sum(0) {}
  41. template <class F>
  42. void add_test_case(F f)
  43. {
  44. tests.push_back(param_info());
  45. for(unsigned i = 0; i < sizeof(quantiles) / sizeof(quantiles[0]); ++i)
  46. {
  47. tests.back().x_values.push_back(sanitize_x(f(quantiles[i])));
  48. }
  49. }
  50. template <class F>
  51. void add_test_case(double p1, F f)
  52. {
  53. tests.push_back(param_info());
  54. tests.back().params.push_back(p1);
  55. for(unsigned i = 0; i < sizeof(quantiles) / sizeof(quantiles[0]); ++i)
  56. {
  57. tests.back().x_values.push_back(sanitize_x(f(p1, quantiles[i])));
  58. }
  59. }
  60. template <class F>
  61. void add_test_case(double p1, double p2, F f)
  62. {
  63. tests.push_back(param_info());
  64. tests.back().params.push_back(p1);
  65. tests.back().params.push_back(p2);
  66. for(unsigned i = 0; i < sizeof(quantiles) / sizeof(quantiles[0]); ++i)
  67. {
  68. tests.back().x_values.push_back(sanitize_x(f(p1, p2, quantiles[i])));
  69. }
  70. }
  71. template <class F>
  72. void add_test_case(double p1, double p2, double p3, F f)
  73. {
  74. tests.push_back(param_info());
  75. tests.back().params.push_back(p1);
  76. tests.back().params.push_back(p2);
  77. tests.back().params.push_back(p3);
  78. for(unsigned i = 0; i < sizeof(quantiles) / sizeof(quantiles[0]); ++i)
  79. {
  80. tests.back().x_values.push_back(sanitize_x(f(p1, p2, p3, quantiles[i])));
  81. }
  82. }
  83. enum
  84. {
  85. main_table = 1,
  86. boost_only_table = 2,
  87. both_tables = 3
  88. };
  89. template <class F>
  90. void run_timed_tests(F f, std::string sub_name, std::string column, bool p_value = false, int where = main_table)
  91. {
  92. std::cout << "Testing " << distro_name + " (" + std::string(sub_name) + ")" << " with library " << column << std::endl;
  93. try{
  94. double t = 0;
  95. unsigned repeats = 1;
  96. unsigned data_size;
  97. do{
  98. data_size = 0;
  99. stopwatch<boost::chrono::high_resolution_clock> w;
  100. for(unsigned count = 0; count < repeats; ++count)
  101. {
  102. for(unsigned i = 0; i < tests.size(); ++i)
  103. {
  104. for(unsigned j = 0; j < tests[i].x_values.size(); ++j)
  105. {
  106. if((boost::math::isfinite)(tests[i].x_values[j]))
  107. sum += f(tests[i].params, p_value ? quantiles[j] : tests[i].x_values[j]);
  108. ++data_size;
  109. }
  110. }
  111. }
  112. t = boost::chrono::duration_cast<boost::chrono::duration<double>>(w.elapsed()).count();
  113. if(t < 0.5)
  114. repeats *= 2;
  115. } while(t < 0.5);
  116. static const std::string main_table_name = std::string("Distribution performance comparison with ") + compiler_name() + std::string(" on ") + platform_name();
  117. static const std::string boost_table_name = std::string("Distribution performance comparison for different performance options with ") + compiler_name() + std::string(" on ") + platform_name();
  118. if (where & 1)
  119. {
  120. report_execution_time(
  121. t / data_size,
  122. main_table_name,
  123. distro_name + " (" + std::string(sub_name) + ")",
  124. column);
  125. }
  126. if (where & 2)
  127. {
  128. report_execution_time(
  129. t / data_size,
  130. boost_table_name,
  131. distro_name + " (" + std::string(sub_name) + ")",
  132. column);
  133. }
  134. }
  135. catch(const std::exception& e)
  136. {
  137. std::cerr << "Aborting due to exception: " << e.what() << std::endl;
  138. std::cerr << "In " << distro_name + " (" + std::string(sub_name) + ")" << std::endl;
  139. report_execution_time(
  140. (std::numeric_limits<boost::uintmax_t>::max)(),
  141. std::string("Distribution performance comparison with ") + compiler_name() + std::string(" on ") + platform_name(),
  142. distro_name + " (" + std::string(sub_name) + ")",
  143. column);
  144. }
  145. }
  146. };
  147. const double distribution_tester::quantiles[19] =
  148. {
  149. 0.000001,
  150. 0.00001,
  151. 0.0001,
  152. 0.001,
  153. 0.01,
  154. 0.1,
  155. 0.2,
  156. 0.3,
  157. 0.4,
  158. 0.5,
  159. 0.6,
  160. 0.7,
  161. 0.8,
  162. 0.9,
  163. 0.99,
  164. 0.999,
  165. 0.9999,
  166. 0.99999,
  167. 0.999999
  168. };
  169. template <class D>
  170. struct three_param_quantile
  171. {
  172. template <class T, class U, class V, class X>
  173. double operator()(T x, U y, V z, X q)const
  174. {
  175. return quantile(D(x, y, z), q);
  176. }
  177. };
  178. template <class D>
  179. struct two_param_quantile
  180. {
  181. template <class T, class U, class V>
  182. double operator()(T x, U y, V q)const
  183. {
  184. return quantile(D(x, y), q);
  185. }
  186. };
  187. template <class D>
  188. struct one_param_quantile
  189. {
  190. template <class T, class V>
  191. double operator()(T x, V q)const
  192. {
  193. return quantile(D(x), q);
  194. }
  195. };
  196. template <template <class T, class U> class D>
  197. void test_boost_1_param(distribution_tester& tester)
  198. {
  199. //
  200. // Define some custom policies to test:
  201. //
  202. typedef boost::math::policies::policy<> default_policy;
  203. typedef boost::math::policies::policy<boost::math::policies::promote_double<false> > no_promote_double_policy;
  204. typedef boost::math::policies::policy<boost::math::policies::promote_double<false>, boost::math::policies::digits10<10> > no_promote_double_10_digits_policy;
  205. typedef boost::math::policies::policy<boost::math::policies::promote_float<false> > no_promote_float_policy;
  206. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<double, default_policy>(v[0]), x); }, "PDF", boost_name(), false, distribution_tester::both_tables);
  207. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<double, default_policy>(v[0]), x); }, "CDF", boost_name(), false, distribution_tester::both_tables);
  208. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<double, default_policy>(v[0]), x); }, "quantile", boost_name(), true, distribution_tester::both_tables);
  209. if(sizeof(double) != sizeof(long double))
  210. {
  211. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<double, no_promote_double_policy>(v[0]), x); }, "PDF", "Boost[br]promote_double<false>", false, distribution_tester::both_tables);
  212. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<double, no_promote_double_policy>(v[0]), x); }, "CDF", "Boost[br]promote_double<false>", false, distribution_tester::both_tables);
  213. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<double, no_promote_double_policy>(v[0]), x); }, "quantile", "Boost[br]promote_double<false>", true, distribution_tester::both_tables);
  214. }
  215. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<double, no_promote_double_10_digits_policy>(v[0]), x); }, "PDF", "Boost[br]promote_double<false>[br]digits10<10>", false, distribution_tester::boost_only_table);
  216. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<double, no_promote_double_10_digits_policy>(v[0]), x); }, "CDF", "Boost[br]promote_double<false>[br]digits10<10>", false, distribution_tester::boost_only_table);
  217. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<double, no_promote_double_10_digits_policy>(v[0]), x); }, "quantile", "Boost[br]promote_double<false>[br]digits10<10>", true, distribution_tester::boost_only_table);
  218. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<float, no_promote_float_policy>(static_cast<float>(v[0])), static_cast<float>(x)); }, "PDF", "Boost[br]float[br]promote_float<false>", false, distribution_tester::boost_only_table);
  219. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<float, no_promote_float_policy>(static_cast<float>(v[0])), static_cast<float>(x)); }, "CDF", "Boost[br]float[br]promote_float<false>", false, distribution_tester::boost_only_table);
  220. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<float, no_promote_float_policy>(static_cast<float>(v[0])), static_cast<float>(x)); }, "quantile", "Boost[br]float[br]promote_float<false>", true, distribution_tester::boost_only_table);
  221. }
  222. template <template <class T, class U> class D>
  223. void test_boost_2_param(distribution_tester& tester)
  224. {
  225. //
  226. // Define some custom policies to test:
  227. //
  228. typedef boost::math::policies::policy<> default_policy;
  229. typedef boost::math::policies::policy<boost::math::policies::promote_double<false> > no_promote_double_policy;
  230. typedef boost::math::policies::policy<boost::math::policies::promote_double<false>, boost::math::policies::digits10<10> > no_promote_double_10_digits_policy;
  231. typedef boost::math::policies::policy<boost::math::policies::promote_float<false> > no_promote_float_policy;
  232. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<double, default_policy>(v[0], v[1]), x); }, "PDF", boost_name(), false, distribution_tester::both_tables);
  233. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<double, default_policy>(v[0], v[1]), x); }, "CDF", boost_name(), false, distribution_tester::both_tables);
  234. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<double, default_policy>(v[0], v[1]), x); }, "quantile", boost_name(), true, distribution_tester::both_tables);
  235. if(sizeof(double) != sizeof(long double))
  236. {
  237. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<double, no_promote_double_policy>(v[0], v[1]), x); }, "PDF", "Boost[br]promote_double<false>", false, distribution_tester::both_tables);
  238. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<double, no_promote_double_policy>(v[0], v[1]), x); }, "CDF", "Boost[br]promote_double<false>", false, distribution_tester::both_tables);
  239. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<double, no_promote_double_policy>(v[0], v[1]), x); }, "quantile", "Boost[br]promote_double<false>", true, distribution_tester::both_tables);
  240. }
  241. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<double, no_promote_double_10_digits_policy>(v[0], v[1]), x); }, "PDF", "Boost[br]promote_double<false>[br]digits10<10>", false, distribution_tester::boost_only_table);
  242. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<double, no_promote_double_10_digits_policy>(v[0], v[1]), x); }, "CDF", "Boost[br]promote_double<false>[br]digits10<10>", false, distribution_tester::boost_only_table);
  243. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<double, no_promote_double_10_digits_policy>(v[0], v[1]), x); }, "quantile", "Boost[br]promote_double<false>[br]digits10<10>", true, distribution_tester::boost_only_table);
  244. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<float, no_promote_float_policy>(static_cast<float>(v[0]), static_cast<float>(v[1])), static_cast<float>(x)); }, "PDF", "Boost[br]float[br]promote_float<false>", false, distribution_tester::boost_only_table);
  245. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<float, no_promote_float_policy>(static_cast<float>(v[0]), static_cast<float>(v[1])), static_cast<float>(x)); }, "CDF", "Boost[br]float[br]promote_float<false>", false, distribution_tester::boost_only_table);
  246. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<float, no_promote_float_policy>(static_cast<float>(v[0]), static_cast<float>(v[1])), static_cast<float>(x)); }, "quantile", "Boost[br]float[br]promote_float<false>", true, distribution_tester::boost_only_table);
  247. }
  248. template <template <class T, class U> class D>
  249. void test_boost_3_param(distribution_tester& tester)
  250. {
  251. //
  252. // Define some custom policies to test:
  253. //
  254. typedef boost::math::policies::policy<> default_policy;
  255. typedef boost::math::policies::policy<boost::math::policies::promote_double<false> > no_promote_double_policy;
  256. typedef boost::math::policies::policy<boost::math::policies::promote_double<false>, boost::math::policies::digits10<10> > no_promote_double_10_digits_policy;
  257. typedef boost::math::policies::policy<boost::math::policies::promote_float<false> > no_promote_float_policy;
  258. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<double, default_policy>(v[0], v[1], v[2]), x); }, "PDF", boost_name(), false, distribution_tester::both_tables);
  259. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<double, default_policy>(v[0], v[1], v[2]), x); }, "CDF", boost_name(), false, distribution_tester::both_tables);
  260. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<double, default_policy>(v[0], v[1], v[2]), x); }, "quantile", boost_name(), true, distribution_tester::both_tables);
  261. if(sizeof(double) != sizeof(long double))
  262. {
  263. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<double, no_promote_double_policy>(v[0], v[1], v[2]), x); }, "PDF", "Boost[br]promote_double<false>", false, distribution_tester::both_tables);
  264. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<double, no_promote_double_policy>(v[0], v[1], v[2]), x); }, "CDF", "Boost[br]promote_double<false>", false, distribution_tester::both_tables);
  265. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<double, no_promote_double_policy>(v[0], v[1], v[2]), x); }, "quantile", "Boost[br]promote_double<false>", true, distribution_tester::both_tables);
  266. }
  267. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<double, no_promote_double_10_digits_policy>(v[0], v[1], v[2]), x); }, "PDF", "Boost[br]promote_double<false>[br]digits10<10>", false, distribution_tester::boost_only_table);
  268. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<double, no_promote_double_10_digits_policy>(v[0], v[1], v[2]), x); }, "CDF", "Boost[br]promote_double<false>[br]digits10<10>", false, distribution_tester::boost_only_table);
  269. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<double, no_promote_double_10_digits_policy>(v[0], v[1], v[2]), x); }, "quantile", "Boost[br]promote_double<false>[br]digits10<10>", true, distribution_tester::boost_only_table);
  270. tester.run_timed_tests([](const std::vector<double>& v, double x){ return pdf(D<float, no_promote_float_policy>(static_cast<float>(v[0]), static_cast<float>(v[1]), static_cast<float>(v[2])), static_cast<float>(x)); }, "PDF", "Boost[br]float[br]promote_float<false>", false, distribution_tester::boost_only_table);
  271. tester.run_timed_tests([](const std::vector<double>& v, double x){ return cdf(D<float, no_promote_float_policy>(static_cast<float>(v[0]), static_cast<float>(v[1]), static_cast<float>(v[2])), static_cast<float>(x)); }, "CDF", "Boost[br]float[br]promote_float<false>", false, distribution_tester::boost_only_table);
  272. tester.run_timed_tests([](const std::vector<double>& v, double x){ return quantile(D<float, no_promote_float_policy>(static_cast<float>(v[0]), static_cast<float>(v[1]), static_cast<float>(v[2])), static_cast<float>(x)); }, "quantile", "Boost[br]float[br]promote_float<false>", true, distribution_tester::boost_only_table);
  273. }
  274. int main()
  275. {
  276. try {
  277. //
  278. // Normal:
  279. //
  280. distribution_tester n("Normal");
  281. n.add_test_case(0, 1, two_param_quantile<boost::math::normal_distribution<> >());
  282. n.add_test_case(20, 20, two_param_quantile<boost::math::normal_distribution<> >());
  283. n.add_test_case(-20, 0.0125, two_param_quantile<boost::math::normal_distribution<> >());
  284. test_boost_2_param<boost::math::normal_distribution>(n);
  285. distribution_tester arcsine("ArcSine");
  286. arcsine.add_test_case(0, 1, two_param_quantile<boost::math::arcsine_distribution<> >());
  287. arcsine.add_test_case(20, 500, two_param_quantile<boost::math::arcsine_distribution<> >());
  288. arcsine.add_test_case(-20, 100000, two_param_quantile<boost::math::arcsine_distribution<> >());
  289. test_boost_2_param<boost::math::arcsine_distribution>(arcsine);
  290. distribution_tester beta("Beta");
  291. beta.add_test_case(1, 4, two_param_quantile<boost::math::beta_distribution<> >());
  292. beta.add_test_case(20, 500, two_param_quantile<boost::math::beta_distribution<> >());
  293. beta.add_test_case(0.1, 0.01, two_param_quantile<boost::math::beta_distribution<> >());
  294. test_boost_2_param<boost::math::beta_distribution>(beta);
  295. distribution_tester binomial("Binomial");
  296. binomial.add_test_case(5, 0.125, two_param_quantile<boost::math::binomial_distribution<> >());
  297. binomial.add_test_case(200, 0.75, two_param_quantile<boost::math::binomial_distribution<> >());
  298. binomial.add_test_case(2000, 0.5, two_param_quantile<boost::math::binomial_distribution<> >());
  299. binomial.add_test_case(20000, 0.001, two_param_quantile<boost::math::binomial_distribution<> >());
  300. binomial.add_test_case(200000, 0.99, two_param_quantile<boost::math::binomial_distribution<> >());
  301. test_boost_2_param<boost::math::binomial_distribution>(binomial);
  302. distribution_tester cauchy("Cauchy");
  303. cauchy.add_test_case(0, 1, two_param_quantile<boost::math::cauchy_distribution<> >());
  304. cauchy.add_test_case(20, 20, two_param_quantile<boost::math::cauchy_distribution<> >());
  305. cauchy.add_test_case(-20, 0.0125, two_param_quantile<boost::math::cauchy_distribution<> >());
  306. test_boost_2_param<boost::math::cauchy_distribution>(cauchy);
  307. distribution_tester chi_squared("ChiSquared");
  308. chi_squared.add_test_case(3, one_param_quantile<boost::math::chi_squared_distribution<> >());
  309. chi_squared.add_test_case(20, one_param_quantile<boost::math::chi_squared_distribution<> >());
  310. chi_squared.add_test_case(200, one_param_quantile<boost::math::chi_squared_distribution<> >());
  311. chi_squared.add_test_case(2000, one_param_quantile<boost::math::chi_squared_distribution<> >());
  312. chi_squared.add_test_case(20000, one_param_quantile<boost::math::chi_squared_distribution<> >());
  313. chi_squared.add_test_case(200000, one_param_quantile<boost::math::chi_squared_distribution<> >());
  314. test_boost_1_param<boost::math::chi_squared_distribution>(chi_squared);
  315. distribution_tester exponential("Exponential");
  316. exponential.add_test_case(0.001, one_param_quantile<boost::math::exponential_distribution<> >());
  317. exponential.add_test_case(0.01, one_param_quantile<boost::math::exponential_distribution<> >());
  318. exponential.add_test_case(0.1, one_param_quantile<boost::math::exponential_distribution<> >());
  319. exponential.add_test_case(1, one_param_quantile<boost::math::exponential_distribution<> >());
  320. exponential.add_test_case(10, one_param_quantile<boost::math::exponential_distribution<> >());
  321. exponential.add_test_case(100, one_param_quantile<boost::math::exponential_distribution<> >());
  322. exponential.add_test_case(1000, one_param_quantile<boost::math::exponential_distribution<> >());
  323. test_boost_1_param<boost::math::exponential_distribution>(exponential);
  324. distribution_tester extreme_value("ExtremeValue");
  325. extreme_value.add_test_case(0, 1, two_param_quantile<boost::math::extreme_value_distribution<> >());
  326. extreme_value.add_test_case(20, 20, two_param_quantile<boost::math::extreme_value_distribution<> >());
  327. extreme_value.add_test_case(-20, 0.0125, two_param_quantile<boost::math::extreme_value_distribution<> >());
  328. test_boost_2_param<boost::math::extreme_value_distribution>(extreme_value);
  329. distribution_tester fisher("F");
  330. for (unsigned i = 2; i <= 200000; i *= 10)
  331. {
  332. for (unsigned j = 2; j <= 200000; j *= 10)
  333. {
  334. fisher.add_test_case(i, j, two_param_quantile<boost::math::fisher_f_distribution<> >());
  335. }
  336. }
  337. test_boost_2_param<boost::math::fisher_f_distribution>(fisher);
  338. distribution_tester gamma("Gamma");
  339. gamma.add_test_case(0.1, 1, two_param_quantile<boost::math::gamma_distribution<> >());
  340. gamma.add_test_case(20, 20, two_param_quantile<boost::math::gamma_distribution<> >());
  341. gamma.add_test_case(200, 0.0125, two_param_quantile<boost::math::gamma_distribution<> >());
  342. gamma.add_test_case(2000, 500, two_param_quantile<boost::math::gamma_distribution<> >());
  343. test_boost_2_param<boost::math::gamma_distribution>(gamma);
  344. distribution_tester geometric("Geometric");
  345. geometric.add_test_case(0.001, one_param_quantile<boost::math::geometric_distribution<> >());
  346. geometric.add_test_case(0.01, one_param_quantile<boost::math::geometric_distribution<> >());
  347. geometric.add_test_case(0.1, one_param_quantile<boost::math::geometric_distribution<> >());
  348. geometric.add_test_case(0.5, one_param_quantile<boost::math::geometric_distribution<> >());
  349. geometric.add_test_case(0.9, one_param_quantile<boost::math::geometric_distribution<> >());
  350. geometric.add_test_case(0.99, one_param_quantile<boost::math::geometric_distribution<> >());
  351. geometric.add_test_case(0.999, one_param_quantile<boost::math::geometric_distribution<> >());
  352. test_boost_1_param<boost::math::geometric_distribution>(geometric);
  353. distribution_tester hypergeometric("Hypergeometric");
  354. hypergeometric.add_test_case(10, 5, 100, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  355. hypergeometric.add_test_case(50, 75, 100, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  356. hypergeometric.add_test_case(30, 20, 100, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  357. hypergeometric.add_test_case(100, 50, 1000000, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  358. hypergeometric.add_test_case(500000, 3000, 1000000, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  359. hypergeometric.add_test_case(20000, 800000, 1000000, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  360. hypergeometric.add_test_case(100, 5, 1000, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  361. hypergeometric.add_test_case(500, 50, 1000, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  362. hypergeometric.add_test_case(2, 25, 1000, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  363. hypergeometric.add_test_case(1, 5, 1000, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  364. hypergeometric.add_test_case(100, 500, 1000, three_param_quantile<boost::math::hypergeometric_distribution<> >());
  365. test_boost_3_param<boost::math::hypergeometric_distribution>(hypergeometric);
  366. distribution_tester inverse_chi_squared("InverseChiSquared");
  367. inverse_chi_squared.add_test_case(5, 0.125, two_param_quantile<boost::math::inverse_chi_squared_distribution<> >());
  368. inverse_chi_squared.add_test_case(200, 0.75, two_param_quantile<boost::math::inverse_chi_squared_distribution<> >());
  369. inverse_chi_squared.add_test_case(2000, 1, two_param_quantile<boost::math::inverse_chi_squared_distribution<> >());
  370. inverse_chi_squared.add_test_case(20000, 10, two_param_quantile<boost::math::inverse_chi_squared_distribution<> >());
  371. inverse_chi_squared.add_test_case(200000, 100, two_param_quantile<boost::math::inverse_chi_squared_distribution<> >());
  372. test_boost_2_param<boost::math::inverse_chi_squared_distribution>(inverse_chi_squared);
  373. distribution_tester inverse_gamma("InverseGamma");
  374. inverse_gamma.add_test_case(0.1, 1, two_param_quantile<boost::math::inverse_gamma_distribution<> >());
  375. inverse_gamma.add_test_case(20, 20, two_param_quantile<boost::math::inverse_gamma_distribution<> >());
  376. inverse_gamma.add_test_case(200, 0.0125, two_param_quantile<boost::math::inverse_gamma_distribution<> >());
  377. inverse_gamma.add_test_case(2000, 500, two_param_quantile<boost::math::inverse_gamma_distribution<> >());
  378. test_boost_2_param<boost::math::inverse_gamma_distribution>(inverse_gamma);
  379. distribution_tester inverse_gaussian("InverseGaussian");
  380. inverse_gaussian.add_test_case(0.001, 1, two_param_quantile<boost::math::inverse_gaussian_distribution<> >());
  381. inverse_gaussian.add_test_case(20, 20, two_param_quantile<boost::math::inverse_gaussian_distribution<> >());
  382. test_boost_2_param<boost::math::inverse_gaussian_distribution>(inverse_gaussian);
  383. distribution_tester laplace("Laplace");
  384. laplace.add_test_case(0, 1, two_param_quantile<boost::math::laplace_distribution<> >());
  385. laplace.add_test_case(20, 20, two_param_quantile<boost::math::laplace_distribution<> >());
  386. laplace.add_test_case(-20, 0.0125, two_param_quantile<boost::math::laplace_distribution<> >());
  387. test_boost_2_param<boost::math::laplace_distribution>(laplace);
  388. distribution_tester logistic("Logistic");
  389. logistic.add_test_case(0, 1, two_param_quantile<boost::math::logistic_distribution<> >());
  390. logistic.add_test_case(20, 20, two_param_quantile<boost::math::logistic_distribution<> >());
  391. logistic.add_test_case(-20, 0.0125, two_param_quantile<boost::math::logistic_distribution<> >());
  392. test_boost_2_param<boost::math::logistic_distribution>(logistic);
  393. distribution_tester lognormal("LogNormal");
  394. lognormal.add_test_case(0, 1, two_param_quantile<boost::math::lognormal_distribution<> >());
  395. lognormal.add_test_case(20, 20, two_param_quantile<boost::math::lognormal_distribution<> >());
  396. lognormal.add_test_case(-20, 0.0125, two_param_quantile<boost::math::lognormal_distribution<> >());
  397. test_boost_2_param<boost::math::lognormal_distribution>(lognormal);
  398. distribution_tester negative_binomial("NegativeBinomial");
  399. negative_binomial.add_test_case(5, 0.125, two_param_quantile<boost::math::negative_binomial_distribution<> >());
  400. negative_binomial.add_test_case(200, 0.75, two_param_quantile<boost::math::negative_binomial_distribution<> >());
  401. negative_binomial.add_test_case(2000, 0.001, two_param_quantile<boost::math::negative_binomial_distribution<> >());
  402. negative_binomial.add_test_case(20000, 0.5, two_param_quantile<boost::math::negative_binomial_distribution<> >());
  403. negative_binomial.add_test_case(200000, 0.99, two_param_quantile<boost::math::negative_binomial_distribution<> >());
  404. test_boost_2_param<boost::math::negative_binomial_distribution>(negative_binomial);
  405. distribution_tester non_central_beta("NonCentralBeta");
  406. non_central_beta.add_test_case(2, 5, 2.1, three_param_quantile<boost::math::non_central_beta_distribution<> >());
  407. non_central_beta.add_test_case(0.25, 0.01, 20, three_param_quantile<boost::math::non_central_beta_distribution<> >());
  408. non_central_beta.add_test_case(20, 3, 30, three_param_quantile<boost::math::non_central_beta_distribution<> >());
  409. non_central_beta.add_test_case(100, 200, 400, three_param_quantile<boost::math::non_central_beta_distribution<> >());
  410. non_central_beta.add_test_case(100, 0.25, 20, three_param_quantile<boost::math::non_central_beta_distribution<> >());
  411. test_boost_3_param<boost::math::non_central_beta_distribution>(non_central_beta);
  412. distribution_tester non_central_chi_squared("NonCentralChiSquared");
  413. non_central_chi_squared.add_test_case(5, 0.5, two_param_quantile<boost::math::non_central_chi_squared_distribution<> >());
  414. non_central_chi_squared.add_test_case(200, 2, two_param_quantile<boost::math::non_central_chi_squared_distribution<> >());
  415. non_central_chi_squared.add_test_case(2000, 20, two_param_quantile<boost::math::non_central_chi_squared_distribution<> >());
  416. non_central_chi_squared.add_test_case(20000, 10, two_param_quantile<boost::math::non_central_chi_squared_distribution<> >());
  417. non_central_chi_squared.add_test_case(200000, 50, two_param_quantile<boost::math::non_central_chi_squared_distribution<> >());
  418. test_boost_2_param<boost::math::non_central_chi_squared_distribution>(non_central_chi_squared);
  419. distribution_tester non_central_f("NonCentralF");
  420. non_central_f.add_test_case(20, 20, 3, three_param_quantile<boost::math::non_central_f_distribution<> >());
  421. non_central_f.add_test_case(20, 50, 20, three_param_quantile<boost::math::non_central_f_distribution<> >());
  422. non_central_f.add_test_case(100, 20, 30, three_param_quantile<boost::math::non_central_f_distribution<> >());
  423. non_central_f.add_test_case(100, 200, 100, three_param_quantile<boost::math::non_central_f_distribution<> >());
  424. non_central_f.add_test_case(1000, 100000, 20, three_param_quantile<boost::math::non_central_f_distribution<> >());
  425. test_boost_3_param<boost::math::non_central_f_distribution>(non_central_f);
  426. distribution_tester non_central_t("NonCentralT");
  427. non_central_t.add_test_case(5, 0.5, two_param_quantile<boost::math::non_central_t_distribution<> >());
  428. non_central_t.add_test_case(200, 2, two_param_quantile<boost::math::non_central_t_distribution<> >());
  429. non_central_t.add_test_case(2000, 20, two_param_quantile<boost::math::non_central_t_distribution<> >());
  430. non_central_t.add_test_case(20000, 10, two_param_quantile<boost::math::non_central_t_distribution<> >());
  431. non_central_t.add_test_case(200000, 50, two_param_quantile<boost::math::non_central_t_distribution<> >());
  432. test_boost_2_param<boost::math::non_central_t_distribution>(non_central_t);
  433. distribution_tester pareto("Pareto");
  434. pareto.add_test_case(0.1, 1, two_param_quantile<boost::math::pareto_distribution<> >());
  435. pareto.add_test_case(20, 20, two_param_quantile<boost::math::pareto_distribution<> >());
  436. pareto.add_test_case(200, 0.0125, two_param_quantile<boost::math::pareto_distribution<> >());
  437. pareto.add_test_case(2000, 500, two_param_quantile<boost::math::pareto_distribution<> >());
  438. test_boost_2_param<boost::math::pareto_distribution>(pareto);
  439. distribution_tester poisson("Poisson");
  440. poisson.add_test_case(0.001, one_param_quantile<boost::math::poisson_distribution<> >());
  441. poisson.add_test_case(0.01, one_param_quantile<boost::math::poisson_distribution<> >());
  442. poisson.add_test_case(0.1, one_param_quantile<boost::math::poisson_distribution<> >());
  443. poisson.add_test_case(1, one_param_quantile<boost::math::poisson_distribution<> >());
  444. poisson.add_test_case(10, one_param_quantile<boost::math::poisson_distribution<> >());
  445. poisson.add_test_case(100, one_param_quantile<boost::math::poisson_distribution<> >());
  446. poisson.add_test_case(1000, one_param_quantile<boost::math::poisson_distribution<> >());
  447. test_boost_1_param<boost::math::poisson_distribution>(poisson);
  448. distribution_tester rayleigh("Rayleigh");
  449. rayleigh.add_test_case(0.001, one_param_quantile<boost::math::rayleigh_distribution<> >());
  450. rayleigh.add_test_case(0.01, one_param_quantile<boost::math::rayleigh_distribution<> >());
  451. rayleigh.add_test_case(0.1, one_param_quantile<boost::math::rayleigh_distribution<> >());
  452. rayleigh.add_test_case(1, one_param_quantile<boost::math::rayleigh_distribution<> >());
  453. rayleigh.add_test_case(10, one_param_quantile<boost::math::rayleigh_distribution<> >());
  454. rayleigh.add_test_case(100, one_param_quantile<boost::math::rayleigh_distribution<> >());
  455. rayleigh.add_test_case(1000, one_param_quantile<boost::math::rayleigh_distribution<> >());
  456. test_boost_1_param<boost::math::rayleigh_distribution>(rayleigh);
  457. distribution_tester skew_norm("SkewNormal");
  458. skew_norm.add_test_case(0, 1, 0.1, three_param_quantile<boost::math::skew_normal_distribution<> >());
  459. skew_norm.add_test_case(20, 20, 30, three_param_quantile<boost::math::skew_normal_distribution<> >());
  460. skew_norm.add_test_case(-20, 0.0125, 10, three_param_quantile<boost::math::skew_normal_distribution<> >());
  461. test_boost_3_param<boost::math::skew_normal_distribution>(skew_norm);
  462. distribution_tester students_t("StudentsT");
  463. students_t.add_test_case(3, one_param_quantile<boost::math::students_t_distribution<> >());
  464. students_t.add_test_case(20, one_param_quantile<boost::math::students_t_distribution<> >());
  465. students_t.add_test_case(200, one_param_quantile<boost::math::students_t_distribution<> >());
  466. students_t.add_test_case(2000, one_param_quantile<boost::math::students_t_distribution<> >());
  467. students_t.add_test_case(20000, one_param_quantile<boost::math::students_t_distribution<> >());
  468. students_t.add_test_case(200000, one_param_quantile<boost::math::students_t_distribution<> >());
  469. test_boost_1_param<boost::math::students_t_distribution>(students_t);
  470. distribution_tester weibull("Weibull");
  471. weibull.add_test_case(0.1, 1, two_param_quantile<boost::math::weibull_distribution<> >());
  472. weibull.add_test_case(20, 20, two_param_quantile<boost::math::weibull_distribution<> >());
  473. weibull.add_test_case(200, 0.0125, two_param_quantile<boost::math::weibull_distribution<> >());
  474. weibull.add_test_case(2000, 500, two_param_quantile<boost::math::weibull_distribution<> >());
  475. test_boost_2_param<boost::math::weibull_distribution>(weibull);
  476. #ifdef TEST_GSL
  477. // normal, note no location param
  478. n.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_gaussian_P(x, v[1]); }, "CDF", "GSL");
  479. n.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_gaussian_Pinv(x, v[1]); }, "quantile", "GSL", true);
  480. // exponential:
  481. exponential.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_exponential_P(x, 1 / v[0]); }, "CDF", "GSL");
  482. exponential.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_exponential_Pinv(x, 1 / v[0]); }, "quantile", "GSL", true);
  483. // laplace, note no location param:
  484. laplace.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_laplace_P(x, v[1]); }, "CDF", "GSL");
  485. laplace.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_laplace_Pinv(x, v[1]); }, "quantile", "GSL", true);
  486. // cauchy, note no location param:
  487. cauchy.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_cauchy_P(x, v[1]); }, "CDF", "GSL");
  488. cauchy.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_cauchy_Pinv(x, v[1]); }, "quantile", "GSL", true);
  489. // rayleigh:
  490. rayleigh.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_rayleigh_P(x, v[0]); }, "CDF", "GSL");
  491. rayleigh.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_rayleigh_Pinv(x, v[0]); }, "quantile", "GSL", true);
  492. // gamma:
  493. gamma.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_gamma_P(x, v[0], v[1]); }, "CDF", "GSL");
  494. gamma.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_gamma_Pinv(x, v[0], v[1]); }, "quantile", "GSL", true);
  495. // lognormal:
  496. lognormal.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_lognormal_P(x, v[0], v[1]); }, "CDF", "GSL");
  497. lognormal.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_lognormal_Pinv(x, v[0], v[1]); }, "quantile", "GSL", true);
  498. // chi squared:
  499. chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_chisq_P(x, v[0]); }, "CDF", "GSL");
  500. chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_chisq_Pinv(x, v[0]); }, "quantile", "GSL", true);
  501. // F:
  502. fisher.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_fdist_P(x, v[0], v[1]); }, "CDF", "GSL");
  503. fisher.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_fdist_Pinv(x, v[0], v[1]); }, "quantile", "GSL", true);
  504. // T:
  505. students_t.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_tdist_P(x, v[0]); }, "CDF", "GSL");
  506. students_t.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_tdist_Pinv(x, v[0]); }, "quantile", "GSL", true);
  507. // beta:
  508. beta.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_beta_P(x, v[0], v[1]); }, "CDF", "GSL");
  509. beta.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_beta_Pinv(x, v[0], v[1]); }, "quantile", "GSL", true);
  510. // logistic, note no location param
  511. logistic.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_logistic_P(x, v[1]); }, "CDF", "GSL");
  512. logistic.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_logistic_Pinv(x, v[1]); }, "quantile", "GSL", true);
  513. // pareto:
  514. pareto.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_pareto_P(x, v[1], v[0]); }, "CDF", "GSL");
  515. pareto.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_pareto_Pinv(x, v[1], v[0]); }, "quantile", "GSL", true);
  516. // weibull:
  517. weibull.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_weibull_P(x, v[1], v[0]); }, "CDF", "GSL");
  518. weibull.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_weibull_Pinv(x, v[1], v[0]); }, "quantile", "GSL", true);
  519. // poisson:
  520. poisson.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_poisson_P(x, v[0]); }, "CDF", "GSL");
  521. //poisson.run_timed_tests([](const std::vector<double>& v, double x){ return gsl_cdf_poisson_Pinv(x, v[0]); }, "quantile", "GSL", true);
  522. // binomial:
  523. binomial.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_binomial_P(x, v[1], v[0]); }, "CDF", "GSL");
  524. //binomial.run_timed_tests([](const std::vector<double>& v, double x){ return gsl_cdf_binomial_Pinv(x, v[1], v[0]); }, "quantile", "GSL", true);
  525. // negative_binomial:
  526. negative_binomial.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_negative_binomial_P(x, v[1], v[0]); }, "CDF", "GSL");
  527. //negative_binomial.run_timed_tests([](const std::vector<double>& v, double x){ return gsl_cdf_negative_binomial_Pinv(x, v[1], v[0]); }, "quantile", "GSL", true);
  528. // geometric:
  529. geometric.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_geometric_P(x + 1, v[0]); }, "CDF", "GSL");
  530. //geometric.run_timed_tests([](const std::vector<double>& v, double x){ return gsl_cdf_geometric_Pinv(x, v[0]) - 1; }, "quantile", "GSL", true);
  531. // hypergeometric:
  532. hypergeometric.run_timed_tests([](const std::vector<double>& v, double x) { return gsl_cdf_hypergeometric_P(x, v[0], v[2] - v[0], v[1]); }, "CDF", "GSL");
  533. //hypergeometric.run_timed_tests([](const std::vector<double>& v, double x){ return gsl_cdf_hypergeometric_Pinv(x, v[0], v[2] - v[0], v[1]); }, "quantile", "GSL", true);
  534. #endif
  535. #ifdef TEST_RMATH
  536. // beta
  537. beta.run_timed_tests([](const std::vector<double>& v, double x) { return dbeta(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  538. beta.run_timed_tests([](const std::vector<double>& v, double x) { return pbeta(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  539. beta.run_timed_tests([](const std::vector<double>& v, double x) { return qbeta(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  540. // non-central beta
  541. non_central_beta.run_timed_tests([](const std::vector<double>& v, double x) { return dnbeta(x, v[0], v[1], v[2], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  542. non_central_beta.run_timed_tests([](const std::vector<double>& v, double x) { return pnbeta(x, v[0], v[1], v[2], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  543. non_central_beta.run_timed_tests([](const std::vector<double>& v, double x) { return qnbeta(x, v[0], v[1], v[2], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  544. // binomial
  545. binomial.run_timed_tests([](const std::vector<double>& v, double x) { return dbinom(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  546. binomial.run_timed_tests([](const std::vector<double>& v, double x) { return pbinom(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  547. binomial.run_timed_tests([](const std::vector<double>& v, double x) { return qbinom(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  548. // cauchy
  549. cauchy.run_timed_tests([](const std::vector<double>& v, double x) { return dcauchy(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  550. cauchy.run_timed_tests([](const std::vector<double>& v, double x) { return pcauchy(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  551. cauchy.run_timed_tests([](const std::vector<double>& v, double x) { return qcauchy(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  552. // chi squared
  553. chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return dchisq(x, v[0], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  554. chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return pchisq(x, v[0], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  555. chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return qchisq(x, v[0], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  556. // non central chi squared
  557. non_central_chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return dnchisq(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  558. non_central_chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return pnchisq(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  559. non_central_chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return qnchisq(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  560. // exponential
  561. exponential.run_timed_tests([](const std::vector<double>& v, double x) { return dexp(x, 1 / v[0], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  562. exponential.run_timed_tests([](const std::vector<double>& v, double x) { return pexp(x, 1 / v[0], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  563. exponential.run_timed_tests([](const std::vector<double>& v, double x) { return qexp(x, 1 / v[0], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  564. // F
  565. fisher.run_timed_tests([](const std::vector<double>& v, double x) { return df(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  566. fisher.run_timed_tests([](const std::vector<double>& v, double x) { return pf(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  567. fisher.run_timed_tests([](const std::vector<double>& v, double x) { return qf(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  568. // non central F
  569. non_central_f.run_timed_tests([](const std::vector<double>& v, double x) { return dnf(x, v[0], v[1], v[2], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  570. non_central_f.run_timed_tests([](const std::vector<double>& v, double x) { return pnf(x, v[0], v[1], v[2], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  571. non_central_f.run_timed_tests([](const std::vector<double>& v, double x) { return qnf(x, v[0], v[1], v[2], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  572. // gamma
  573. gamma.run_timed_tests([](const std::vector<double>& v, double x) { return dgamma(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  574. gamma.run_timed_tests([](const std::vector<double>& v, double x) { return pgamma(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  575. gamma.run_timed_tests([](const std::vector<double>& v, double x) { return qgamma(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  576. // geometric
  577. geometric.run_timed_tests([](const std::vector<double>& v, double x) { return dgeom(x, v[0], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  578. geometric.run_timed_tests([](const std::vector<double>& v, double x) { return pgeom(x, v[0], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  579. geometric.run_timed_tests([](const std::vector<double>& v, double x) { return qgeom(x, v[0], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  580. // hypergeometric
  581. hypergeometric.run_timed_tests([](const std::vector<double>& v, double x) { return dhyper(x, v[0], v[2] - v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  582. hypergeometric.run_timed_tests([](const std::vector<double>& v, double x) { return phyper(x, v[0], v[2] - v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  583. hypergeometric.run_timed_tests([](const std::vector<double>& v, double x) { return qhyper(x, v[0], v[2] - v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  584. // logistic
  585. logistic.run_timed_tests([](const std::vector<double>& v, double x) { return dlogis(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  586. logistic.run_timed_tests([](const std::vector<double>& v, double x) { return plogis(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  587. logistic.run_timed_tests([](const std::vector<double>& v, double x) { return qlogis(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  588. // lognormal
  589. lognormal.run_timed_tests([](const std::vector<double>& v, double x) { return dlnorm(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  590. lognormal.run_timed_tests([](const std::vector<double>& v, double x) { return plnorm(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  591. lognormal.run_timed_tests([](const std::vector<double>& v, double x) { return qlnorm(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  592. // negative_binomial
  593. negative_binomial.run_timed_tests([](const std::vector<double>& v, double x) { return dnbinom(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  594. negative_binomial.run_timed_tests([](const std::vector<double>& v, double x) { return pnbinom(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  595. negative_binomial.run_timed_tests([](const std::vector<double>& v, double x) { return qnbinom(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  596. // normal
  597. n.run_timed_tests([](const std::vector<double>& v, double x) { return dnorm(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  598. n.run_timed_tests([](const std::vector<double>& v, double x) { return pnorm(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  599. n.run_timed_tests([](const std::vector<double>& v, double x) { return qnorm(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  600. // poisson
  601. poisson.run_timed_tests([](const std::vector<double>& v, double x) { return dpois(x, v[0], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  602. poisson.run_timed_tests([](const std::vector<double>& v, double x) { return ppois(x, v[0], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  603. poisson.run_timed_tests([](const std::vector<double>& v, double x) { return qpois(x, v[0], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  604. // T
  605. students_t.run_timed_tests([](const std::vector<double>& v, double x) { return dt(x, v[0], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  606. students_t.run_timed_tests([](const std::vector<double>& v, double x) { return pt(x, v[0], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  607. students_t.run_timed_tests([](const std::vector<double>& v, double x) { return qt(x, v[0], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  608. // non central T
  609. non_central_t.run_timed_tests([](const std::vector<double>& v, double x) { return dnt(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  610. non_central_t.run_timed_tests([](const std::vector<double>& v, double x) { return pnt(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  611. non_central_t.run_timed_tests([](const std::vector<double>& v, double x) { return qnt(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  612. // weibull
  613. weibull.run_timed_tests([](const std::vector<double>& v, double x) { return dweibull(x, v[0], v[1], 0); }, "PDF", "Rmath " R_VERSION_STRING);
  614. weibull.run_timed_tests([](const std::vector<double>& v, double x) { return pweibull(x, v[0], v[1], 1, 0); }, "CDF", "Rmath " R_VERSION_STRING);
  615. weibull.run_timed_tests([](const std::vector<double>& v, double x) { return qweibull(x, v[0], v[1], 1, 0); }, "quantile", "Rmath " R_VERSION_STRING, true);
  616. #endif
  617. #ifdef TEST_DCDFLIB
  618. n.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_norm_cdf(x, v[0], v[1]); }, "CDF", "DCDFLIB");
  619. n.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_norm_quantile(x, v[0], v[1]); }, "quantile", "DCDFLIB", true);
  620. beta.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_beta_cdf(x, v[0], v[1]); }, "CDF", "DCDFLIB");
  621. beta.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_beta_quantile(x, v[0], v[1]); }, "quantile", "DCDFLIB", true);
  622. binomial.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_binomial_cdf(x, v[0], v[1]); }, "CDF", "DCDFLIB");
  623. binomial.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_binomial_quantile(x, v[0], v[1]); }, "quantile", "DCDFLIB", true);
  624. chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_chi_cdf(x, v[0]); }, "CDF", "DCDFLIB");
  625. chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_chi_quantile(x, v[0]); }, "quantile", "DCDFLIB", true);
  626. non_central_chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_chi_n_cdf(x, v[0], v[1]); }, "CDF", "DCDFLIB");
  627. non_central_chi_squared.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_chi_n_quantile(x, v[0], v[1]); }, "quantile", "DCDFLIB", true);
  628. fisher.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_f_cdf(x, v[0], v[1]); }, "CDF", "DCDFLIB");
  629. fisher.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_f_quantile(x, v[0], v[1]); }, "quantile", "DCDFLIB", true);
  630. non_central_f.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_f_n_cdf(x, v[0], v[1], v[2]); }, "CDF", "DCDFLIB");
  631. non_central_f.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_f_n_quantile(x, v[0], v[1], v[2]); }, "quantile", "DCDFLIB", true);
  632. gamma.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_gamma_cdf(x, v[0], v[1]); }, "CDF", "DCDFLIB");
  633. gamma.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_gamma_quantile(x, v[0], v[1]); }, "quantile", "DCDFLIB", true);
  634. negative_binomial.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_nbin_cdf(x, v[0], v[1]); }, "CDF", "DCDFLIB");
  635. negative_binomial.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_nbin_quantile(x, v[0], v[1]); }, "quantile", "DCDFLIB", true);
  636. poisson.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_poisson_cdf(x, v[0]); }, "CDF", "DCDFLIB");
  637. poisson.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_poisson_quantile(x, v[0]); }, "quantile", "DCDFLIB", true);
  638. students_t.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_t_cdf(x, v[0]); }, "CDF", "DCDFLIB");
  639. students_t.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_t_quantile(x, v[0]); }, "quantile", "DCDFLIB", true);
  640. non_central_t.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_t_n_cdf(x, v[0], v[1]); }, "CDF", "DCDFLIB");
  641. non_central_t.run_timed_tests([](const std::vector<double>& v, double x) { return dcdflib_t_n_quantile(x, v[0], v[1]); }, "quantile", "DCDFLIB", true);
  642. #endif
  643. }
  644. catch(const std::exception& e)
  645. {
  646. std::cout << "Test run aborted due to thrown exception: " << e.what() << std::endl;
  647. return 1;
  648. }
  649. return 0;
  650. }