inverse_gaussian.hpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. // Copyright John Maddock 2010.
  2. // Copyright Paul A. Bristow 2010.
  3. // Copyright Matt Borland 2024.
  4. // Use, modification and distribution are subject to the
  5. // Boost Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_STATS_INVERSE_GAUSSIAN_HPP
  8. #define BOOST_STATS_INVERSE_GAUSSIAN_HPP
  9. #ifdef _MSC_VER
  10. #pragma warning(disable: 4512) // assignment operator could not be generated
  11. #endif
  12. // http://en.wikipedia.org/wiki/Normal-inverse_Gaussian_distribution
  13. // http://mathworld.wolfram.com/InverseGaussianDistribution.html
  14. // The normal-inverse Gaussian distribution
  15. // also called the Wald distribution (some sources limit this to when mean = 1).
  16. // It is the continuous probability distribution
  17. // that is defined as the normal variance-mean mixture where the mixing density is the
  18. // inverse Gaussian distribution. The tails of the distribution decrease more slowly
  19. // than the normal distribution. It is therefore suitable to model phenomena
  20. // where numerically large values are more probable than is the case for the normal distribution.
  21. // The Inverse Gaussian distribution was first studied in relationship to Brownian motion.
  22. // In 1956 M.C.K. Tweedie used the name 'Inverse Gaussian' because there is an inverse
  23. // relationship between the time to cover a unit distance and distance covered in unit time.
  24. // Examples are returns from financial assets and turbulent wind speeds.
  25. // The normal-inverse Gaussian distributions form
  26. // a subclass of the generalised hyperbolic distributions.
  27. // See also
  28. // http://en.wikipedia.org/wiki/Normal_distribution
  29. // http://www.itl.nist.gov/div898/handbook/eda/section3/eda3661.htm
  30. // Also:
  31. // Weisstein, Eric W. "Normal Distribution."
  32. // From MathWorld--A Wolfram Web Resource.
  33. // http://mathworld.wolfram.com/NormalDistribution.html
  34. // http://www.jstatsoft.org/v26/i04/paper General class of inverse Gaussian distributions.
  35. // ig package - withdrawn but at http://cran.r-project.org/src/contrib/Archive/ig/
  36. // http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/SuppDists/html/inverse_gaussian.html
  37. // R package for dinverse_gaussian, ...
  38. // http://www.statsci.org/s/inverse_gaussian.s and http://www.statsci.org/s/inverse_gaussian.html
  39. #include <boost/math/tools/config.hpp>
  40. #include <boost/math/tools/cstdint.hpp>
  41. #include <boost/math/special_functions/erf.hpp> // for erf/erfc.
  42. #include <boost/math/distributions/complement.hpp>
  43. #include <boost/math/distributions/detail/common_error_handling.hpp>
  44. #include <boost/math/distributions/normal.hpp>
  45. #include <boost/math/distributions/gamma.hpp> // for gamma function
  46. #include <boost/math/tools/tuple.hpp>
  47. #include <boost/math/tools/roots.hpp>
  48. #include <boost/math/policies/policy.hpp>
  49. #include <boost/math/policies/error_handling.hpp>
  50. namespace boost{ namespace math{
  51. template <class RealType = double, class Policy = policies::policy<> >
  52. class inverse_gaussian_distribution
  53. {
  54. public:
  55. using value_type = RealType;
  56. using policy_type = Policy;
  57. BOOST_MATH_GPU_ENABLED explicit inverse_gaussian_distribution(RealType l_mean = 1, RealType l_scale = 1)
  58. : m_mean(l_mean), m_scale(l_scale)
  59. { // Default is a 1,1 inverse_gaussian distribution.
  60. constexpr auto function = "boost::math::inverse_gaussian_distribution<%1%>::inverse_gaussian_distribution";
  61. RealType result;
  62. detail::check_scale(function, l_scale, &result, Policy());
  63. detail::check_location(function, l_mean, &result, Policy());
  64. detail::check_x_gt0(function, l_mean, &result, Policy());
  65. }
  66. BOOST_MATH_GPU_ENABLED RealType mean()const
  67. { // alias for location.
  68. return m_mean; // aka mu
  69. }
  70. // Synonyms, provided to allow generic use of find_location and find_scale.
  71. BOOST_MATH_GPU_ENABLED RealType location()const
  72. { // location, aka mu.
  73. return m_mean;
  74. }
  75. BOOST_MATH_GPU_ENABLED RealType scale()const
  76. { // scale, aka lambda.
  77. return m_scale;
  78. }
  79. BOOST_MATH_GPU_ENABLED RealType shape()const
  80. { // shape, aka phi = lambda/mu.
  81. return m_scale / m_mean;
  82. }
  83. private:
  84. //
  85. // Data members:
  86. //
  87. RealType m_mean; // distribution mean or location, aka mu.
  88. RealType m_scale; // distribution standard deviation or scale, aka lambda.
  89. }; // class normal_distribution
  90. using inverse_gaussian = inverse_gaussian_distribution<double>;
  91. #ifdef __cpp_deduction_guides
  92. template <class RealType>
  93. inverse_gaussian_distribution(RealType)->inverse_gaussian_distribution<typename boost::math::tools::promote_args<RealType>::type>;
  94. template <class RealType>
  95. inverse_gaussian_distribution(RealType,RealType)->inverse_gaussian_distribution<typename boost::math::tools::promote_args<RealType>::type>;
  96. #endif
  97. template <class RealType, class Policy>
  98. BOOST_MATH_GPU_ENABLED inline boost::math::pair<RealType, RealType> range(const inverse_gaussian_distribution<RealType, Policy>& /*dist*/)
  99. { // Range of permissible values for random variable x, zero to max.
  100. using boost::math::tools::max_value;
  101. return boost::math::pair<RealType, RealType>(static_cast<RealType>(0.), max_value<RealType>()); // - to + max value.
  102. }
  103. template <class RealType, class Policy>
  104. BOOST_MATH_GPU_ENABLED inline boost::math::pair<RealType, RealType> support(const inverse_gaussian_distribution<RealType, Policy>& /*dist*/)
  105. { // Range of supported values for random variable x, zero to max.
  106. // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
  107. using boost::math::tools::max_value;
  108. return boost::math::pair<RealType, RealType>(static_cast<RealType>(0.), max_value<RealType>()); // - to + max value.
  109. }
  110. template <class RealType, class Policy>
  111. BOOST_MATH_GPU_ENABLED inline RealType pdf(const inverse_gaussian_distribution<RealType, Policy>& dist, const RealType& x)
  112. { // Probability Density Function
  113. BOOST_MATH_STD_USING // for ADL of std functions
  114. RealType scale = dist.scale();
  115. RealType mean = dist.mean();
  116. RealType result = 0;
  117. constexpr auto function = "boost::math::pdf(const inverse_gaussian_distribution<%1%>&, %1%)";
  118. if(false == detail::check_scale(function, scale, &result, Policy()))
  119. {
  120. return result;
  121. }
  122. if(false == detail::check_location(function, mean, &result, Policy()))
  123. {
  124. return result;
  125. }
  126. if(false == detail::check_x_gt0(function, mean, &result, Policy()))
  127. {
  128. return result;
  129. }
  130. if(false == detail::check_positive_x(function, x, &result, Policy()))
  131. {
  132. return result;
  133. }
  134. if (x == 0)
  135. {
  136. return 0; // Convenient, even if not defined mathematically.
  137. }
  138. result =
  139. sqrt(scale / (constants::two_pi<RealType>() * x * x * x))
  140. * exp(-scale * (x - mean) * (x - mean) / (2 * x * mean * mean));
  141. return result;
  142. } // pdf
  143. template <class RealType, class Policy>
  144. BOOST_MATH_GPU_ENABLED inline RealType logpdf(const inverse_gaussian_distribution<RealType, Policy>& dist, const RealType& x)
  145. { // Probability Density Function
  146. BOOST_MATH_STD_USING // for ADL of std functions
  147. RealType scale = dist.scale();
  148. RealType mean = dist.mean();
  149. RealType result = -boost::math::numeric_limits<RealType>::infinity();
  150. constexpr auto function = "boost::math::logpdf(const inverse_gaussian_distribution<%1%>&, %1%)";
  151. if(false == detail::check_scale(function, scale, &result, Policy()))
  152. {
  153. return result;
  154. }
  155. if(false == detail::check_location(function, mean, &result, Policy()))
  156. {
  157. return result;
  158. }
  159. if(false == detail::check_x_gt0(function, mean, &result, Policy()))
  160. {
  161. return result;
  162. }
  163. if(false == detail::check_positive_x(function, x, &result, Policy()))
  164. {
  165. return result;
  166. }
  167. if (x == 0)
  168. {
  169. return boost::math::numeric_limits<RealType>::quiet_NaN(); // Convenient, even if not defined mathematically. log(0)
  170. }
  171. const RealType two_pi = boost::math::constants::two_pi<RealType>();
  172. result = (-scale*pow(mean - x, RealType(2))/(mean*mean*x) + log(scale) - 3*log(x) - log(two_pi)) / 2;
  173. return result;
  174. } // pdf
  175. template <class RealType, class Policy>
  176. BOOST_MATH_GPU_ENABLED inline RealType cdf(const inverse_gaussian_distribution<RealType, Policy>& dist, const RealType& x)
  177. { // Cumulative Density Function.
  178. BOOST_MATH_STD_USING // for ADL of std functions.
  179. RealType scale = dist.scale();
  180. RealType mean = dist.mean();
  181. constexpr auto function = "boost::math::cdf(const inverse_gaussian_distribution<%1%>&, %1%)";
  182. RealType result = 0;
  183. if(false == detail::check_scale(function, scale, &result, Policy()))
  184. {
  185. return result;
  186. }
  187. if(false == detail::check_location(function, mean, &result, Policy()))
  188. {
  189. return result;
  190. }
  191. if (false == detail::check_x_gt0(function, mean, &result, Policy()))
  192. {
  193. return result;
  194. }
  195. if(false == detail::check_positive_x(function, x, &result, Policy()))
  196. {
  197. return result;
  198. }
  199. if (x == 0)
  200. {
  201. return 0; // Convenient, even if not defined mathematically.
  202. }
  203. // Problem with this formula for large scale > 1000 or small x
  204. // so use normal distribution version:
  205. // Wikipedia CDF equation http://en.wikipedia.org/wiki/Inverse_Gaussian_distribution.
  206. normal_distribution<RealType> n01;
  207. RealType n0 = sqrt(scale / x);
  208. n0 *= ((x / mean) -1);
  209. RealType n1 = cdf(n01, n0);
  210. RealType expfactor = exp(2 * scale / mean);
  211. RealType n3 = - sqrt(scale / x);
  212. n3 *= (x / mean) + 1;
  213. RealType n4 = cdf(n01, n3);
  214. result = n1 + expfactor * n4;
  215. return result;
  216. } // cdf
  217. template <class RealType, class Policy>
  218. struct inverse_gaussian_quantile_functor
  219. {
  220. BOOST_MATH_GPU_ENABLED inverse_gaussian_quantile_functor(const boost::math::inverse_gaussian_distribution<RealType, Policy> dist, RealType const& p)
  221. : distribution(dist), prob(p)
  222. {
  223. }
  224. BOOST_MATH_GPU_ENABLED boost::math::tuple<RealType, RealType> operator()(RealType const& x)
  225. {
  226. RealType c = cdf(distribution, x);
  227. RealType fx = c - prob; // Difference cdf - value - to minimize.
  228. RealType dx = pdf(distribution, x); // pdf is 1st derivative.
  229. // return both function evaluation difference f(x) and 1st derivative f'(x).
  230. return boost::math::make_tuple(fx, dx);
  231. }
  232. private:
  233. const boost::math::inverse_gaussian_distribution<RealType, Policy> distribution;
  234. RealType prob;
  235. };
  236. template <class RealType, class Policy>
  237. struct inverse_gaussian_quantile_complement_functor
  238. {
  239. BOOST_MATH_GPU_ENABLED inverse_gaussian_quantile_complement_functor(const boost::math::inverse_gaussian_distribution<RealType, Policy> dist, RealType const& p)
  240. : distribution(dist), prob(p)
  241. {
  242. }
  243. BOOST_MATH_GPU_ENABLED boost::math::tuple<RealType, RealType> operator()(RealType const& x)
  244. {
  245. RealType c = cdf(complement(distribution, x));
  246. RealType fx = c - prob; // Difference cdf - value - to minimize.
  247. RealType dx = -pdf(distribution, x); // pdf is 1st derivative.
  248. // return both function evaluation difference f(x) and 1st derivative f'(x).
  249. //return std::tr1::make_tuple(fx, dx); if available.
  250. return boost::math::make_tuple(fx, dx);
  251. }
  252. private:
  253. const boost::math::inverse_gaussian_distribution<RealType, Policy> distribution;
  254. RealType prob;
  255. };
  256. namespace detail
  257. {
  258. template <class RealType>
  259. BOOST_MATH_GPU_ENABLED inline RealType guess_ig(RealType p, RealType mu = 1, RealType lambda = 1)
  260. { // guess at random variate value x for inverse gaussian quantile.
  261. BOOST_MATH_STD_USING
  262. using boost::math::policies::policy;
  263. // Error type.
  264. using boost::math::policies::overflow_error;
  265. // Action.
  266. using boost::math::policies::ignore_error;
  267. using no_overthrow_policy = policy<overflow_error<ignore_error>>;
  268. RealType x; // result is guess at random variate value x.
  269. RealType phi = lambda / mu;
  270. if (phi > 2.)
  271. { // Big phi, so starting to look like normal Gaussian distribution.
  272. //
  273. // Whitmore, G.A. and Yalovsky, M.
  274. // A normalising logarithmic transformation for inverse Gaussian random variables,
  275. // Technometrics 20-2, 207-208 (1978), but using expression from
  276. // V Seshadri, Inverse Gaussian distribution (1998) ISBN 0387 98618 9, page 6.
  277. normal_distribution<RealType, no_overthrow_policy> n01;
  278. x = mu * exp(quantile(n01, p) / sqrt(phi) - 1/(2 * phi));
  279. }
  280. else
  281. { // phi < 2 so much less symmetrical with long tail,
  282. // so use gamma distribution as an approximation.
  283. using boost::math::gamma_distribution;
  284. // Define the distribution, using gamma_nooverflow:
  285. using gamma_nooverflow = gamma_distribution<RealType, no_overthrow_policy>;
  286. gamma_nooverflow g(static_cast<RealType>(0.5), static_cast<RealType>(1.));
  287. // R qgamma(0.2, 0.5, 1) = 0.0320923
  288. RealType qg = quantile(complement(g, p));
  289. x = lambda / (qg * 2);
  290. //
  291. if (x > mu/2) // x > mu /2?
  292. { // x too large for the gamma approximation to work well.
  293. //x = qgamma(p, 0.5, 1.0); // qgamma(0.270614, 0.5, 1) = 0.05983807
  294. RealType q = quantile(g, p);
  295. // x = mu * exp(q * static_cast<RealType>(0.1)); // Said to improve at high p
  296. // x = mu * x; // Improves at high p?
  297. x = mu * exp(q / sqrt(phi) - 1/(2 * phi));
  298. }
  299. }
  300. return x;
  301. } // guess_ig
  302. } // namespace detail
  303. template <class RealType, class Policy>
  304. BOOST_MATH_GPU_ENABLED inline RealType quantile(const inverse_gaussian_distribution<RealType, Policy>& dist, const RealType& p)
  305. {
  306. BOOST_MATH_STD_USING // for ADL of std functions.
  307. // No closed form exists so guess and use Newton Raphson iteration.
  308. RealType mean = dist.mean();
  309. RealType scale = dist.scale();
  310. constexpr auto function = "boost::math::quantile(const inverse_gaussian_distribution<%1%>&, %1%)";
  311. RealType result = 0;
  312. if(false == detail::check_scale(function, scale, &result, Policy()))
  313. return result;
  314. if(false == detail::check_location(function, mean, &result, Policy()))
  315. return result;
  316. if (false == detail::check_x_gt0(function, mean, &result, Policy()))
  317. return result;
  318. if(false == detail::check_probability(function, p, &result, Policy()))
  319. return result;
  320. if (p == 0)
  321. {
  322. return 0; // Convenient, even if not defined mathematically?
  323. }
  324. if (p == 1)
  325. { // overflow
  326. result = policies::raise_overflow_error<RealType>(function,
  327. "probability parameter is 1, but must be < 1!", Policy());
  328. return result; // infinity;
  329. }
  330. RealType guess = detail::guess_ig(p, dist.mean(), dist.scale());
  331. using boost::math::tools::max_value;
  332. RealType min = static_cast<RealType>(0); // Minimum possible value is bottom of range of distribution.
  333. RealType max = max_value<RealType>();// Maximum possible value is top of range.
  334. // int digits = std::numeric_limits<RealType>::digits; // Maximum possible binary digits accuracy for type T.
  335. // digits used to control how accurate to try to make the result.
  336. // To allow user to control accuracy versus speed,
  337. int get_digits = policies::digits<RealType, Policy>();// get digits from policy,
  338. boost::math::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); // and max iterations.
  339. using boost::math::tools::newton_raphson_iterate;
  340. result =
  341. newton_raphson_iterate(inverse_gaussian_quantile_functor<RealType, Policy>(dist, p), guess, min, max, get_digits, max_iter);
  342. if (max_iter >= policies::get_max_root_iterations<Policy>())
  343. {
  344. return policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:" // LCOV_EXCL_LINE
  345. " either there is no answer to quantile or the answer is infinite. Current best guess is %1%", result, Policy()); // LCOV_EXCL_LINE
  346. }
  347. return result;
  348. } // quantile
  349. template <class RealType, class Policy>
  350. BOOST_MATH_GPU_ENABLED inline RealType cdf(const complemented2_type<inverse_gaussian_distribution<RealType, Policy>, RealType>& c)
  351. {
  352. BOOST_MATH_STD_USING // for ADL of std functions.
  353. RealType scale = c.dist.scale();
  354. RealType mean = c.dist.mean();
  355. RealType x = c.param;
  356. constexpr auto function = "boost::math::cdf(const complement(inverse_gaussian_distribution<%1%>&), %1%)";
  357. RealType result = 0;
  358. if(false == detail::check_scale(function, scale, &result, Policy()))
  359. return result;
  360. if(false == detail::check_location(function, mean, &result, Policy()))
  361. return result;
  362. if (false == detail::check_x_gt0(function, mean, &result, Policy()))
  363. return result;
  364. if(false == detail::check_positive_x(function, x, &result, Policy()))
  365. return result;
  366. normal_distribution<RealType> n01;
  367. RealType n0 = sqrt(scale / x);
  368. n0 *= ((x / mean) -1);
  369. RealType cdf_1 = cdf(complement(n01, n0));
  370. RealType expfactor = exp(2 * scale / mean);
  371. RealType n3 = - sqrt(scale / x);
  372. n3 *= (x / mean) + 1;
  373. //RealType n5 = +sqrt(scale/x) * ((x /mean) + 1); // note now positive sign.
  374. RealType n6 = cdf(complement(n01, +sqrt(scale/x) * ((x /mean) + 1)));
  375. // RealType n4 = cdf(n01, n3); // =
  376. result = cdf_1 - expfactor * n6;
  377. return result;
  378. } // cdf complement
  379. template <class RealType, class Policy>
  380. BOOST_MATH_GPU_ENABLED inline RealType quantile(const complemented2_type<inverse_gaussian_distribution<RealType, Policy>, RealType>& c)
  381. {
  382. BOOST_MATH_STD_USING // for ADL of std functions
  383. RealType scale = c.dist.scale();
  384. RealType mean = c.dist.mean();
  385. constexpr auto function = "boost::math::quantile(const complement(inverse_gaussian_distribution<%1%>&), %1%)";
  386. RealType result = 0;
  387. if(false == detail::check_scale(function, scale, &result, Policy()))
  388. return result;
  389. if(false == detail::check_location(function, mean, &result, Policy()))
  390. return result;
  391. if (false == detail::check_x_gt0(function, mean, &result, Policy()))
  392. return result;
  393. RealType q = c.param;
  394. if(false == detail::check_probability(function, q, &result, Policy()))
  395. return result;
  396. RealType guess = detail::guess_ig(q, mean, scale);
  397. // Complement.
  398. using boost::math::tools::max_value;
  399. RealType min = static_cast<RealType>(0); // Minimum possible value is bottom of range of distribution.
  400. RealType max = max_value<RealType>();// Maximum possible value is top of range.
  401. // int digits = std::numeric_limits<RealType>::digits; // Maximum possible binary digits accuracy for type T.
  402. // digits used to control how accurate to try to make the result.
  403. int get_digits = policies::digits<RealType, Policy>();
  404. boost::math::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
  405. using boost::math::tools::newton_raphson_iterate;
  406. result = newton_raphson_iterate(inverse_gaussian_quantile_complement_functor<RealType, Policy>(c.dist, q), guess, min, max, get_digits, max_iter);
  407. if (max_iter >= policies::get_max_root_iterations<Policy>())
  408. {
  409. return policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:" // LCOV_EXCL_LINE
  410. " either there is no answer to quantile or the answer is infinite. Current best guess is %1%", result, Policy()); // LCOV_EXCL_LINE
  411. }
  412. return result;
  413. } // quantile
  414. template <class RealType, class Policy>
  415. BOOST_MATH_GPU_ENABLED inline RealType mean(const inverse_gaussian_distribution<RealType, Policy>& dist)
  416. { // aka mu
  417. return dist.mean();
  418. }
  419. template <class RealType, class Policy>
  420. BOOST_MATH_GPU_ENABLED inline RealType scale(const inverse_gaussian_distribution<RealType, Policy>& dist)
  421. { // aka lambda
  422. return dist.scale();
  423. }
  424. template <class RealType, class Policy>
  425. BOOST_MATH_GPU_ENABLED inline RealType shape(const inverse_gaussian_distribution<RealType, Policy>& dist)
  426. { // aka phi
  427. return dist.shape();
  428. }
  429. template <class RealType, class Policy>
  430. BOOST_MATH_GPU_ENABLED inline RealType standard_deviation(const inverse_gaussian_distribution<RealType, Policy>& dist)
  431. {
  432. BOOST_MATH_STD_USING
  433. RealType scale = dist.scale();
  434. RealType mean = dist.mean();
  435. RealType result = sqrt(mean * mean * mean / scale);
  436. return result;
  437. }
  438. template <class RealType, class Policy>
  439. BOOST_MATH_GPU_ENABLED inline RealType mode(const inverse_gaussian_distribution<RealType, Policy>& dist)
  440. {
  441. BOOST_MATH_STD_USING
  442. RealType scale = dist.scale();
  443. RealType mean = dist.mean();
  444. RealType result = mean * (sqrt(1 + (9 * mean * mean)/(4 * scale * scale))
  445. - 3 * mean / (2 * scale));
  446. return result;
  447. }
  448. template <class RealType, class Policy>
  449. BOOST_MATH_GPU_ENABLED inline RealType skewness(const inverse_gaussian_distribution<RealType, Policy>& dist)
  450. {
  451. BOOST_MATH_STD_USING
  452. RealType scale = dist.scale();
  453. RealType mean = dist.mean();
  454. RealType result = 3 * sqrt(mean/scale);
  455. return result;
  456. }
  457. template <class RealType, class Policy>
  458. BOOST_MATH_GPU_ENABLED inline RealType kurtosis(const inverse_gaussian_distribution<RealType, Policy>& dist)
  459. {
  460. RealType scale = dist.scale();
  461. RealType mean = dist.mean();
  462. RealType result = 15 * mean / scale -3;
  463. return result;
  464. }
  465. template <class RealType, class Policy>
  466. BOOST_MATH_GPU_ENABLED inline RealType kurtosis_excess(const inverse_gaussian_distribution<RealType, Policy>& dist)
  467. {
  468. RealType scale = dist.scale();
  469. RealType mean = dist.mean();
  470. RealType result = 15 * mean / scale;
  471. return result;
  472. }
  473. } // namespace math
  474. } // namespace boost
  475. // This include must be at the end, *after* the accessors
  476. // for this distribution have been defined, in order to
  477. // keep compilers that support two-phase lookup happy.
  478. #include <boost/math/distributions/detail/derived_accessors.hpp>
  479. #endif // BOOST_STATS_INVERSE_GAUSSIAN_HPP