cauchy.qbk 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. [section:cauchy_dist Cauchy-Lorentz Distribution]
  2. ``#include <boost/math/distributions/cauchy.hpp>``
  3. template <class RealType = double,
  4. class ``__Policy`` = ``__policy_class`` >
  5. class cauchy_distribution;
  6. typedef cauchy_distribution<> cauchy;
  7. template <class RealType, class ``__Policy``>
  8. class cauchy_distribution
  9. {
  10. public:
  11. typedef RealType value_type;
  12. typedef Policy policy_type;
  13. cauchy_distribution(RealType location = 0, RealType scale = 1);
  14. RealType location()const;
  15. RealType scale()const;
  16. };
  17. The [@http://en.wikipedia.org/wiki/Cauchy_distribution Cauchy-Lorentz distribution]
  18. is named after Augustin Cauchy and Hendrik Lorentz.
  19. It is a [@http://en.wikipedia.org/wiki/Probability_distribution continuous probability distribution]
  20. with [@http://en.wikipedia.org/wiki/Probability_distribution probability distribution function PDF]
  21. given by:
  22. [equation cauchy_ref1]
  23. The location parameter ['x[sub 0]] is the location of the
  24. peak of the distribution (the mode of the distribution),
  25. while the scale parameter [gamma] specifies half the width
  26. of the PDF at half the maximum height. If the location is
  27. zero, and the scale 1, then the result is a standard Cauchy
  28. distribution.
  29. The distribution is important in physics as it is the solution
  30. to the differential equation describing forced resonance,
  31. while in spectroscopy it is the description of the line shape
  32. of spectral lines.
  33. The following graph shows how the distributions moves as the
  34. location parameter changes:
  35. [graph cauchy_pdf1]
  36. While the following graph shows how the shape (scale) parameter alters
  37. the distribution:
  38. [graph cauchy_pdf2]
  39. [h4 Member Functions]
  40. cauchy_distribution(RealType location = 0, RealType scale = 1);
  41. Constructs a Cauchy distribution, with location parameter /location/
  42. and scale parameter /scale/. When these parameters take their default
  43. values (location = 0, scale = 1)
  44. then the result is a Standard Cauchy Distribution.
  45. Requires scale > 0, otherwise calls __domain_error.
  46. RealType location()const;
  47. Returns the location parameter of the distribution.
  48. RealType scale()const;
  49. Returns the scale parameter of the distribution.
  50. [h4 Non-member Accessors]
  51. All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
  52. that are generic to all distributions are supported: __usual_accessors.
  53. Note however that the Cauchy distribution does not have a mean,
  54. standard deviation, etc. See __math_undefined
  55. [/link math_toolkit.pol_ref.assert_undefined mathematically undefined function]
  56. to control whether these should fail to compile with a BOOST_STATIC_ASSERTION_FAILURE,
  57. which is the default.
  58. Alternately, the functions __mean, __sd,
  59. __variance, __skewness, __kurtosis and __kurtosis_excess will all
  60. return a __domain_error if called.
  61. The domain of the random variable is \[-[max_value], +[min_value]\].
  62. [h4 Accuracy]
  63. The Cauchy distribution is implemented in terms of the
  64. standard library `tan` and `atan` functions,
  65. and as such should have very low error rates.
  66. [h4 Implementation]
  67. [def __x0 x[sub 0 ]]
  68. In the following table __x0 is the location parameter of the distribution,
  69. [gamma] is its scale parameter,
  70. /x/ is the random variate, /p/ is the probability and /q = 1-p/.
  71. [table
  72. [[Function][Implementation Notes]]
  73. [[pdf][Using the relation: ['pdf = 1 / ([pi] * [gamma] * (1 + ((x - __x0) / [gamma])[super 2]) ]]]
  74. [[cdf and its complement][
  75. The cdf is normally given by:
  76. [expression p = 0.5 + atan(x)/[pi]]
  77. But that suffers from cancellation error as x -> -[infin].
  78. So recall that for `x < 0`:
  79. [expression atan(x) = -[pi]/2 - atan(1/x)]
  80. Substituting into the above we get:
  81. [expression p = -atan(1/x) ; x < 0]
  82. So the procedure is to calculate the cdf for -fabs(x)
  83. using the above formula. Note that to factor in the location and scale
  84. parameters you must substitute (x - __x0) / [gamma] for x in the above.
  85. This procedure yields the smaller of /p/ and /q/, so the result
  86. may need subtracting from 1 depending on whether we want the complement
  87. or not, and whether /x/ is less than __x0 or not.
  88. ]]
  89. [[quantile][The same procedure is used irrespective of whether we're starting
  90. from the probability or its complement. First the argument /p/ is
  91. reduced to the range \[-0.5, 0.5\], then the relation
  92. [expression x = __x0 [plusminus] [gamma] / tan([pi] * p)]
  93. is used to obtain the result. Whether we're adding
  94. or subtracting from __x0 is determined by whether we're
  95. starting from the complement or not.]]
  96. [[mode][The location parameter.]]
  97. ]
  98. [h4 References]
  99. * [@http://en.wikipedia.org/wiki/Cauchy_distribution Cauchy-Lorentz distribution]
  100. * [@http://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm NIST Exploratory Data Analysis]
  101. * [@http://mathworld.wolfram.com/CauchyDistribution.html Weisstein, Eric W. "Cauchy Distribution." From MathWorld--A Wolfram Web Resource.]
  102. [endsect][/section:cauchy_dist Cauchi]
  103. [/ cauchy.qbk
  104. Copyright 2006, 2007 John Maddock and Paul A. Bristow.
  105. Distributed under the Boost Software License, Version 1.0.
  106. (See accompanying file LICENSE_1_0.txt or copy at
  107. http://www.boost.org/LICENSE_1_0.txt).
  108. ]