test_owens_t.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. // test_owens_t.cpp
  2. // Copyright Paul A. Bristow 2012.
  3. // Copyright Benjamin Sobotta 2012.
  4. // Use, modification and distribution are subject to the
  5. // Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt
  7. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. // Tested using some 30 decimal digit accuracy values from:
  9. // Fast and accurate calculation of Owen's T-function
  10. // Mike Patefield, and David Tandy
  11. // Journal of Statistical Software, 5 (5), 1-25 (2000).
  12. // http://www.jstatsoft.org/v05/a05/paper Table 3, page 15
  13. // Values of T(h,a) accurate to thirty figures were calculated using 128 bit arithmetic by
  14. // evaluating (9) with m = 48, the summation over k being continued until additional terms did
  15. // not alter the result. The resultant values Tacc(h,a) say, were validated by evaluating (8) with
  16. // m = 48 (i.e. 96 point Gaussian quadrature).
  17. #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
  18. #ifdef _MSC_VER
  19. # pragma warning (disable : 4127) // conditional expression is constant
  20. # pragma warning (disable : 4305) // 'initializing' : truncation from 'double' to 'const float'
  21. // ?? TODO get rid of these warnings?
  22. #endif
  23. #include <boost/math/concepts/real_concept.hpp> // for real_concept.
  24. using ::boost::math::concepts::real_concept;
  25. #include <boost/math/special_functions/owens_t.hpp> // for owens_t function.
  26. using boost::math::owens_t;
  27. #include <boost/math/distributions/normal.hpp>
  28. #define BOOST_TEST_MAIN
  29. #include <boost/test/unit_test.hpp>
  30. #include <boost/test/tools/floating_point_comparison.hpp>
  31. #include <boost/array.hpp>
  32. #include "libs/math/test/handle_test_result.hpp"
  33. #include "libs/math/test/table_type.hpp"
  34. #include "libs/math/test/functor.hpp"
  35. #include "test_owens_t.hpp"
  36. //
  37. // Defining TEST_CPP_DEC_FLOAT enables testing of multiprecision support.
  38. // This requires the multiprecision library from sandbox/big_number.
  39. // Note that these tests *do not pass*, but they do give an idea of the
  40. // error rates that can be expected....
  41. //
  42. #ifdef TEST_CPP_DEC_FLOAT
  43. #include <boost/multiprecision/cpp_dec_float.hpp>
  44. template <class R>
  45. inline R convert_to(const char* s)
  46. {
  47. try{
  48. return boost::lexical_cast<R>(s);
  49. }
  50. catch(const boost::bad_lexical_cast&)
  51. {
  52. return 0;
  53. }
  54. }
  55. #define SC_(x) convert_to<T>(BOOST_STRINGIZE(x))
  56. #endif
  57. #include "owens_t_T7.hpp"
  58. #include <iostream>
  59. using std::cout;
  60. using std::endl;
  61. #include <limits>
  62. using std::numeric_limits;
  63. void expected_results()
  64. {
  65. //
  66. // Define the max and mean errors expected for
  67. // various compilers and platforms.
  68. //
  69. const char* largest_type;
  70. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  71. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  72. {
  73. largest_type = "(long\\s+)?double|real_concept";
  74. }
  75. else
  76. {
  77. largest_type = "long double|real_concept";
  78. }
  79. #else
  80. largest_type = "(long\\s+)?double";
  81. #endif
  82. //
  83. // Catch all cases come last:
  84. //
  85. if(std::numeric_limits<long double>::digits > 60)
  86. {
  87. add_expected_result(
  88. ".*", // compiler
  89. ".*", // stdlib
  90. ".*", // platform
  91. largest_type, // test type(s)
  92. ".*", // test data group
  93. "owens_t", 500, 100); // test function
  94. }
  95. else
  96. {
  97. add_expected_result(
  98. ".*", // compiler
  99. ".*", // stdlib
  100. ".*", // platform
  101. largest_type, // test type(s)
  102. ".*", // test data group
  103. "owens_t", 60, 5); // test function
  104. }
  105. //
  106. // Finish off by printing out the compiler/stdlib/platform names,
  107. // we do this to make it easier to mark up expected error rates.
  108. //
  109. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  110. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  111. }
  112. BOOST_AUTO_TEST_CASE( test_main )
  113. {
  114. BOOST_MATH_CONTROL_FP;
  115. expected_results();
  116. // Basic sanity-check spot values.
  117. // (Parameter value, arbitrarily zero, only communicates the floating point type).
  118. test_spots(0.0F); // Test float.
  119. test_spots(0.0); // Test double.
  120. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  121. test_spots(0.0L); // Test long double.
  122. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  123. test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
  124. #endif
  125. #endif
  126. check_against_T7(0.0F); // Test float.
  127. check_against_T7(0.0); // Test double.
  128. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  129. check_against_T7(0.0L); // Test long double.
  130. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  131. check_against_T7(boost::math::concepts::real_concept(0.)); // Test real concept.
  132. #endif
  133. #endif
  134. test_owens_t(0.0F, "float"); // Test float.
  135. test_owens_t(0.0, "double"); // Test double.
  136. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  137. test_owens_t(0.0L, "long double"); // Test long double.
  138. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  139. test_owens_t(boost::math::concepts::real_concept(0.), "real_concept"); // Test real concept.
  140. #endif
  141. #endif
  142. #ifdef TEST_CPP_DEC_FLOAT
  143. typedef boost::multiprecision::mp_number<boost::multiprecision::cpp_dec_float<35> > cpp_dec_float_35;
  144. test_owens_t(cpp_dec_float_35(0), "cpp_dec_float_35"); // Test real concept.
  145. test_owens_t(boost::multiprecision::cpp_dec_float_50(0), "cpp_dec_float_50"); // Test real concept.
  146. test_owens_t(boost::multiprecision::cpp_dec_float_100(0), "cpp_dec_float_100"); // Test real concept.
  147. #endif
  148. } // BOOST_AUTO_TEST_CASE( test_main )
  149. /*
  150. Output:
  151. Description: Autorun "J:\Cpp\MathToolkit\test\Math_test\Debug\test_owens_t.exe"
  152. Running 1 test case...
  153. Tests run with Microsoft Visual C++ version 10.0, Dinkumware standard library version 520, Win32
  154. Tolerance = 3.57628e-006.
  155. Tolerance = 6.66134e-015.
  156. Tolerance = 6.66134e-015.
  157. Tolerance = 6.66134e-015.
  158. Tolerance = 1.78814e-005.
  159. Tolerance = 3.33067e-014.
  160. Tolerance = 3.33067e-014.
  161. Tolerance = 3.33067e-014.
  162. Testing Owens T (medium small values) with type float
  163. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  164. boost::math::owens_t<float> Max = 0 RMS Mean=0
  165. Testing Owens T (large and diverse values) with type float
  166. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167. boost::math::owens_t<float> Max = 0 RMS Mean=0
  168. Testing Owens T (medium small values) with type double
  169. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170. boost::math::owens_t<double> Max = 4.375 RMS Mean=0.9728
  171. worst case at row: 81
  172. { 4.4206809997558594, 0.1269868016242981, 1.0900281236140834e-006 }
  173. Testing Owens T (large and diverse values) with type double
  174. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  175. boost::math::owens_t<double> Max = 3.781 RMS Mean=0.6206
  176. worst case at row: 430
  177. { 3.4516773223876953, 0.0010718167759478092, 4.413983645332431e-007 }
  178. Testing Owens T (medium small values) with type long double
  179. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  180. boost::math::owens_t<long double> Max = 4.375 RMS Mean=0.9728
  181. worst case at row: 81
  182. { 4.4206809997558594, 0.1269868016242981, 1.0900281236140834e-006 }
  183. Testing Owens T (large and diverse values) with type long double
  184. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185. boost::math::owens_t<long double> Max = 3.781 RMS Mean=0.6206
  186. worst case at row: 430
  187. { 3.4516773223876953, 0.0010718167759478092, 4.413983645332431e-007 }
  188. Testing Owens T (medium small values) with type real_concept
  189. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  190. boost::math::owens_t<real_concept> Max = 4.375 RMS Mean=1.032
  191. worst case at row: 81
  192. { 4.4206809997558594, 0.1269868016242981, 1.0900281236140834e-006 }
  193. Testing Owens T (large and diverse values) with type real_concept
  194. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195. boost::math::owens_t<real_concept> Max = 21.04 RMS Mean=1.102
  196. worst case at row: 439
  197. { 3.4516773223876953, 0.98384737968444824, 0.00013923002576038691 }
  198. *** No errors detected
  199. */