uniform.qbk 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. [section:uniform_dist Uniform Distribution]
  2. ``#include <boost/math/distributions/uniform.hpp>``
  3. namespace boost{ namespace math{
  4. template <class RealType = double,
  5. class ``__Policy`` = ``__policy_class`` >
  6. class uniform_distribution;
  7. typedef uniform_distribution<> uniform;
  8. template <class RealType, class ``__Policy``>
  9. class uniform_distribution
  10. {
  11. public:
  12. typedef RealType value_type;
  13. uniform_distribution(RealType lower = 0, RealType upper = 1); // Constructor.
  14. : m_lower(lower), m_upper(upper) // Default is standard uniform distribution.
  15. // Accessor functions.
  16. RealType lower()const;
  17. RealType upper()const;
  18. }; // class uniform_distribution
  19. }} // namespaces
  20. The uniform distribution, also known as a rectangular distribution,
  21. is a probability distribution that has constant probability.
  22. The [@http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29 continuous uniform distribution]
  23. is a distribution with the
  24. [@http://en.wikipedia.org/wiki/Probability_density_function probability density function]:
  25. [expression f(x) =1 / (upper - lower) [sixemspace] for lower < x < upper]
  26. [expression f(x) =zero [sixemspace] for x < lower or x > upper]
  27. and in this implementation:
  28. [expression 1 / (upper - lower) [sixemspace] for x = lower or x = upper]
  29. The choice of /x = lower/ or /x = upper/ is made because statistical use of this distribution judged is most likely:
  30. the method of maximum likelihood uses this definition.
  31. There is also a [@http://en.wikipedia.org/wiki/Discrete_uniform_distribution *discrete* uniform distribution].
  32. Parameters lower and upper can be any finite value.
  33. The [@http://en.wikipedia.org/wiki/Random_variate random variate]
  34. /x/ must also be finite, and is supported /lower <= x <= upper/.
  35. The lower parameter is also called the
  36. [@http://www.itl.nist.gov/div898/handbook/eda/section3/eda364.htm location parameter],
  37. [@http://en.wikipedia.org/wiki/Location_parameter that is where the origin of a plot will lie],
  38. and (upper - lower) is also called the [@http://en.wikipedia.org/wiki/Scale_parameter scale parameter].
  39. The following graph illustrates how the
  40. [@http://en.wikipedia.org/wiki/Probability_density_function probability density function PDF]
  41. varies with the shape parameter:
  42. [graph uniform_pdf]
  43. Likewise for the CDF:
  44. [graph uniform_cdf]
  45. [h4 Member Functions]
  46. uniform_distribution(RealType lower = 0, RealType upper = 1);
  47. Constructs a [@http://en.wikipedia.org/wiki/uniform_distribution
  48. uniform distribution] with lower /lower/ (a) and upper /upper/ (b).
  49. Requires that the /lower/ and /upper/ parameters are both finite;
  50. otherwise if infinity or NaN then calls __domain_error.
  51. RealType lower()const;
  52. Returns the /lower/ parameter of this distribution.
  53. RealType upper()const;
  54. Returns the /upper/ parameter of this distribution.
  55. [h4 Non-member Accessors]
  56. All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
  57. that are generic to all distributions are supported: __usual_accessors.
  58. The domain of the random variable is any finite value,
  59. but the supported range is only /lower/ <= x <= /upper/.
  60. [h4 Accuracy]
  61. The uniform distribution is implemented with simple arithmetic operators and so should have errors within an epsilon or two.
  62. [h4 Implementation]
  63. In the following table a is the /lower/ parameter of the distribution,
  64. b is the /upper/ parameter,
  65. /x/ is the random variate, /p/ is the probability and /q = 1-p/.
  66. [table
  67. [[Function][Implementation Notes]]
  68. [[pdf][Using the relation: pdf = 0 for x < a, 1 / (b - a) for a <= x <= b, 0 for x > b ]]
  69. [[cdf][Using the relation: cdf = 0 for x < a, (x - a) / (b - a) for a <= x <= b, 1 for x > b]]
  70. [[cdf complement][Using the relation: q = 1 - p, (b - x) / (b - a) ]]
  71. [[quantile][Using the relation: x = p * (b - a) + a; ]]
  72. [[quantile from the complement][x = -q * (b - a) + b ]]
  73. [[mean][(a + b) / 2 ]]
  74. [[variance][(b - a) [super 2] / 12 ]]
  75. [[mode][any value in \[a, b\] but a is chosen. (Would NaN be better?) ]]
  76. [[skewness][0]]
  77. [[kurtosis excess][-6/5 = -1.2 exactly. (kurtosis - 3)]]
  78. [[kurtosis][9/5]]
  79. ]
  80. [h4 References]
  81. * [@http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29 Wikpedia continuous uniform distribution]
  82. * [@http://mathworld.wolfram.com/UniformDistribution.html Weisstein, Weisstein, Eric W. "Uniform Distribution." From MathWorld--A Wolfram Web Resource.]
  83. * [@http://www.itl.nist.gov/div898/handbook/eda/section3/eda3662.htm]
  84. [endsect] [/section:uniform_dist Uniform]
  85. [/
  86. Copyright 2006 John Maddock and Paul A. Bristow.
  87. Distributed under the Boost Software License, Version 1.0.
  88. (See accompanying file LICENSE_1_0.txt or copy at
  89. http://www.boost.org/LICENSE_1_0.txt).
  90. ]