]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/doc/html/math_toolkit/dist_ref/dists/triangular_dist.html
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / doc / html / math_toolkit / dist_ref / dists / triangular_dist.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Triangular 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="students_t_dist.html" title="Students t Distribution">
10 <link rel="next" href="uniform_dist.html" title="Uniform 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="students_t_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="uniform_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.triangular_dist"></a><a class="link" href="triangular_dist.html" title="Triangular Distribution">Triangular
28 Distribution</a>
29 </h4></div></div></div>
30 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</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">triangular</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
31 <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>
32 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RealType</span> <span class="special">=</span> <span class="keyword">double</span><span class="special">,</span>
33 <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;15.&#160;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&lt;&gt;</a> <span class="special">&gt;</span>
34 <span class="keyword">class</span> <span class="identifier">triangular_distribution</span><span class="special">;</span>
35
36 <span class="keyword">typedef</span> <span class="identifier">triangular_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">triangular</span><span class="special">;</span>
37
38 <span class="keyword">template</span> <span class="special">&lt;</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&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
39 <span class="keyword">class</span> <span class="identifier">triangular_distribution</span>
40 <span class="special">{</span>
41 <span class="keyword">public</span><span class="special">:</span>
42 <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span>
43 <span class="keyword">typedef</span> <span class="identifier">Policy</span> <span class="identifier">policy_type</span><span class="special">;</span>
44
45 <span class="identifier">triangular_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lower</span> <span class="special">=</span> <span class="special">-</span><span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">mode</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>
46 <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_mode</span><span class="special">(</span><span class="identifier">mode</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 -1, 0, +1 symmetric triangular distribution.</span>
47 <span class="comment">// Accessor functions.</span>
48 <span class="identifier">RealType</span> <span class="identifier">lower</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
49 <span class="identifier">RealType</span> <span class="identifier">mode</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
50 <span class="identifier">RealType</span> <span class="identifier">upper</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
51 <span class="special">};</span> <span class="comment">// class triangular_distribution</span>
52
53 <span class="special">}}</span> <span class="comment">// namespaces</span>
54 </pre>
55 <p>
56 The <a href="http://en.wikipedia.org/wiki/Triangular_distribution" target="_top">triangular
57 distribution</a> is a <a href="http://en.wikipedia.org/wiki/Continuous_distribution" target="_top">continuous</a>
58 <a href="http://en.wikipedia.org/wiki/Probability_distribution" target="_top">probability
59 distribution</a> with a lower limit a, <a href="http://en.wikipedia.org/wiki/Mode_%28statistics%29" target="_top">mode
60 c</a>, and upper limit b.
61 </p>
62 <p>
63 The triangular distribution is often used where the distribution is only
64 vaguely known, but, like the <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">uniform
65 distribution</a>, upper and limits are 'known', but a 'best guess',
66 the mode or center point, is also added. It has been recommended as a
67 <a href="http://www.worldscibooks.com/mathematics/etextbook/5720/5720_chap1.pdf" target="_top">proxy
68 for the beta distribution.</a> The distribution is used in business
69 decision making and project planning.
70 </p>
71 <p>
72 The <a href="http://en.wikipedia.org/wiki/Triangular_distribution" target="_top">triangular
73 distribution</a> is a distribution with the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
74 density function</a>:
75 </p>
76 <p>
77 &#8192;&#8192; f(x) =
78 </p>
79 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
80 <li class="listitem">
81 2(x-a)/(b-a) (c-a) for a &lt;= x &lt;= c
82 </li>
83 <li class="listitem">
84 2(b-x)/(b-a)(b-c) for c &lt; x &lt;= b
85 </li>
86 </ul></div>
87 <p>
88 Parameter <span class="emphasis"><em>a</em></span> (lower) can be any finite value. Parameter
89 <span class="emphasis"><em>b</em></span> (upper) can be any finite value &gt; a (lower).
90 Parameter <span class="emphasis"><em>c</em></span> (mode) a &lt;= c &lt;= b. This is the
91 most probable value.
92 </p>
93 <p>
94 The <a href="http://en.wikipedia.org/wiki/Random_variate" target="_top">random variate</a>
95 x must also be finite, and is supported lower &lt;= x &lt;= upper.
96 </p>
97 <p>
98 The triangular distribution may be appropriate when an assumption of a
99 normal distribution is unjustified because uncertainty is caused by rounding
100 and quantization from analog to digital conversion. Upper and lower limits
101 are known, and the most probable value lies midway.
102 </p>
103 <p>
104 The distribution simplifies when the 'best guess' is either the lower or
105 upper limit - a 90 degree angle triangle. The 001 triangular distribution
106 which expresses an estimate that the lowest value is the most likely; for
107 example, you believe that the next-day quoted delivery date is most likely
108 (knowing that a quicker delivery is impossible - the postman only comes
109 once a day), and that longer delays are decreasingly likely, and delivery
110 is assumed to never take more than your upper limit.
111 </p>
112 <p>
113 The following graph illustrates how the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
114 density function PDF</a> varies with the various parameters:
115 </p>
116 <p>
117 <span class="inlinemediaobject"><img src="../../../../graphs/triangular_pdf.svg" align="middle"></span>
118 </p>
119 <p>
120 and cumulative distribution function
121 </p>
122 <p>
123 <span class="inlinemediaobject"><img src="../../../../graphs/triangular_cdf.svg" align="middle"></span>
124 </p>
125 <h5>
126 <a name="math_toolkit.dist_ref.dists.triangular_dist.h0"></a>
127 <span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.member_functions"></a></span><a class="link" href="triangular_dist.html#math_toolkit.dist_ref.dists.triangular_dist.member_functions">Member
128 Functions</a>
129 </h5>
130 <pre class="programlisting"><span class="identifier">triangular_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">mode</span> <span class="special">=</span> <span class="number">0</span> <span class="identifier">RealType</span> <span class="identifier">upper</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
131 </pre>
132 <p>
133 Constructs a <a href="http://en.wikipedia.org/wiki/triangular_distribution" target="_top">triangular
134 distribution</a> with lower <span class="emphasis"><em>lower</em></span> (a) and upper
135 <span class="emphasis"><em>upper</em></span> (b).
136 </p>
137 <p>
138 Requires that the <span class="emphasis"><em>lower</em></span>, <span class="emphasis"><em>mode</em></span>
139 and <span class="emphasis"><em>upper</em></span> parameters are all finite, otherwise calls
140 <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
141 </p>
142 <div class="warning"><table border="0" summary="Warning">
143 <tr>
144 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
145 <th align="left">Warning</th>
146 </tr>
147 <tr><td align="left" valign="top">
148 <p>
149 These constructors are slightly different from the analogs provided by
150 <a href="http://mathworld.wolfram.com" target="_top">Wolfram MathWorld</a>
151 <a href="http://reference.wolfram.com/language/ref/TriangularDistribution.html" target="_top">Triangular
152 distribution</a>, where
153 </p>
154 <p>
155 <code class="literal">TriangularDistribution[{min, max}]</code> represents a <span class="bold"><strong>symmetric</strong></span> triangular statistical distribution
156 giving values between min and max.<br> <code class="literal">TriangularDistribution[]</code>
157 represents a <span class="bold"><strong>symmetric</strong></span> triangular statistical
158 distribution giving values between 0 and 1.<br> <code class="literal">TriangularDistribution[{min,
159 max}, c]</code> represents a triangular distribution with mode at
160 c (usually <span class="bold"><strong>asymmetric</strong></span>).<br>
161 </p>
162 <p>
163 So, for example, to compute a variance using <a href="http://www.wolframalpha.com/" target="_top">Wolfram
164 Alpha</a>, use <code class="literal">N[variance[TriangularDistribution{1, +2}],
165 50]</code>
166 </p>
167 </td></tr>
168 </table></div>
169 <p>
170 The parameters of a distribution can be obtained using these member functions:
171 </p>
172 <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>
173 </pre>
174 <p>
175 Returns the <span class="emphasis"><em>lower</em></span> parameter of this distribution (default
176 -1).
177 </p>
178 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">mode</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
179 </pre>
180 <p>
181 Returns the <span class="emphasis"><em>mode</em></span> parameter of this distribution (default
182 0).
183 </p>
184 <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>
185 </pre>
186 <p>
187 Returns the <span class="emphasis"><em>upper</em></span> parameter of this distribution (default+1).
188 </p>
189 <h5>
190 <a name="math_toolkit.dist_ref.dists.triangular_dist.h1"></a>
191 <span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.non_member_accessors"></a></span><a class="link" href="triangular_dist.html#math_toolkit.dist_ref.dists.triangular_dist.non_member_accessors">Non-member
192 Accessors</a>
193 </h5>
194 <p>
195 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
196 functions</a> that are generic to all distributions are supported:
197 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
198 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
199 <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>,
200 <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>,
201 <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>,
202 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
203 <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>,
204 <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>.
205 </p>
206 <p>
207 The domain of the random variable is \lowerto \upper, and the supported
208 range is lower &lt;= x &lt;= upper.
209 </p>
210 <h5>
211 <a name="math_toolkit.dist_ref.dists.triangular_dist.h2"></a>
212 <span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.accuracy"></a></span><a class="link" href="triangular_dist.html#math_toolkit.dist_ref.dists.triangular_dist.accuracy">Accuracy</a>
213 </h5>
214 <p>
215 The triangular distribution is implemented with simple arithmetic operators
216 and so should have errors within an epsilon or two, except quantiles with
217 arguments nearing the extremes of zero and unity.
218 </p>
219 <h5>
220 <a name="math_toolkit.dist_ref.dists.triangular_dist.h3"></a>
221 <span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.implementation"></a></span><a class="link" href="triangular_dist.html#math_toolkit.dist_ref.dists.triangular_dist.implementation">Implementation</a>
222 </h5>
223 <p>
224 In the following table, a is the <span class="emphasis"><em>lower</em></span> parameter of
225 the distribution, c is the <span class="emphasis"><em>mode</em></span> parameter, b is the
226 <span class="emphasis"><em>upper</em></span> parameter, <span class="emphasis"><em>x</em></span> is the random
227 variate, <span class="emphasis"><em>p</em></span> is the probability and <span class="emphasis"><em>q = 1-p</em></span>.
228 </p>
229 <div class="informaltable"><table class="table">
230 <colgroup>
231 <col>
232 <col>
233 </colgroup>
234 <thead><tr>
235 <th>
236 <p>
237 Function
238 </p>
239 </th>
240 <th>
241 <p>
242 Implementation Notes
243 </p>
244 </th>
245 </tr></thead>
246 <tbody>
247 <tr>
248 <td>
249 <p>
250 pdf
251 </p>
252 </td>
253 <td>
254 <p>
255 Using the relation: pdf = 0 for x &lt; mode, 2(x-a)/(b-a)(c-a)
256 else 2*(b-x)/((b-a)(b-c))
257 </p>
258 </td>
259 </tr>
260 <tr>
261 <td>
262 <p>
263 cdf
264 </p>
265 </td>
266 <td>
267 <p>
268 Using the relation: cdf = 0 for x &lt; mode (x-a)<sup>2</sup>/((b-a)(c-a))
269 else 1 - (b-x)<sup>2</sup>/((b-a)(b-c))
270 </p>
271 </td>
272 </tr>
273 <tr>
274 <td>
275 <p>
276 cdf complement
277 </p>
278 </td>
279 <td>
280 <p>
281 Using the relation: q = 1 - p
282 </p>
283 </td>
284 </tr>
285 <tr>
286 <td>
287 <p>
288 quantile
289 </p>
290 </td>
291 <td>
292 <p>
293 let p0 = (c-a)/(b-a) the point of inflection on the cdf, then
294 given probability p and q = 1-p:
295 </p>
296 <p>
297 x = sqrt((b-a)(c-a)p) + a ; for p &lt; p0
298 </p>
299 <p>
300 x = c ; for p == p0
301 </p>
302 <p>
303 x = b - sqrt((b-a)(b-c)q) ; for p &gt; p0
304 </p>
305 <p>
306 (See <a href="../../../../../../../boost/math/distributions/triangular.hpp" target="_top">/boost/math/distributions/triangular.hpp</a>
307 for details.)
308 </p>
309 </td>
310 </tr>
311 <tr>
312 <td>
313 <p>
314 quantile from the complement
315 </p>
316 </td>
317 <td>
318 <p>
319 As quantile (See <a href="../../../../../../../boost/math/distributions/triangular.hpp" target="_top">/boost/math/distributions/triangular.hpp</a>
320 for details.)
321 </p>
322 </td>
323 </tr>
324 <tr>
325 <td>
326 <p>
327 mean
328 </p>
329 </td>
330 <td>
331 <p>
332 (a + b + 3) / 3
333 </p>
334 </td>
335 </tr>
336 <tr>
337 <td>
338 <p>
339 variance
340 </p>
341 </td>
342 <td>
343 <p>
344 (a<sup>2</sup>+b<sup>2</sup>+c<sup>2</sup> - ab - ac - bc)/18
345 </p>
346 </td>
347 </tr>
348 <tr>
349 <td>
350 <p>
351 mode
352 </p>
353 </td>
354 <td>
355 <p>
356 c
357 </p>
358 </td>
359 </tr>
360 <tr>
361 <td>
362 <p>
363 skewness
364 </p>
365 </td>
366 <td>
367 <p>
368 (See <a href="../../../../../../../boost/math/distributions/triangular.hpp" target="_top">/boost/math/distributions/triangular.hpp</a>
369 for details).
370 </p>
371 </td>
372 </tr>
373 <tr>
374 <td>
375 <p>
376 kurtosis
377 </p>
378 </td>
379 <td>
380 <p>
381 12/5
382 </p>
383 </td>
384 </tr>
385 <tr>
386 <td>
387 <p>
388 kurtosis excess
389 </p>
390 </td>
391 <td>
392 <p>
393 -3/5
394 </p>
395 </td>
396 </tr>
397 </tbody>
398 </table></div>
399 <p>
400 Some 'known good' test values were obtained using <a href="http://www.wolframalpha.com/" target="_top">Wolfram
401 Alpha</a>.
402 </p>
403 <h5>
404 <a name="math_toolkit.dist_ref.dists.triangular_dist.h4"></a>
405 <span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.references"></a></span><a class="link" href="triangular_dist.html#math_toolkit.dist_ref.dists.triangular_dist.references">References</a>
406 </h5>
407 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
408 <li class="listitem">
409 <a href="http://en.wikipedia.org/wiki/Triangular_distribution" target="_top">Wikpedia
410 triangular distribution</a>
411 </li>
412 <li class="listitem">
413 <a href="http://mathworld.wolfram.com/TriangularDistribution.html" target="_top">Weisstein,
414 Eric W. "Triangular Distribution." From MathWorld--A Wolfram
415 Web Resource.</a>
416 </li>
417 <li class="listitem">
418 Evans, M.; Hastings, N.; and Peacock, B. "Triangular Distribution."
419 Ch. 40 in Statistical Distributions, 3rd ed. New York: Wiley, pp. 187-188,
420 2000, ISBN - 0471371246.
421 </li>
422 <li class="listitem">
423 <a href="http://www.measurement.sk/2002/S1/Wimmer2.pdf" target="_top">Gejza Wimmer,
424 Viktor Witkovsky and Tomas Duby, Measurement Science Review, Volume
425 2, Section 1, 2002, Proper Rounding Of The Measurement Results Under
426 The Assumption Of Triangular Distribution.</a>
427 </li>
428 </ul></div>
429 </div>
430 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
431 <td align="left"></td>
432 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2010, 2012-2014 Nikhar Agrawal,
433 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
434 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;de, Gautam Sewani,
435 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
436 Distributed under the Boost Software License, Version 1.0. (See accompanying
437 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>)
438 </p>
439 </div></td>
440 </tr></table>
441 <hr>
442 <div class="spirit-nav">
443 <a accesskey="p" href="students_t_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="uniform_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
444 </div>
445 </body>
446 </html>