gamma.qbk 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. [section:gamma_dist Gamma (and Erlang) Distribution]
  2. ``#include <boost/math/distributions/gamma.hpp>``
  3. namespace boost{ namespace math{
  4. template <class RealType = double,
  5. class ``__Policy`` = ``__policy_class`` >
  6. class gamma_distribution
  7. {
  8. public:
  9. typedef RealType value_type;
  10. typedef Policy policy_type;
  11. gamma_distribution(RealType shape, RealType scale = 1)
  12. RealType shape()const;
  13. RealType scale()const;
  14. };
  15. }} // namespaces
  16. The gamma distribution is a continuous probability distribution.
  17. When the shape parameter is an integer then it is known as the
  18. Erlang Distribution. It is also closely related to the Poisson
  19. and Chi Squared Distributions.
  20. When the shape parameter has an integer value, the distribution is the
  21. [@http://en.wikipedia.org/wiki/Erlang_distribution Erlang distribution].
  22. Since this can be produced by ensuring that the shape parameter has an
  23. integer value > 0, the Erlang distribution is not separately implemented.
  24. [note
  25. To avoid potential confusion with the gamma functions, this
  26. distribution does not provide the typedef:
  27. ``typedef gamma_distribution<double> gamma;``
  28. Instead if you want a double precision gamma distribution you can write
  29. ``boost::math::gamma_distribution<> my_gamma(1, 1);``
  30. ]
  31. For shape parameter /k/ and scale parameter [theta] it is defined by the
  32. probability density function:
  33. [equation gamma_dist_ref1]
  34. Sometimes an alternative formulation is used: given parameters
  35. [alpha] = k and [beta] = 1 / [theta], then the
  36. distribution can be defined by the PDF:
  37. [equation gamma_dist_ref2]
  38. In this form the inverse scale parameter is called a /rate parameter/.
  39. Both forms are in common usage: this library uses the first definition
  40. throughout. Therefore to construct a Gamma Distribution from a ['rate
  41. parameter], you should pass the reciprocal of the rate as the scale parameter.
  42. The following two graphs illustrate how the PDF of the gamma distribution
  43. varies as the parameters vary:
  44. [graph gamma1_pdf]
  45. [graph gamma2_pdf]
  46. The [*Erlang Distribution] is the same as the Gamma, but with the shape parameter
  47. an integer. It is often expressed using a /rate/ rather than a /scale/ as the
  48. second parameter (remember that the rate is the reciprocal of the scale).
  49. Internally the functions used to implement the Gamma Distribution are
  50. already optimised for small-integer arguments, so in general there should
  51. be no great loss of performance from using a Gamma Distribution rather than
  52. a dedicated Erlang Distribution.
  53. [h4 Member Functions]
  54. gamma_distribution(RealType shape, RealType scale = 1);
  55. Constructs a gamma distribution with shape /shape/ and
  56. scale /scale/.
  57. Requires that the shape and scale parameters are greater than zero, otherwise calls
  58. __domain_error.
  59. RealType shape()const;
  60. Returns the /shape/ parameter of this distribution.
  61. RealType scale()const;
  62. Returns the /scale/ parameter of this distribution.
  63. [h4 Non-member Accessors]
  64. All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions] that are generic to all
  65. distributions are supported: __usual_accessors.
  66. The domain of the random variable is \[0,+[infin]\].
  67. [h4 Accuracy]
  68. The gamma distribution is implemented in terms of the
  69. incomplete gamma functions __gamma_p and __gamma_q and their
  70. inverses __gamma_p_inv and __gamma_q_inv: refer to the accuracy
  71. data for those functions for more information.
  72. [h4 Implementation]
  73. In the following table /k/ is the shape parameter of the distribution,
  74. [theta] is its scale parameter, /x/ is the random variate, /p/ is the probability
  75. and /q = 1-p/.
  76. [table
  77. [[Function][Implementation Notes]]
  78. [[pdf][Using the relation: pdf = __gamma_p_derivative(k, x / [theta]) / [theta] ]]
  79. [[cdf][Using the relation: p = __gamma_p(k, x / [theta]) ]]
  80. [[cdf complement][Using the relation: q = __gamma_q(k, x / [theta]) ]]
  81. [[quantile][Using the relation: x = [theta] * __gamma_p_inv(k, p) ]]
  82. [[quantile from the complement][Using the relation: x = [theta]* __gamma_q_inv(k, p) ]]
  83. [[mean][k[theta] ]]
  84. [[variance][k[theta][super 2] ]]
  85. [[mode][(k-1)[theta] for ['k>1] otherwise a __domain_error ]]
  86. [[skewness][2 / sqrt(k) ]]
  87. [[kurtosis][3 + 6 / k]]
  88. [[kurtosis excess][6 / k ]]
  89. ]
  90. [endsect] [/section:gamma_dist Gamma (and Erlang) Distribution]
  91. [/
  92. Copyright 2006, 2010 John Maddock and Paul A. Bristow.
  93. Distributed under the Boost Software License, Version 1.0.
  94. (See accompanying file LICENSE_1_0.txt or copy at
  95. http://www.boost.org/LICENSE_1_0.txt).
  96. ]