inverse_gaussian_example.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. // wald_example.cpp or inverse_gaussian_example.cpp
  2. // Copyright Paul A. Bristow 2010.
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // Example of using the Inverse Gaussian (or Inverse Normal) distribution.
  8. // The Wald Distribution is
  9. // Note that this file contains Quickbook mark-up as well as code
  10. // and comments, don't change any of the special comment mark-ups!
  11. //[inverse_gaussian_basic1
  12. /*`
  13. First we need some includes to access the normal distribution
  14. (and some std output of course).
  15. */
  16. #ifdef _MSC_VER
  17. # pragma warning (disable : 4224)
  18. # pragma warning (disable : 4189)
  19. # pragma warning (disable : 4100)
  20. # pragma warning (disable : 4224)
  21. # pragma warning (disable : 4512)
  22. # pragma warning (disable : 4702)
  23. # pragma warning (disable : 4127)
  24. #endif
  25. //#define BOOST_MATH_INSTRUMENT
  26. #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
  27. #define BOOST_MATH_DOMAIN_ERROR_POLICY ignore_error
  28. #include <boost/math/distributions/inverse_gaussian.hpp> // for inverse_gaussian_distribution
  29. using boost::math::inverse_gaussian; // typedef provides default type is double.
  30. using boost::math::inverse_gaussian_distribution; // for inverse gaussian distribution.
  31. #include <boost/math/distributions/normal.hpp> // for normal_distribution
  32. using boost::math::normal; // typedef provides default type is double.
  33. #include <boost/array.hpp>
  34. using boost::array;
  35. #include <iostream>
  36. using std::cout; using std::endl; using std::left; using std::showpoint; using std::noshowpoint;
  37. #include <iomanip>
  38. using std::setw; using std::setprecision;
  39. #include <limits>
  40. using std::numeric_limits;
  41. #include <sstream>
  42. using std::string;
  43. #include <string>
  44. using std::stringstream;
  45. // const double tol = 3 * numeric_limits<double>::epsilon();
  46. int main()
  47. {
  48. cout << "Example: Inverse Gaussian Distribution."<< endl;
  49. try
  50. {
  51. double tolfeweps = numeric_limits<double>::epsilon();
  52. //cout << "Tolerance = " << tol << endl;
  53. int precision = 17; // traditional tables are only computed to much lower precision.
  54. cout.precision(17); // std::numeric_limits<double>::max_digits10; for 64-bit doubles.
  55. // Traditional tables and values.
  56. double step = 0.2; // in z
  57. double range = 4; // min and max z = -range to +range.
  58. // Construct a (standard) inverse gaussian distribution s
  59. inverse_gaussian w11(1, 1);
  60. // (default mean = units, and standard deviation = unity)
  61. cout << "(Standard) Inverse Gaussian distribution, mean = "<< w11.mean()
  62. << ", scale = " << w11.scale() << endl;
  63. /*` First the probability distribution function (pdf).
  64. */
  65. cout << "Probability distribution function (pdf) values" << endl;
  66. cout << " z " " pdf " << endl;
  67. cout.precision(5);
  68. for (double z = (numeric_limits<double>::min)(); z < range + step; z += step)
  69. {
  70. cout << left << setprecision(3) << setw(6) << z << " "
  71. << setprecision(precision) << setw(12) << pdf(w11, z) << endl;
  72. }
  73. cout.precision(6); // default
  74. /*`And the area under the normal curve from -[infin] up to z,
  75. the cumulative distribution function (cdf).
  76. */
  77. // For a (default) inverse gaussian distribution.
  78. cout << "Integral (area under the curve) from 0 up to z (cdf) " << endl;
  79. cout << " z " " cdf " << endl;
  80. for (double z = (numeric_limits<double>::min)(); z < range + step; z += step)
  81. {
  82. cout << left << setprecision(3) << setw(6) << z << " "
  83. << setprecision(precision) << setw(12) << cdf(w11, z) << endl;
  84. }
  85. /*`giving the following table:
  86. [pre
  87. z pdf
  88. 2.23e-308 -1.#IND
  89. 0.2 0.90052111680384117
  90. 0.4 1.0055127039453111
  91. 0.6 0.75123750098955733
  92. 0.8 0.54377310461643302
  93. 1 0.3989422804014327
  94. 1.2 0.29846949816803292
  95. 1.4 0.2274579835638664
  96. 1.6 0.17614566625628389
  97. 1.8 0.13829083543591469
  98. 2 0.10984782236693062
  99. 2.2 0.088133964251182237
  100. 2.4 0.071327382959107177
  101. 2.6 0.058162562161661699
  102. 2.8 0.047742223328567722
  103. 3 0.039418357969819712
  104. 3.2 0.032715223861241892
  105. 3.4 0.027278388940958308
  106. 3.6 0.022840312999395804
  107. 3.8 0.019196657941016954
  108. 4 0.016189699458236451
  109. Integral (area under the curve) from 0 up to z (cdf)
  110. z cdf
  111. 2.23e-308 0
  112. 0.2 0.063753567519976254
  113. 0.4 0.2706136704424541
  114. 0.6 0.44638391340412931
  115. 0.8 0.57472390962590925
  116. 1 0.66810200122317065
  117. 1.2 0.73724578422952536
  118. 1.4 0.78944214237790356
  119. 1.6 0.82953458108474554
  120. 1.8 0.86079282968276671
  121. 2 0.88547542598600626
  122. 2.2 0.90517870624273966
  123. 2.4 0.92105495653509362
  124. 2.6 0.93395164268166786
  125. 2.8 0.94450240360053817
  126. 3 0.95318792074278835
  127. 3.2 0.96037753019309191
  128. 3.4 0.96635823989417369
  129. 3.6 0.97135533107998406
  130. 3.8 0.97554722413538364
  131. 4 0.97907636417888622
  132. ]
  133. /*`We can get the inverse, the quantile, percentile, percentage point, or critical value
  134. for a probability for a few probability from the above table, for z = 0.4, 1.0, 2.0:
  135. */
  136. cout << quantile(w11, 0.27061367044245421 ) << endl; // 0.4
  137. cout << quantile(w11, 0.66810200122317065) << endl; // 1.0
  138. cout << quantile(w11, 0.88547542598600615) << endl; // 2.0
  139. /*`turning the expect values apart from some 'computational noise' in the least significant bit or two.
  140. [pre
  141. 0.40000000000000008
  142. 0.99999999999999967
  143. 1.9999999999999973
  144. ]
  145. */
  146. // cout << "pnorm01(-0.406053) " << pnorm01(-0.406053) << ", cdfn01(-0.406053) = " << cdf(n01, -0.406053) << endl;
  147. //cout << "pnorm01(0.5) = " << pnorm01(0.5) << endl; // R pnorm(0.5,0,1) = 0.6914625 == 0.69146246127401312
  148. // R qnorm(0.6914625,0,1) = 0.5
  149. // formatC(SuppDists::qinvGauss(0.3649755481729598, 1, 1), digits=17) [1] "0.50000000969034875"
  150. // formatC(SuppDists::dinvGauss(0.01, 1, 1), digits=17) [1] "2.0811768202028392e-19"
  151. // formatC(SuppDists::pinvGauss(0.01, 1, 1), digits=17) [1] "4.122313403318778e-23"
  152. //cout << " qinvgauss(0.3649755481729598, 1, 1) = " << qinvgauss(0.3649755481729598, 1, 1) << endl; // 0.5
  153. // cout << quantile(s, 0.66810200122317065) << endl; // expect 1, get 0.50517388467190727
  154. //cout << " qinvgauss(0.62502320258649202, 1, 1) = " << qinvgauss(0.62502320258649202, 1, 1) << endl; // 0.9
  155. //cout << " qinvgauss(0.063753567519976254, 1, 1) = " << qinvgauss(0.063753567519976254, 1, 1) << endl; // 0.2
  156. //cout << " qinvgauss(0.0040761113207110162, 1, 1) = " << qinvgauss(0.0040761113207110162, 1, 1) << endl; // 0.1
  157. //double x = 1.; // SuppDists::pinvGauss(0.4, 1,1) [1] 0.2706137
  158. //double c = pinvgauss(x, 1, 1); // 0.3649755481729598 == cdf(x, 1,1) 0.36497554817295974
  159. //cout << " pinvgauss(x, 1, 1) = " << c << endl; // pinvgauss(x, 1, 1) = 0.27061367044245421
  160. //double p = pdf(w11, x);
  161. //double c = cdf(w11, x); // cdf(1, 1, 1) = 0.66810200122317065
  162. //cout << "cdf(" << x << ", " << w11.mean() << ", "<< w11.scale() << ") = " << c << endl; // cdf(x, 1, 1) 0.27061367044245421
  163. //cout << "pdf(" << x << ", " << w11.mean() << ", "<< w11.scale() << ") = " << p << endl;
  164. //double q = quantile(w11, c);
  165. //cout << "quantile(w11, " << c << ") = " << q << endl;
  166. //cout << "quantile(w11, 4.122313403318778e-23) = "<< quantile(w11, 4.122313403318778e-23) << endl; // quantile
  167. //cout << "quantile(w11, 4.8791443010851493e-219) = " << quantile(w11, 4.8791443010851493e-219) << endl; // quantile
  168. //double c1 = 1 - cdf(w11, x); // 1 - cdf(1, 1, 1) = 0.33189799877682935
  169. //cout << "1 - cdf(" << x << ", " << w11.mean() << ", " << w11.scale() << ") = " << c1 << endl; // cdf(x, 1, 1) 0.27061367044245421
  170. //double cc = cdf(complement(w11, x));
  171. //cout << "cdf(complement(" << x << ", " << w11.mean() << ", "<< w11.scale() << ")) = " << cc << endl; // cdf(x, 1, 1) 0.27061367044245421
  172. //// 1 - cdf(1000, 1, 1) = 0
  173. //// cdf(complement(1000, 1, 1)) = 4.8694344366900402e-222
  174. //cout << "quantile(w11, " << c << ") = "<< quantile(w11, c) << endl; // quantile = 0.99999999999999978 == x = 1
  175. //cout << "quantile(w11, " << c << ") = "<< quantile(w11, 1 - c) << endl; // quantile complement. quantile(w11, 0.66810200122317065) = 0.46336593652340152
  176. // cout << "quantile(complement(w11, " << c << ")) = " << quantile(complement(w11, c)) << endl; // quantile complement = 0.46336593652340163
  177. // cdf(1, 1, 1) = 0.66810200122317065
  178. // 1 - cdf(1, 1, 1) = 0.33189799877682935
  179. // cdf(complement(1, 1, 1)) = 0.33189799877682929
  180. // quantile(w11, 0.66810200122317065) = 0.99999999999999978
  181. // 1 - quantile(w11, 0.66810200122317065) = 2.2204460492503131e-016
  182. // quantile(complement(w11, 0.33189799877682929)) = 0.99999999999999989
  183. // qinvgauss(c, 1, 1) = 0.3999999999999998
  184. // SuppDists::qinvGauss(0.270613670442454, 1, 1) [1] 0.4
  185. /*
  186. double qs = pinvgaussU(c, 1, 1); //
  187. cout << "qinvgaussU(c, 1, 1) = " << qs << endl; // qinvgaussU(c, 1, 1) = 0.86567442459240929
  188. // > z=q - exp(c) * p [1] 0.8656744 qs 0.86567442459240929 double
  189. // Is this the complement?
  190. cout << "qgamma(0.2, 0.5, 1) expect 0.0320923 = " << qgamma(0.2, 0.5, 1) << endl;
  191. // qgamma(0.2, 0.5, 1) expect 0.0320923 = 0.032092377333650807
  192. cout << "qinvgauss(pinvgauss(x, 1, 1) = " << q
  193. << ", diff = " << x - q << ", fraction = " << (x - q) /x << endl; // 0.5
  194. */ // > SuppDists::pinvGauss(0.02, 1,1) [1] 4.139176e-12
  195. // > SuppDists::qinvGauss(4.139176e-12, 1,1) [1] 0.02000000
  196. // pinvGauss(1,1,1) = 0.668102 C++ == 0.66810200122317065
  197. // qinvGauss(0.668102,1,1) = 1
  198. // SuppDists::pinvGauss(0.3,1,1) = 0.1657266
  199. // cout << "qinvGauss(0.0040761113207110162, 1, 1) = " << qinvgauss(0.0040761113207110162, 1, 1) << endl;
  200. //cout << "quantile(s, 0.1657266) = " << quantile(s, 0.1657266) << endl; // expect 1.
  201. //wald s12(2, 1);
  202. //cout << "qinvGauss(0.3, 2, 1) = " << qinvgauss(0.3, 2, 1) << endl; // SuppDists::qinvGauss(0.3,2,1) == 0.58288065635052944
  203. //// but actually get qinvGauss(0.3, 2, 1) = 0.58288064777632187
  204. //cout << "cdf(s12, 0.3) = " << cdf(s12, 0.3) << endl; // cdf(s12, 0.3) = 0.10895339868447573
  205. // using boost::math::wald;
  206. //cout.precision(6);
  207. /*
  208. double m = 1;
  209. double l = 1;
  210. double x = 0.1;
  211. //c = cdf(w, x);
  212. double p = pinvgauss(x, m, l);
  213. cout << "x = " << x << ", pinvgauss(x, m, l) = " << p << endl; // R 0.4 0.2706137
  214. double qg = qgamma(1.- p, 0.5, 1.0, true, false);
  215. cout << " qgamma(1.- p, 0.5, 1.0, true, false) = " << qg << endl; // 0.606817
  216. double g = guess_whitmore(p, m, l);
  217. cout << "m = " << m << ", l = " << l << ", x = " << x << ", guess = " << g
  218. << ", diff = " << (x - g) << endl;
  219. g = guess_wheeler(p, m, l);
  220. cout << "m = " << m << ", l = " << l << ", x = " << x << ", guess = " << g
  221. << ", diff = " << (x - g) << endl;
  222. g = guess_bagshaw(p, m, l);
  223. cout << "m = " << m << ", l = " << l << ", x = " << x << ", guess = " << g
  224. << ", diff = " << (x - g) << endl;
  225. // m = 1, l = 10, x = 0.9, guess = 0.89792, diff = 0.00231075 so a better fit.
  226. // x = 0.9, guess = 0.887907
  227. // x = 0.5, guess = 0.474977
  228. // x = 0.4, guess = 0.369597
  229. // x = 0.2, guess = 0.155196
  230. // m = 1, l = 2, x = 0.9, guess = 1.0312, diff = -0.145778
  231. // m = 1, l = 2, x = 0.1, guess = 0.122201, diff = -0.222013
  232. // m = 1, l = 2, x = 0.2, guess = 0.299326, diff = -0.49663
  233. // m = 1, l = 2, x = 0.5, guess = 1.00437, diff = -1.00875
  234. // m = 1, l = 2, x = 0.7, guess = 1.01517, diff = -0.450247
  235. double ls[7] = {0.1, 0.2, 0.5, 1., 2., 10, 100}; // scale values.
  236. double ms[10] = {0.001, 0.02, 0.1, 0.2, 0.5, 0.9, 1., 2., 10, 100}; // mean values.
  237. */
  238. cout.precision(6); // Restore to default.
  239. } // try
  240. catch(const std::exception& e)
  241. { // Always useful to include try & catch blocks because default policies
  242. // are to throw exceptions on arguments that cause errors like underflow, overflow.
  243. // Lacking try & catch blocks, the program will abort without a message below,
  244. // which may give some helpful clues as to the cause of the exception.
  245. std::cout <<
  246. "\n""Message from thrown exception was:\n " << e.what() << std::endl;
  247. }
  248. return 0;
  249. } // int main()
  250. /*
  251. Output is:
  252. inverse_gaussian_example.cpp
  253. inverse_gaussian_example.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Debug\inverse_gaussian_example.exe
  254. Example: Inverse Gaussian Distribution.
  255. (Standard) Inverse Gaussian distribution, mean = 1, scale = 1
  256. Probability distribution function (pdf) values
  257. z pdf
  258. 2.23e-308 -1.#IND
  259. 0.2 0.90052111680384117
  260. 0.4 1.0055127039453111
  261. 0.6 0.75123750098955733
  262. 0.8 0.54377310461643302
  263. 1 0.3989422804014327
  264. 1.2 0.29846949816803292
  265. 1.4 0.2274579835638664
  266. 1.6 0.17614566625628389
  267. 1.8 0.13829083543591469
  268. 2 0.10984782236693062
  269. 2.2 0.088133964251182237
  270. 2.4 0.071327382959107177
  271. 2.6 0.058162562161661699
  272. 2.8 0.047742223328567722
  273. 3 0.039418357969819712
  274. 3.2 0.032715223861241892
  275. 3.4 0.027278388940958308
  276. 3.6 0.022840312999395804
  277. 3.8 0.019196657941016954
  278. 4 0.016189699458236451
  279. Integral (area under the curve) from 0 up to z (cdf)
  280. z cdf
  281. 2.23e-308 0
  282. 0.2 0.063753567519976254
  283. 0.4 0.2706136704424541
  284. 0.6 0.44638391340412931
  285. 0.8 0.57472390962590925
  286. 1 0.66810200122317065
  287. 1.2 0.73724578422952536
  288. 1.4 0.78944214237790356
  289. 1.6 0.82953458108474554
  290. 1.8 0.86079282968276671
  291. 2 0.88547542598600626
  292. 2.2 0.90517870624273966
  293. 2.4 0.92105495653509362
  294. 2.6 0.93395164268166786
  295. 2.8 0.94450240360053817
  296. 3 0.95318792074278835
  297. 3.2 0.96037753019309191
  298. 3.4 0.96635823989417369
  299. 3.6 0.97135533107998406
  300. 3.8 0.97554722413538364
  301. 4 0.97907636417888622
  302. 0.40000000000000008
  303. 0.99999999999999967
  304. 1.9999999999999973
  305. > SuppDists::dinvGauss(2, 1, 1) [1] 0.1098478
  306. > SuppDists::dinvGauss(0.4, 1, 1) [1] 1.005513
  307. > SuppDists::dinvGauss(0.5, 1, 1) [1] 0.8787826
  308. > SuppDists::dinvGauss(0.39, 1, 1) [1] 1.016559
  309. > SuppDists::dinvGauss(0.38, 1, 1) [1] 1.027006
  310. > SuppDists::dinvGauss(0.37, 1, 1) [1] 1.036748
  311. > SuppDists::dinvGauss(0.36, 1, 1) [1] 1.045661
  312. > SuppDists::dinvGauss(0.35, 1, 1) [1] 1.053611
  313. > SuppDists::dinvGauss(0.3, 1, 1) [1] 1.072888
  314. > SuppDists::dinvGauss(0.1, 1, 1) [1] 0.2197948
  315. > SuppDists::dinvGauss(0.2, 1, 1) [1] 0.9005211
  316. >
  317. x = 0.3 [1, 1] 1.0728879234594337 // R SuppDists::dinvGauss(0.3, 1, 1) [1] 1.072888
  318. x = 1 [1, 1] 0.3989422804014327
  319. 0 " NA"
  320. 1 "0.3989422804014327"
  321. 2 "0.10984782236693059"
  322. 3 "0.039418357969819733"
  323. 4 "0.016189699458236468"
  324. 5 "0.007204168934430732"
  325. 6 "0.003379893528659049"
  326. 7 "0.0016462878258114036"
  327. 8 "0.00082460931140859956"
  328. 9 "0.00042207355643694234"
  329. 10 "0.00021979480031862676"
  330. [1] " NA" " 0.690988298942671" "0.11539974210409144"
  331. [4] "0.01799698883772935" "0.0029555399206496469" "0.00050863023587406587"
  332. [7] "9.0761842931362914e-05" "1.6655279133132795e-05" "3.1243174913715429e-06"
  333. [10] "5.96530227727434e-07" "1.1555606328299836e-07"
  334. matC(dinvGauss(0:10, 1, 3), digits=17) df = 3
  335. [1] " NA" " 0.690988298942671" "0.11539974210409144"
  336. [4] "0.01799698883772935" "0.0029555399206496469" "0.00050863023587406587"
  337. [7] "9.0761842931362914e-05" "1.6655279133132795e-05" "3.1243174913715429e-06"
  338. [10] "5.96530227727434e-07" "1.1555606328299836e-07"
  339. $title
  340. [1] "Inverse Gaussian"
  341. $nu
  342. [1] 1
  343. $lambda
  344. [1] 3
  345. $Mean
  346. [1] 1
  347. $Median
  348. [1] 0.8596309
  349. $Mode
  350. [1] 0.618034
  351. $Variance
  352. [1] 0.3333333
  353. $SD
  354. [1] 0.5773503
  355. $ThirdCentralMoment
  356. [1] 0.3333333
  357. $FourthCentralMoment
  358. [1] 0.8888889
  359. $PearsonsSkewness...mean.minus.mode.div.SD
  360. [1] 0.6615845
  361. $Skewness...sqrtB1
  362. [1] 1.732051
  363. $Kurtosis...B2.minus.3
  364. [1] 5
  365. Example: Wald distribution.
  366. (Standard) Wald distribution, mean = 1, scale = 1
  367. 1 dx = 0.24890250442652451, x = 0.70924622051646713
  368. 2 dx = -0.038547954953794553, x = 0.46034371608994262
  369. 3 dx = -0.0011074090830291131, x = 0.49889167104373716
  370. 4 dx = -9.1987259926368029e-007, x = 0.49999908012676625
  371. 5 dx = -6.346513344581067e-013, x = 0.49999999999936551
  372. dx = 6.3168242705156857e-017 at i = 6
  373. qinvgauss(0.3649755481729598, 1, 1) = 0.50000000000000011
  374. 1 dx = 0.6719944578376621, x = 1.3735318786222666
  375. 2 dx = -0.16997432635769361, x = 0.70153742078460446
  376. 3 dx = -0.027865119206495724, x = 0.87151174714229807
  377. 4 dx = -0.00062283290009492603, x = 0.89937686634879377
  378. 5 dx = -3.0075104108208687e-007, x = 0.89999969924888867
  379. 6 dx = -7.0485322513588089e-014, x = 0.89999999999992975
  380. 7 dx = 9.557331866250277e-016, x = 0.90000000000000024
  381. dx = 0 at i = 8
  382. qinvgauss(0.62502320258649202, 1, 1) = 0.89999999999999925
  383. 1 dx = -0.0052296256747447678, x = 0.19483508278446249
  384. 2 dx = 6.4699046853900505e-005, x = 0.20006470845920726
  385. 3 dx = 9.4123530465288137e-009, x = 0.20000000941235335
  386. 4 dx = 2.7739513919147025e-016, x = 0.20000000000000032
  387. dx = 1.5410841066192808e-016 at i = 5
  388. qinvgauss(0.063753567519976254, 1, 1) = 0.20000000000000004
  389. 1 dx = -1, x = -0.46073286697416105
  390. 2 dx = 0.47665501251497061, x = 0.53926713302583895
  391. 3 dx = -0.171105768635964, x = 0.062612120510868341
  392. 4 dx = 0.091490360797512563, x = 0.23371788914683234
  393. 5 dx = 0.029410311722649803, x = 0.14222752834931979
  394. 6 dx = 0.010761845493592421, x = 0.11281721662666999
  395. 7 dx = 0.0019864890597643035, x = 0.10205537113307757
  396. 8 dx = 6.8800383732599561e-005, x = 0.10006888207331327
  397. 9 dx = 8.1689466405590418e-008, x = 0.10000008168958067
  398. 10 dx = 1.133634672475146e-013, x = 0.10000000000011428
  399. 11 dx = 5.9588135045224526e-016, x = 0.10000000000000091
  400. 12 dx = 3.433223674791152e-016, x = 0.10000000000000031
  401. dx = 9.0763384505974048e-017 at i = 13
  402. qinvgauss(0.0040761113207110162, 1, 1) = 0.099999999999999964
  403. wald_example.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Debug\wald_example.exe
  404. Example: Wald distribution.
  405. Tolerance = 6.66134e-016
  406. (Standard) Wald distribution, mean = 1, scale = 1
  407. cdf(x, 1,1) 4.1390252102096375e-012
  408. qinvgauss(pinvgauss(x, 1, 1) = 0.020116801973767886, diff = -0.00011680197376788548, fraction = -0.005840098688394274
  409. ____________________________________________________________
  410. wald 1, 1
  411. x = 0.02, diff x - qinvgauss(cdf) = -0.00011680197376788548
  412. x = 0.10000000000000001, diff x - qinvgauss(cdf) = 8.7430063189231078e-016
  413. x = 0.20000000000000001, diff x - qinvgauss(cdf) = -1.1102230246251565e-016
  414. x = 0.29999999999999999, diff x - qinvgauss(cdf) = 0
  415. x = 0.40000000000000002, diff x - qinvgauss(cdf) = 2.2204460492503131e-016
  416. x = 0.5, diff x - qinvgauss(cdf) = -1.1102230246251565e-016
  417. x = 0.59999999999999998, diff x - qinvgauss(cdf) = 1.1102230246251565e-016
  418. x = 0.80000000000000004, diff x - qinvgauss(cdf) = 1.1102230246251565e-016
  419. x = 0.90000000000000002, diff x - qinvgauss(cdf) = 0
  420. x = 0.98999999999999999, diff x - qinvgauss(cdf) = -1.1102230246251565e-016
  421. x = 0.999, diff x - qinvgauss(cdf) = -1.1102230246251565e-016
  422. */