]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | <head> | |
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.77.1"> | |
7 | <link rel="home" href="../../../index.html" title="Math Toolkit 2.5.1"> | |
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"> | |
11 | </head> | |
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> | |
20 | </tr></table> | |
21 | <hr> | |
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> | |
24 | </div> | |
25 | <div class="section"> | |
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 15. 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> | |
34 | ||
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> | |
36 | ||
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 15. 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> | |
42 | ||
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> | |
49 | ||
50 | <span class="special">}}</span> <span class="comment">// namespaces</span> | |
51 | </pre> | |
52 | <p> | |
53 | The uniform distribution, also known as a rectangular distribution, is | |
54 | a probability distribution that has constant probability. | |
55 | </p> | |
56 | <p> | |
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 | |
59 | density function</a>: | |
60 | </p> | |
61 | <p> | |
62 | f(x) = | |
63 | </p> | |
64 | <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> | |
65 | <li class="listitem"> | |
66 | 1 / (upper - lower) for lower < x < upper | |
67 | </li> | |
68 | <li class="listitem"> | |
69 | zero for x < lower or x > upper | |
70 | </li> | |
71 | </ul></div> | |
72 | <p> | |
73 | and in this implementation: | |
74 | </p> | |
75 | <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> | |
76 | 1 / (upper - lower) for x = lower or x = upper | |
77 | </li></ul></div> | |
78 | <p> | |
79 | The choice of x = lower or x = upper is made because statistical use of | |
80 | this distribution judged is most likely: the method of maximum likelihood | |
81 | uses this definition. | |
82 | </p> | |
83 | <p> | |
84 | 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>. | |
85 | </p> | |
86 | <p> | |
87 | Parameters lower and upper can be any finite value. | |
88 | </p> | |
89 | <p> | |
90 | The <a href="http://en.wikipedia.org/wiki/Random_variate" target="_top">random variate</a> | |
91 | x must also be finite, and is supported lower <= x <= upper. | |
92 | </p> | |
93 | <p> | |
94 | The lower parameter is also called the <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda364.htm" target="_top">location | |
95 | parameter</a>, <a href="http://en.wikipedia.org/wiki/Location_parameter" target="_top">that | |
96 | is where the origin of a plot will lie</a>, and (upper - lower) is | |
97 | also called the <a href="http://en.wikipedia.org/wiki/Scale_parameter" target="_top">scale | |
98 | parameter</a>. | |
99 | </p> | |
100 | <p> | |
101 | The following graph illustrates how the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability | |
102 | density function PDF</a> varies with the shape parameter: | |
103 | </p> | |
104 | <p> | |
105 | <span class="inlinemediaobject"><img src="../../../../graphs/uniform_pdf.svg" align="middle"></span> | |
106 | </p> | |
107 | <p> | |
108 | Likewise for the CDF: | |
109 | </p> | |
110 | <p> | |
111 | <span class="inlinemediaobject"><img src="../../../../graphs/uniform_cdf.svg" align="middle"></span> | |
112 | </p> | |
113 | <h5> | |
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 | |
116 | Functions</a> | |
117 | </h5> | |
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> | |
119 | </pre> | |
120 | <p> | |
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). | |
124 | </p> | |
125 | <p> | |
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>. | |
128 | </p> | |
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> | |
130 | </pre> | |
131 | <p> | |
132 | Returns the <span class="emphasis"><em>lower</em></span> parameter of this distribution. | |
133 | </p> | |
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> | |
135 | </pre> | |
136 | <p> | |
137 | Returns the <span class="emphasis"><em>upper</em></span> parameter of this distribution. | |
138 | </p> | |
139 | <h5> | |
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 | |
142 | Accessors</a> | |
143 | </h5> | |
144 | <p> | |
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>. | |
155 | </p> | |
156 | <p> | |
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>. | |
159 | </p> | |
160 | <h5> | |
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> | |
163 | </h5> | |
164 | <p> | |
165 | The uniform distribution is implemented with simple arithmetic operators | |
166 | and so should have errors within an epsilon or two. | |
167 | </p> | |
168 | <h5> | |
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> | |
171 | </h5> | |
172 | <p> | |
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 | |
176 | = 1-p</em></span>. | |
177 | </p> | |
178 | <div class="informaltable"><table class="table"> | |
179 | <colgroup> | |
180 | <col> | |
181 | <col> | |
182 | </colgroup> | |
183 | <thead><tr> | |
184 | <th> | |
185 | <p> | |
186 | Function | |
187 | </p> | |
188 | </th> | |
189 | <th> | |
190 | <p> | |
191 | Implementation Notes | |
192 | </p> | |
193 | </th> | |
194 | </tr></thead> | |
195 | <tbody> | |
196 | <tr> | |
197 | <td> | |
198 | <p> | |
199 | ||
200 | </p> | |
201 | </td> | |
202 | <td> | |
203 | <p> | |
204 | Using the relation: pdf = 0 for x < a, 1 / (b - a) for a <= | |
205 | x <= b, 0 for x > b | |
206 | </p> | |
207 | </td> | |
208 | </tr> | |
209 | <tr> | |
210 | <td> | |
211 | <p> | |
212 | cdf | |
213 | </p> | |
214 | </td> | |
215 | <td> | |
216 | <p> | |
217 | Using the relation: cdf = 0 for x < a, (x - a) / (b - a) for | |
218 | a <= x <= b, 1 for x > b | |
219 | </p> | |
220 | </td> | |
221 | </tr> | |
222 | <tr> | |
223 | <td> | |
224 | <p> | |
225 | cdf complement | |
226 | </p> | |
227 | </td> | |
228 | <td> | |
229 | <p> | |
230 | Using the relation: q = 1 - p, (b - x) / (b - a) | |
231 | </p> | |
232 | </td> | |
233 | </tr> | |
234 | <tr> | |
235 | <td> | |
236 | <p> | |
237 | quantile | |
238 | </p> | |
239 | </td> | |
240 | <td> | |
241 | <p> | |
242 | Using the relation: x = p * (b - a) + a; | |
243 | </p> | |
244 | </td> | |
245 | </tr> | |
246 | <tr> | |
247 | <td> | |
248 | <p> | |
249 | quantile from the complement | |
250 | </p> | |
251 | </td> | |
252 | <td> | |
253 | <p> | |
254 | x = -q * (b - a) + b | |
255 | </p> | |
256 | </td> | |
257 | </tr> | |
258 | <tr> | |
259 | <td> | |
260 | <p> | |
261 | mean | |
262 | </p> | |
263 | </td> | |
264 | <td> | |
265 | <p> | |
266 | (a + b) / 2 | |
267 | </p> | |
268 | </td> | |
269 | </tr> | |
270 | <tr> | |
271 | <td> | |
272 | <p> | |
273 | variance | |
274 | </p> | |
275 | </td> | |
276 | <td> | |
277 | <p> | |
278 | (b - a) <sup>2</sup> / 12 | |
279 | </p> | |
280 | </td> | |
281 | </tr> | |
282 | <tr> | |
283 | <td> | |
284 | <p> | |
285 | mode | |
286 | </p> | |
287 | </td> | |
288 | <td> | |
289 | <p> | |
290 | any value in [a, b] but a is chosen. (Would NaN be better?) | |
291 | </p> | |
292 | </td> | |
293 | </tr> | |
294 | <tr> | |
295 | <td> | |
296 | <p> | |
297 | skewness | |
298 | </p> | |
299 | </td> | |
300 | <td> | |
301 | <p> | |
302 | 0 | |
303 | </p> | |
304 | </td> | |
305 | </tr> | |
306 | <tr> | |
307 | <td> | |
308 | <p> | |
309 | kurtosis excess | |
310 | </p> | |
311 | </td> | |
312 | <td> | |
313 | <p> | |
314 | -6/5 = -1.2 exactly. (kurtosis - 3) | |
315 | </p> | |
316 | </td> | |
317 | </tr> | |
318 | <tr> | |
319 | <td> | |
320 | <p> | |
321 | kurtosis | |
322 | </p> | |
323 | </td> | |
324 | <td> | |
325 | <p> | |
326 | 9/5 | |
327 | </p> | |
328 | </td> | |
329 | </tr> | |
330 | </tbody> | |
331 | </table></div> | |
332 | <h5> | |
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> | |
335 | </h5> | |
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> | |
340 | </li> | |
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> | |
345 | </li> | |
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> | |
348 | </li> | |
349 | </ul></div> | |
350 | </div> | |
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-2010, 2012-2014 Nikhar Agrawal, | |
354 | Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert | |
355 | Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan Råde, Gautam Sewani, | |
356 | Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p> | |
357 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
358 | 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>) | |
359 | </p> | |
360 | </div></td> | |
361 | </tr></table> | |
362 | <hr> | |
363 | <div class="spirit-nav"> | |
364 | <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> | |
365 | </div> | |
366 | </body> | |
367 | </html> |