3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Uniform Distribution</title>
5 <link rel="stylesheet" href="../../../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../../index.html" title="Math Toolkit 2.11.0">
8 <link rel="up" href="../dists.html" title="Distributions">
9 <link rel="prev" href="triangular_dist.html" title="Triangular Distribution">
10 <link rel="next" href="weibull_dist.html" title="Weibull Distribution">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="triangular_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="weibull_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h4 class="title">
27 <a name="math_toolkit.dist_ref.dists.uniform_dist"></a><a class="link" href="uniform_dist.html" title="Uniform Distribution">Uniform Distribution</a>
28 </h4></div></div></div>
29 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">uniform</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></pre>
30 <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
31 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">RealType</span> <span class="special">=</span> <span class="keyword">double</span><span class="special">,</span>
32 <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> <span class="special">=</span> <a class="link" href="../../pol_ref/pol_ref_ref.html" title="Policy Class Reference">policies::policy<></a> <span class="special">></span>
33 <span class="keyword">class</span> <span class="identifier">uniform_distribution</span><span class="special">;</span>
35 <span class="keyword">typedef</span> <span class="identifier">uniform_distribution</span><span class="special"><></span> <span class="identifier">uniform</span><span class="special">;</span>
37 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">RealType</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
38 <span class="keyword">class</span> <span class="identifier">uniform_distribution</span>
39 <span class="special">{</span>
40 <span class="keyword">public</span><span class="special">:</span>
41 <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span>
43 <span class="identifier">uniform_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lower</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">upper</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// Constructor.</span>
44 <span class="special">:</span> <span class="identifier">m_lower</span><span class="special">(</span><span class="identifier">lower</span><span class="special">),</span> <span class="identifier">m_upper</span><span class="special">(</span><span class="identifier">upper</span><span class="special">)</span> <span class="comment">// Default is standard uniform distribution.</span>
45 <span class="comment">// Accessor functions.</span>
46 <span class="identifier">RealType</span> <span class="identifier">lower</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
47 <span class="identifier">RealType</span> <span class="identifier">upper</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
48 <span class="special">};</span> <span class="comment">// class uniform_distribution</span>
50 <span class="special">}}</span> <span class="comment">// namespaces</span>
53 The uniform distribution, also known as a rectangular distribution, is
54 a probability distribution that has constant probability.
57 The <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">continuous
58 uniform distribution</a> is a distribution with the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
61 <div class="blockquote"><blockquote class="blockquote"><p>
62 <span class="serif_italic">f(x) =1 / (upper - lower)   for lower <
64 </p></blockquote></div>
65 <div class="blockquote"><blockquote class="blockquote"><p>
66 <span class="serif_italic">f(x) =zero   for x < lower or x > upper</span>
67 </p></blockquote></div>
69 and in this implementation:
71 <div class="blockquote"><blockquote class="blockquote"><p>
72 <span class="serif_italic">1 / (upper - lower)   for x = lower or x =
74 </p></blockquote></div>
76 The choice of <span class="emphasis"><em>x = lower</em></span> or <span class="emphasis"><em>x = upper</em></span>
77 is made because statistical use of this distribution judged is most likely:
78 the method of maximum likelihood uses this definition.
81 There is also a <a href="http://en.wikipedia.org/wiki/Discrete_uniform_distribution" target="_top"><span class="bold"><strong>discrete</strong></span> uniform distribution</a>.
84 Parameters lower and upper can be any finite value.
87 The <a href="http://en.wikipedia.org/wiki/Random_variate" target="_top">random variate</a>
88 <span class="emphasis"><em>x</em></span> must also be finite, and is supported <span class="emphasis"><em>lower
89 <= x <= upper</em></span>.
92 The lower parameter is also called the <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda364.htm" target="_top">location
93 parameter</a>, <a href="http://en.wikipedia.org/wiki/Location_parameter" target="_top">that
94 is where the origin of a plot will lie</a>, and (upper - lower) is
95 also called the <a href="http://en.wikipedia.org/wiki/Scale_parameter" target="_top">scale
99 The following graph illustrates how the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
100 density function PDF</a> varies with the shape parameter:
102 <div class="blockquote"><blockquote class="blockquote"><p>
103 <span class="inlinemediaobject"><img src="../../../../graphs/uniform_pdf.svg" align="middle"></span>
105 </p></blockquote></div>
107 Likewise for the CDF:
109 <div class="blockquote"><blockquote class="blockquote"><p>
110 <span class="inlinemediaobject"><img src="../../../../graphs/uniform_cdf.svg" align="middle"></span>
112 </p></blockquote></div>
114 <a name="math_toolkit.dist_ref.dists.uniform_dist.h0"></a>
115 <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.member_functions"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.member_functions">Member
118 <pre class="programlisting"><span class="identifier">uniform_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lower</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">upper</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
121 Constructs a <a href="http://en.wikipedia.org/wiki/uniform_distribution" target="_top">uniform
122 distribution</a> with lower <span class="emphasis"><em>lower</em></span> (a) and upper
123 <span class="emphasis"><em>upper</em></span> (b).
126 Requires that the <span class="emphasis"><em>lower</em></span> and <span class="emphasis"><em>upper</em></span>
127 parameters are both finite; otherwise if infinity or NaN then calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
129 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">lower</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
132 Returns the <span class="emphasis"><em>lower</em></span> parameter of this distribution.
134 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">upper</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
137 Returns the <span class="emphasis"><em>upper</em></span> parameter of this distribution.
140 <a name="math_toolkit.dist_ref.dists.uniform_dist.h1"></a>
141 <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.non_member_accessors"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.non_member_accessors">Non-member
145 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
146 functions</a> that are generic to all distributions are supported:
147 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
148 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
149 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.hazard">Hazard Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.chf">Cumulative Hazard Function</a>,
150 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mean">mean</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.median">median</a>,
151 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mode">mode</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>,
152 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
153 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.skewness">skewness</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis">kurtosis</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>,
154 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.range">range</a> and <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.support">support</a>.
157 The domain of the random variable is any finite value, but the supported
158 range is only <span class="emphasis"><em>lower</em></span> <= x <= <span class="emphasis"><em>upper</em></span>.
161 <a name="math_toolkit.dist_ref.dists.uniform_dist.h2"></a>
162 <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.accuracy"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.accuracy">Accuracy</a>
165 The uniform distribution is implemented with simple arithmetic operators
166 and so should have errors within an epsilon or two.
169 <a name="math_toolkit.dist_ref.dists.uniform_dist.h3"></a>
170 <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.implementation"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.implementation">Implementation</a>
173 In the following table a is the <span class="emphasis"><em>lower</em></span> parameter of
174 the distribution, b is the <span class="emphasis"><em>upper</em></span> parameter, <span class="emphasis"><em>x</em></span>
175 is the random variate, <span class="emphasis"><em>p</em></span> is the probability and <span class="emphasis"><em>q
178 <div class="informaltable"><table class="table">
204 Using the relation: pdf = 0 for x < a, 1 / (b - a) for a <=
205 x <= b, 0 for x > b
217 Using the relation: cdf = 0 for x < a, (x - a) / (b - a) for
218 a <= x <= b, 1 for x > b
230 Using the relation: q = 1 - p, (b - x) / (b - a)
242 Using the relation: x = p * (b - a) + a;
249 quantile from the complement
278 (b - a) <sup>2</sup> / 12
290 any value in [a, b] but a is chosen. (Would NaN be better?)
314 -6/5 = -1.2 exactly. (kurtosis - 3)
333 <a name="math_toolkit.dist_ref.dists.uniform_dist.h4"></a>
334 <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.references"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.references">References</a>
336 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
337 <li class="listitem">
338 <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">Wikpedia
339 continuous uniform distribution</a>
341 <li class="listitem">
342 <a href="http://mathworld.wolfram.com/UniformDistribution.html" target="_top">Weisstein,
343 Weisstein, Eric W. "Uniform Distribution." From MathWorld--A
344 Wolfram Web Resource.</a>
346 <li class="listitem">
347 <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda3662.htm" target="_top">http://www.itl.nist.gov/div898/handbook/eda/section3/eda3662.htm</a>
351 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
352 <td align="left"></td>
353 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
354 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
355 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
356 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
357 Daryle Walker and Xiaogang Zhang<p>
358 Distributed under the Boost Software License, Version 1.0. (See accompanying
359 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
364 <div class="spirit-nav">
365 <a accesskey="p" href="triangular_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="weibull_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>