test_skew_normal.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. // Copyright Paul A. Bristow 2012.
  2. // Copyright John Maddock 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. #ifdef _MSC_VER
  9. # pragma warning (disable : 4127) // conditional expression is constant.
  10. # pragma warning (disable : 4305) // 'initializing' : truncation from 'double' to 'const float'.
  11. # pragma warning (disable : 4310) // cast truncates constant value.
  12. # pragma warning (disable : 4512) // assignment operator could not be generated.
  13. #endif
  14. //#include <pch.hpp> // include directory libs/math/src/tr1/ is needed.
  15. #include <boost/math/concepts/real_concept.hpp> // for real_concept
  16. #define BOOST_TEST_MAIN
  17. #include <boost/test/unit_test.hpp> // Boost.Test
  18. #include <boost/test/tools/floating_point_comparison.hpp>
  19. #include <boost/math/distributions/skew_normal.hpp>
  20. using boost::math::skew_normal_distribution;
  21. using boost::math::skew_normal;
  22. #include <boost/math/tools/test.hpp>
  23. #include <iostream>
  24. #include <iomanip>
  25. using std::cout;
  26. using std::endl;
  27. using std::setprecision;
  28. #include <limits>
  29. using std::numeric_limits;
  30. #include "test_out_of_range.hpp"
  31. template <class RealType>
  32. void check_skew_normal(RealType mean, RealType scale, RealType shape, RealType x, RealType p, RealType q, RealType tol)
  33. {
  34. using boost::math::skew_normal_distribution;
  35. BOOST_CHECK_CLOSE_FRACTION(
  36. ::boost::math::cdf( // Check cdf
  37. skew_normal_distribution<RealType>(mean, scale, shape), // distribution.
  38. x), // random variable.
  39. p, // probability.
  40. tol); // tolerance.
  41. BOOST_CHECK_CLOSE_FRACTION(
  42. ::boost::math::cdf( // Check cdf complement
  43. complement(
  44. skew_normal_distribution<RealType>(mean, scale, shape), // distribution.
  45. x)), // random variable.
  46. q, // probability complement.
  47. tol); // %tolerance.
  48. BOOST_CHECK_CLOSE_FRACTION(
  49. ::boost::math::quantile( // Check quantile
  50. skew_normal_distribution<RealType>(mean, scale, shape), // distribution.
  51. p), // probability.
  52. x, // random variable.
  53. tol); // tolerance.
  54. BOOST_CHECK_CLOSE_FRACTION(
  55. ::boost::math::quantile( // Check quantile complement
  56. complement(
  57. skew_normal_distribution<RealType>(mean, scale, shape), // distribution.
  58. q)), // probability complement.
  59. x, // random variable.
  60. tol); // tolerance.
  61. skew_normal_distribution<RealType> dist (mean, scale, shape);
  62. if((p < 0.999) && (q < 0.999))
  63. { // We can only check this if P is not too close to 1,
  64. // so that we can guarantee Q is accurate:
  65. BOOST_CHECK_CLOSE_FRACTION(
  66. cdf(complement(dist, x)), q, tol); // 1 - cdf
  67. BOOST_CHECK_CLOSE_FRACTION(
  68. quantile(dist, p), x, tol); // quantile(cdf) = x
  69. BOOST_CHECK_CLOSE_FRACTION(
  70. quantile(complement(dist, q)), x, tol); // quantile(complement(1 - cdf)) = x
  71. }
  72. } // template <class RealType>void check_skew_normal()
  73. template <class RealType>
  74. void test_spots(RealType)
  75. {
  76. // Basic sanity checks
  77. RealType tolerance = 1e-4f; // 1e-4 (as %)
  78. // Check some bad parameters to the distribution,
  79. #ifndef BOOST_NO_EXCEPTIONS
  80. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType> nbad1(0, 0), std::domain_error); // zero sd
  81. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType> nbad1(0, -1), std::domain_error); // negative sd
  82. #else
  83. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType>(0, 0), std::domain_error); // zero sd
  84. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType>(0, -1), std::domain_error); // negative sd
  85. #endif
  86. // Tests on extreme values of random variate x, if has numeric_limit infinity etc.
  87. skew_normal_distribution<RealType> N01;
  88. if(std::numeric_limits<RealType>::has_infinity)
  89. {
  90. BOOST_CHECK_EQUAL(pdf(N01, +std::numeric_limits<RealType>::infinity()), 0); // x = + infinity, pdf = 0
  91. BOOST_CHECK_EQUAL(pdf(N01, -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, pdf = 0
  92. BOOST_CHECK_EQUAL(cdf(N01, +std::numeric_limits<RealType>::infinity()), 1); // x = + infinity, cdf = 1
  93. BOOST_CHECK_EQUAL(cdf(N01, -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, cdf = 0
  94. BOOST_CHECK_EQUAL(cdf(complement(N01, +std::numeric_limits<RealType>::infinity())), 0); // x = + infinity, c cdf = 0
  95. BOOST_CHECK_EQUAL(cdf(complement(N01, -std::numeric_limits<RealType>::infinity())), 1); // x = - infinity, c cdf = 1
  96. #ifndef BOOST_NO_EXCEPTIONS
  97. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType> nbad1(std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // +infinite mean
  98. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType> nbad1(-std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // -infinite mean
  99. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType> nbad1(static_cast<RealType>(0), std::numeric_limits<RealType>::infinity()), std::domain_error); // infinite sd
  100. #else
  101. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType>(std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // +infinite mean
  102. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType>(-std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), std::domain_error); // -infinite mean
  103. BOOST_MATH_CHECK_THROW(boost::math::skew_normal_distribution<RealType>(static_cast<RealType>(0), std::numeric_limits<RealType>::infinity()), std::domain_error); // infinite sd
  104. #endif
  105. }
  106. if (std::numeric_limits<RealType>::has_quiet_NaN)
  107. {
  108. // No longer allow x to be NaN, then these tests should throw.
  109. BOOST_MATH_CHECK_THROW(pdf(N01, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
  110. BOOST_MATH_CHECK_THROW(cdf(N01, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
  111. BOOST_MATH_CHECK_THROW(cdf(complement(N01, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // x = + infinity
  112. BOOST_MATH_CHECK_THROW(quantile(N01, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // p = + infinity
  113. BOOST_MATH_CHECK_THROW(quantile(complement(N01, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // p = + infinity
  114. }
  115. BOOST_CHECK_EQUAL(mean(N01), 0);
  116. BOOST_CHECK_EQUAL(mode(N01), 0);
  117. BOOST_CHECK_EQUAL(variance(N01), 1);
  118. BOOST_CHECK_EQUAL(skewness(N01), 0);
  119. BOOST_CHECK_EQUAL(kurtosis_excess(N01), 0);
  120. cout << "Tolerance for type " << typeid(RealType).name() << " is " << tolerance << " %" << endl;
  121. // Tests where shape = 0, so same as normal tests.
  122. // (These might be removed later).
  123. check_skew_normal(
  124. static_cast<RealType>(5),
  125. static_cast<RealType>(2),
  126. static_cast<RealType>(0),
  127. static_cast<RealType>(4.8),
  128. static_cast<RealType>(0.46017),
  129. static_cast<RealType>(1 - 0.46017),
  130. tolerance);
  131. check_skew_normal(
  132. static_cast<RealType>(5),
  133. static_cast<RealType>(2),
  134. static_cast<RealType>(0),
  135. static_cast<RealType>(5.2),
  136. static_cast<RealType>(1 - 0.46017),
  137. static_cast<RealType>(0.46017),
  138. tolerance);
  139. check_skew_normal(
  140. static_cast<RealType>(5),
  141. static_cast<RealType>(2),
  142. static_cast<RealType>(0),
  143. static_cast<RealType>(2.2),
  144. static_cast<RealType>(0.08076),
  145. static_cast<RealType>(1 - 0.08076),
  146. tolerance);
  147. check_skew_normal(
  148. static_cast<RealType>(5),
  149. static_cast<RealType>(2),
  150. static_cast<RealType>(0),
  151. static_cast<RealType>(7.8),
  152. static_cast<RealType>(1 - 0.08076),
  153. static_cast<RealType>(0.08076),
  154. tolerance);
  155. check_skew_normal(
  156. static_cast<RealType>(-3),
  157. static_cast<RealType>(5),
  158. static_cast<RealType>(0),
  159. static_cast<RealType>(-4.5),
  160. static_cast<RealType>(0.38209),
  161. static_cast<RealType>(1 - 0.38209),
  162. tolerance);
  163. check_skew_normal(
  164. static_cast<RealType>(-3),
  165. static_cast<RealType>(5),
  166. static_cast<RealType>(0),
  167. static_cast<RealType>(-1.5),
  168. static_cast<RealType>(1 - 0.38209),
  169. static_cast<RealType>(0.38209),
  170. tolerance);
  171. check_skew_normal(
  172. static_cast<RealType>(-3),
  173. static_cast<RealType>(5),
  174. static_cast<RealType>(0),
  175. static_cast<RealType>(-8.5),
  176. static_cast<RealType>(0.13567),
  177. static_cast<RealType>(1 - 0.13567),
  178. tolerance);
  179. check_skew_normal(
  180. static_cast<RealType>(-3),
  181. static_cast<RealType>(5),
  182. static_cast<RealType>(0),
  183. static_cast<RealType>(2.5),
  184. static_cast<RealType>(1 - 0.13567),
  185. static_cast<RealType>(0.13567),
  186. tolerance);
  187. // Tests where shape != 0, specific to skew_normal distribution.
  188. //void check_skew_normal(RealType mean, RealType scale, RealType shape, RealType x, RealType p, RealType q, RealType tol)
  189. check_skew_normal( // 1st R example.
  190. static_cast<RealType>(1.1),
  191. static_cast<RealType>(2.2),
  192. static_cast<RealType>(-3.3),
  193. static_cast<RealType>(0.4), // x
  194. static_cast<RealType>(0.733918618927874), // p == psn
  195. static_cast<RealType>(1 - 0.733918618927874), // q
  196. tolerance);
  197. // Not sure about these yet.
  198. //check_skew_normal( // 2nd R example.
  199. //static_cast<RealType>(1.1),
  200. //static_cast<RealType>(0.02),
  201. //static_cast<RealType>(0.03),
  202. //static_cast<RealType>(1.3), // x
  203. //static_cast<RealType>(0.01), // p
  204. //static_cast<RealType>(0.09), // q
  205. //tolerance);
  206. //check_skew_normal( // 3nd R example.
  207. //static_cast<RealType>(10.1),
  208. //static_cast<RealType>(5.),
  209. //static_cast<RealType>(-0.03),
  210. //static_cast<RealType>(-1.3), // x
  211. //static_cast<RealType>(0.01201290665838824), // p
  212. //static_cast<RealType>(1. - 0.01201290665838824), // q 0.987987101
  213. //tolerance);
  214. // Tests for PDF: we know that the normal peak value is at 1/sqrt(2*pi)
  215. //
  216. tolerance = boost::math::tools::epsilon<RealType>() * 5; // 5 eps as a fraction
  217. BOOST_CHECK_CLOSE_FRACTION(
  218. pdf(skew_normal_distribution<RealType>(), static_cast<RealType>(0)),
  219. static_cast<RealType>(0.3989422804014326779399460599343818684759L), // 1/sqrt(2*pi)
  220. tolerance);
  221. BOOST_CHECK_CLOSE_FRACTION(
  222. pdf(skew_normal_distribution<RealType>(3), static_cast<RealType>(3)),
  223. static_cast<RealType>(0.3989422804014326779399460599343818684759L),
  224. tolerance);
  225. BOOST_CHECK_CLOSE_FRACTION(
  226. pdf(skew_normal_distribution<RealType>(3, 5), static_cast<RealType>(3)),
  227. static_cast<RealType>(0.3989422804014326779399460599343818684759L / 5),
  228. tolerance);
  229. // Shape != 0.
  230. BOOST_CHECK_CLOSE_FRACTION(
  231. pdf(skew_normal_distribution<RealType>(3,5,1e-6), static_cast<RealType>(3)),
  232. static_cast<RealType>(0.3989422804014326779399460599343818684759L / 5),
  233. tolerance);
  234. // Checks on mean, variance cumulants etc.
  235. // Checks on shape ==0
  236. RealType tol5 = boost::math::tools::epsilon<RealType>() * 5;
  237. skew_normal_distribution<RealType> dist(8, 3);
  238. RealType x = static_cast<RealType>(0.125);
  239. BOOST_MATH_STD_USING // ADL of std math lib names
  240. // mean:
  241. BOOST_CHECK_CLOSE(
  242. mean(dist)
  243. , static_cast<RealType>(8), tol5);
  244. // variance:
  245. BOOST_CHECK_CLOSE(
  246. variance(dist)
  247. , static_cast<RealType>(9), tol5);
  248. // std deviation:
  249. BOOST_CHECK_CLOSE(
  250. standard_deviation(dist)
  251. , static_cast<RealType>(3), tol5);
  252. // hazard:
  253. BOOST_CHECK_CLOSE(
  254. hazard(dist, x)
  255. , pdf(dist, x) / cdf(complement(dist, x)), tol5);
  256. // cumulative hazard:
  257. BOOST_CHECK_CLOSE(
  258. chf(dist, x)
  259. , -log(cdf(complement(dist, x))), tol5);
  260. // coefficient_of_variation:
  261. BOOST_CHECK_CLOSE(
  262. coefficient_of_variation(dist)
  263. , standard_deviation(dist) / mean(dist), tol5);
  264. // mode:
  265. BOOST_CHECK_CLOSE_FRACTION(mode(dist), static_cast<RealType>(8), 0.001f);
  266. BOOST_CHECK_CLOSE(
  267. median(dist)
  268. , static_cast<RealType>(8), tol5);
  269. // skewness:
  270. BOOST_CHECK_CLOSE(
  271. skewness(dist)
  272. , static_cast<RealType>(0), tol5);
  273. // kurtosis:
  274. BOOST_CHECK_CLOSE(
  275. kurtosis(dist)
  276. , static_cast<RealType>(3), tol5);
  277. // kurtosis excess:
  278. BOOST_CHECK_CLOSE(
  279. kurtosis_excess(dist)
  280. , static_cast<RealType>(0), tol5);
  281. skew_normal_distribution<RealType> norm01(0, 1); // Test default (0, 1)
  282. BOOST_CHECK_CLOSE(
  283. mean(norm01),
  284. static_cast<RealType>(0), 0); // Mean == zero
  285. skew_normal_distribution<RealType> defsd_norm01(0); // Test default (0, sd = 1)
  286. BOOST_CHECK_CLOSE(
  287. mean(defsd_norm01),
  288. static_cast<RealType>(0), 0); // Mean == zero
  289. skew_normal_distribution<RealType> def_norm01; // Test default (0, sd = 1)
  290. BOOST_CHECK_CLOSE(
  291. mean(def_norm01),
  292. static_cast<RealType>(0), 0); // Mean == zero
  293. BOOST_CHECK_CLOSE(
  294. standard_deviation(def_norm01),
  295. static_cast<RealType>(1), 0); //
  296. BOOST_CHECK_CLOSE(
  297. mode(def_norm01),
  298. static_cast<RealType>(0), 0); // Mode == zero
  299. // Skew_normal tests with shape != 0.
  300. {
  301. // Note these tolerances are expressed as percentages, hence the extra * 100 on the end:
  302. RealType tol10 = boost::math::tools::epsilon<RealType>() * 10 * 100;
  303. RealType tol100 = boost::math::tools::epsilon<RealType>() * 100 * 100;
  304. //skew_normal_distribution<RealType> dist(1.1, 0.02, 0.03);
  305. BOOST_MATH_STD_USING // ADL of std math lib names.
  306. // Test values from R = see skew_normal_drv.cpp which included the R code used.
  307. {
  308. dist = skew_normal_distribution<RealType>(static_cast<RealType>(1.1l), static_cast<RealType>(2.2l), static_cast<RealType>(-3.3l));
  309. BOOST_CHECK_CLOSE( // mean:
  310. mean(dist)
  311. , static_cast<RealType>(-0.579908992539856825862549L), tol10 * 2);
  312. std::cout << std::setprecision(17) << "Variance = " << variance(dist) << std::endl;
  313. BOOST_CHECK_CLOSE( // variance: N[variance[skewnormaldistribution[1.1, 2.2, -3.3]], 50]
  314. variance(dist)
  315. , static_cast<RealType>(2.0179057767837232633904061072049998357047989154484L), tol10);
  316. BOOST_CHECK_CLOSE( // skewness:
  317. skewness(dist)
  318. , static_cast<RealType>(-0.709854548171537509192897824663L), tol100);
  319. BOOST_CHECK_CLOSE( // kurtosis:
  320. kurtosis(dist)
  321. , static_cast<RealType>(3.5538752625241790601377L), tol100);
  322. BOOST_CHECK_CLOSE( // kurtosis excess:
  323. kurtosis_excess(dist)
  324. , static_cast<RealType>(0.5538752625241790601377L), tol100);
  325. BOOST_CHECK_CLOSE(
  326. pdf(dist, static_cast<RealType>(0.4L)),
  327. static_cast<RealType>(0.294140110156599539564571L),
  328. tol10);
  329. BOOST_CHECK_CLOSE(
  330. cdf(dist, static_cast<RealType>(0.4L)),
  331. static_cast<RealType>(0.7339186189278737976326676452L),
  332. tol100);
  333. BOOST_CHECK_CLOSE(
  334. quantile(dist, static_cast<RealType>(0.3L)),
  335. static_cast<RealType>(-1.180104068086875314419247L),
  336. tol100);
  337. { // mode tests
  338. dist = skew_normal_distribution<RealType>(static_cast<RealType>(0.l), static_cast<RealType>(1.l), static_cast<RealType>(4.l));
  339. // cout << "pdf(dist, 0) = " << pdf(dist, 0) << ", pdf(dist, 0.45) = " << pdf(dist, 0.45) << endl;
  340. // BOOST_CHECK_CLOSE(mode(dist), boost::math::constants::root_two<RealType>() / 2, tol5);
  341. BOOST_CHECK_CLOSE(mode(dist), static_cast<RealType>(0.41697299497388863932L), tol100);
  342. }
  343. }
  344. {
  345. dist = skew_normal_distribution<RealType>(static_cast<RealType>(1.1l), static_cast<RealType>(0.02l), static_cast<RealType>(0.03l));
  346. BOOST_CHECK_CLOSE( // mean:
  347. mean(dist)
  348. , static_cast<RealType>(1.1004785154529557886162L), tol10);
  349. BOOST_CHECK_CLOSE( // variance:
  350. variance(dist)
  351. , static_cast<RealType>(0.00039977102296128251645L), tol10);
  352. BOOST_CHECK_CLOSE( // skewness:
  353. skewness(dist)
  354. , static_cast<RealType>(5.8834811259890359782e-006L), tol100);
  355. BOOST_CHECK_CLOSE( // kurtosis:
  356. kurtosis(dist)
  357. , static_cast<RealType>(3.L + 9.2903475812137800239002e-008L), tol100);
  358. BOOST_CHECK_CLOSE( // kurtosis excess:
  359. kurtosis_excess(dist)
  360. , static_cast<RealType>(9.2903475812137800239002e-008L), tol100);
  361. }
  362. {
  363. dist = skew_normal_distribution<RealType>(static_cast<RealType>(10.1l), static_cast<RealType>(5.l), static_cast<RealType>(-0.03l));
  364. BOOST_CHECK_CLOSE( // mean:
  365. mean(dist)
  366. , static_cast<RealType>(9.9803711367610528459485937L), tol10);
  367. BOOST_CHECK_CLOSE( // variance:
  368. variance(dist)
  369. , static_cast<RealType>(24.98568893508015727823L), tol10);
  370. BOOST_CHECK_CLOSE( // skewness:
  371. skewness(dist)
  372. , static_cast<RealType>(-5.8834811259890359782085e-006L), tol100);
  373. BOOST_CHECK_CLOSE( // kurtosis:
  374. kurtosis(dist)
  375. , static_cast<RealType>(3.L + 9.2903475812137800239002e-008L), tol100);
  376. BOOST_CHECK_CLOSE( // kurtosis excess:
  377. kurtosis_excess(dist)
  378. , static_cast<RealType>(9.2903475812137800239002e-008L), tol100);
  379. }
  380. {
  381. dist = skew_normal_distribution<RealType>(static_cast<RealType>(-10.1l), static_cast<RealType>(5.l), static_cast<RealType>(30.l));
  382. BOOST_CHECK_CLOSE( // mean:
  383. mean(dist)
  384. , static_cast<RealType>(-6.11279169674138408531365L), 2 * tol10);
  385. BOOST_CHECK_CLOSE( // variance:
  386. variance(dist)
  387. , static_cast<RealType>(9.10216994642554914628242L), tol10 * 2);
  388. BOOST_CHECK_CLOSE( // skewness:
  389. skewness(dist)
  390. , static_cast<RealType>(0.99072425443686904424L), tol100);
  391. BOOST_CHECK_CLOSE( // kurtosis:
  392. kurtosis(dist)
  393. , static_cast<RealType>(3.L + 0.8638862008406084244563L), tol100);
  394. BOOST_CHECK_CLOSE( // kurtosis excess:
  395. kurtosis_excess(dist)
  396. , static_cast<RealType>(0.8638862008406084244563L), tol100);
  397. }
  398. BOOST_MATH_CHECK_THROW(cdf(skew_normal_distribution<RealType>(0, 0, 0), 0), std::domain_error);
  399. BOOST_MATH_CHECK_THROW(cdf(skew_normal_distribution<RealType>(0, -1, 0), 0), std::domain_error);
  400. BOOST_MATH_CHECK_THROW(quantile(skew_normal_distribution<RealType>(0, 1, 0), -1), std::domain_error);
  401. BOOST_MATH_CHECK_THROW(quantile(skew_normal_distribution<RealType>(0, 1, 0), 2), std::domain_error);
  402. check_out_of_range<skew_normal_distribution<RealType> >(1, 1, 1);
  403. }
  404. } // template <class RealType>void test_spots(RealType)
  405. BOOST_AUTO_TEST_CASE( test_main )
  406. {
  407. using boost::math::skew_normal;
  408. using boost::math::skew_normal_distribution;
  409. //int precision = 17; // std::numeric_limits<double::max_digits10;
  410. double tolfeweps = numeric_limits<double>::epsilon() * 5;
  411. //double tol6decdigits = numeric_limits<float>::epsilon() * 2;
  412. // Check that can generate skew_normal distribution using the two convenience methods:
  413. boost::math::skew_normal w12(1., 2); // Using typedef.
  414. boost::math::skew_normal_distribution<> w01; // Use default unity values for mean and scale.
  415. // Note NOT myn01() as the compiler will interpret as a function!
  416. // Checks on constructors.
  417. // Default parameters.
  418. BOOST_CHECK_EQUAL(w01.location(), 0);
  419. BOOST_CHECK_EQUAL(w01.scale(), 1);
  420. BOOST_CHECK_EQUAL(w01.shape(), 0);
  421. skew_normal_distribution<> w23(2., 3); // Using default RealType double.
  422. BOOST_CHECK_EQUAL(w23.scale(), 3);
  423. BOOST_CHECK_EQUAL(w23.shape(), 0);
  424. skew_normal_distribution<> w123(1., 2., 3.); // Using default RealType double.
  425. BOOST_CHECK_EQUAL(w123.location(), 1.);
  426. BOOST_CHECK_EQUAL(w123.scale(), 2.);
  427. BOOST_CHECK_EQUAL(w123.shape(), 3.);
  428. BOOST_CHECK_CLOSE_FRACTION(mean(w01), static_cast<double>(0), tolfeweps); // Default mean == zero
  429. BOOST_CHECK_CLOSE_FRACTION(scale(w01), static_cast<double>(1), tolfeweps); // Default scale == unity
  430. // Basic sanity-check spot values for all floating-point types..
  431. // (Parameter value, arbitrarily zero, only communicates the floating point type).
  432. test_spots(0.0F); // Test float. OK at decdigits = 0 tolerance = 0.0001 %
  433. test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 %
  434. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  435. test_spots(0.0L); // Test long double.
  436. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  437. test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
  438. #endif
  439. #else
  440. std::cout << "<note>The long double tests have been disabled on this platform "
  441. "either because the long double overloads of the usual math functions are "
  442. "not available at all, or because they are too inaccurate for these tests "
  443. "to pass.</note>" << std::endl;
  444. #endif
  445. /* */
  446. } // BOOST_AUTO_TEST_CASE( test_main )
  447. /*
  448. Output:
  449. */