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.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="students_t_dist.html" title="Students t Distribution">
10 <link rel="next" href="uniform_dist.html" title="Uniform 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="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>
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
29 </h4></div></div></div>
30 <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">triangular</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></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"><</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 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>
34 <span class="keyword">class</span> <span class="identifier">triangular_distribution</span><span class="special">;</span>
36 <span class="keyword">typedef</span> <span class="identifier">triangular_distribution</span><span class="special"><></span> <span class="identifier">triangular</span><span class="special">;</span>
38 <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>
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>
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>
53 <span class="special">}}</span> <span class="comment">// namespaces</span>
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.
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.
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
76 <div class="blockquote"><blockquote class="blockquote"><p>
77 <span class="serif_italic">f(x) = 2(x-a)/(b-a) (c-a)   for a <= x <=
79 </p></blockquote></div>
80 <div class="blockquote"><blockquote class="blockquote"><p>
81 <span class="serif_italic">f(x) = 2(b-x)/(b-a) (b-c)   for c < x <=
83 </p></blockquote></div>
85 Parameter <span class="emphasis"><em>a</em></span> (lower) can be any finite value. Parameter
86 <span class="emphasis"><em>b</em></span> (upper) can be any finite value > a (lower).
87 Parameter <span class="emphasis"><em>c</em></span> (mode) a <= c <= b. This is the
91 The <a href="http://en.wikipedia.org/wiki/Random_variate" target="_top">random variate</a>
92 x must also be finite, and is supported lower <= x <= upper.
95 The triangular distribution may be appropriate when an assumption of a
96 normal distribution is unjustified because uncertainty is caused by rounding
97 and quantization from analog to digital conversion. Upper and lower limits
98 are known, and the most probable value lies midway.
101 The distribution simplifies when the 'best guess' is either the lower or
102 upper limit - a 90 degree angle triangle. The 001 triangular distribution
103 which expresses an estimate that the lowest value is the most likely; for
104 example, you believe that the next-day quoted delivery date is most likely
105 (knowing that a quicker delivery is impossible - the postman only comes
106 once a day), and that longer delays are decreasingly likely, and delivery
107 is assumed to never take more than your upper limit.
110 The following graph illustrates how the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
111 density function PDF</a> varies with the various parameters:
113 <div class="blockquote"><blockquote class="blockquote"><p>
114 <span class="inlinemediaobject"><img src="../../../../graphs/triangular_pdf.svg" align="middle"></span>
116 </p></blockquote></div>
118 and cumulative distribution function
120 <div class="blockquote"><blockquote class="blockquote"><p>
121 <span class="inlinemediaobject"><img src="../../../../graphs/triangular_cdf.svg" align="middle"></span>
123 </p></blockquote></div>
125 <a name="math_toolkit.dist_ref.dists.triangular_dist.h0"></a>
126 <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
129 <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>
132 Constructs a <a href="http://en.wikipedia.org/wiki/triangular_distribution" target="_top">triangular
133 distribution</a> with lower <span class="emphasis"><em>lower</em></span> (a) and upper
134 <span class="emphasis"><em>upper</em></span> (b).
137 Requires that the <span class="emphasis"><em>lower</em></span>, <span class="emphasis"><em>mode</em></span>
138 and <span class="emphasis"><em>upper</em></span> parameters are all finite, otherwise calls
139 <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
141 <div class="warning"><table border="0" summary="Warning">
143 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
144 <th align="left">Warning</th>
146 <tr><td align="left" valign="top">
148 These constructors are slightly different from the analogs provided by
149 <a href="http://mathworld.wolfram.com" target="_top">Wolfram MathWorld</a>
150 <a href="http://reference.wolfram.com/language/ref/TriangularDistribution.html" target="_top">Triangular
151 distribution</a>, where
154 <code class="literal">TriangularDistribution[{min, max}]</code> represents a <span class="bold"><strong>symmetric</strong></span> triangular statistical distribution
155 giving values between min and max.<br> <code class="literal">TriangularDistribution[]</code>
156 represents a <span class="bold"><strong>symmetric</strong></span> triangular statistical
157 distribution giving values between 0 and 1.<br> <code class="literal">TriangularDistribution[{min,
158 max}, c]</code> represents a triangular distribution with mode at
159 c (usually <span class="bold"><strong>asymmetric</strong></span>).<br>
162 So, for example, to compute a variance using <a href="http://www.wolframalpha.com/" target="_top">Wolfram
163 Alpha</a>, use <code class="literal">N[variance[TriangularDistribution{1, +2}],
169 The parameters of a distribution can be obtained using these member functions:
171 <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>
174 Returns the <span class="emphasis"><em>lower</em></span> parameter of this distribution (default
177 <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>
180 Returns the <span class="emphasis"><em>mode</em></span> parameter of this distribution (default
183 <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>
186 Returns the <span class="emphasis"><em>upper</em></span> parameter of this distribution (default+1).
189 <a name="math_toolkit.dist_ref.dists.triangular_dist.h1"></a>
190 <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
194 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
195 functions</a> that are generic to all distributions are supported:
196 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
197 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
198 <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>,
199 <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>,
200 <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>,
201 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
202 <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>,
203 <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>.
206 The domain of the random variable is \lowerto \upper, and the supported
207 range is lower <= x <= upper.
210 <a name="math_toolkit.dist_ref.dists.triangular_dist.h2"></a>
211 <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>
214 The triangular distribution is implemented with simple arithmetic operators
215 and so should have errors within an epsilon or two, except quantiles with
216 arguments nearing the extremes of zero and unity.
219 <a name="math_toolkit.dist_ref.dists.triangular_dist.h3"></a>
220 <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>
223 In the following table, a is the <span class="emphasis"><em>lower</em></span> parameter of
224 the distribution, c is the <span class="emphasis"><em>mode</em></span> parameter, b is the
225 <span class="emphasis"><em>upper</em></span> parameter, <span class="emphasis"><em>x</em></span> is the random
226 variate, <span class="emphasis"><em>p</em></span> is the probability and <span class="emphasis"><em>q = 1-p</em></span>.
228 <div class="informaltable"><table class="table">
254 Using the relation: pdf = 0 for x < mode, 2(x-a)/(b-a)(c-a)
255 else 2*(b-x)/((b-a)(b-c))
267 Using the relation: cdf = 0 for x < mode (x-a)<sup>2</sup>/((b-a)(c-a))
268 else 1 - (b-x)<sup>2</sup>/((b-a)(b-c))
280 Using the relation: q = 1 - p
292 let p0 = (c-a)/(b-a) the point of inflection on the cdf, then
293 given probability p and q = 1-p:
296 x = sqrt((b-a)(c-a)p) + a ; for p < p0
302 x = b - sqrt((b-a)(b-c)q) ; for p > p0
305 (See <a href="../../../../../../../boost/math/distributions/triangular.hpp" target="_top">/boost/math/distributions/triangular.hpp</a>
313 quantile from the complement
318 As quantile (See <a href="../../../../../../../boost/math/distributions/triangular.hpp" target="_top">/boost/math/distributions/triangular.hpp</a>
343 (a<sup>2</sup>+b<sup>2</sup>+c<sup>2</sup> - ab - ac - bc)/18
367 (See <a href="../../../../../../../boost/math/distributions/triangular.hpp" target="_top">/boost/math/distributions/triangular.hpp</a>
399 Some 'known good' test values were obtained using <a href="http://www.wolframalpha.com/" target="_top">Wolfram
403 <a name="math_toolkit.dist_ref.dists.triangular_dist.h4"></a>
404 <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 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
407 <li class="listitem">
408 <a href="http://en.wikipedia.org/wiki/Triangular_distribution" target="_top">Wikpedia
409 triangular distribution</a>
411 <li class="listitem">
412 <a href="http://mathworld.wolfram.com/TriangularDistribution.html" target="_top">Weisstein,
413 Eric W. "Triangular Distribution." From MathWorld--A Wolfram
416 <li class="listitem">
417 Evans, M.; Hastings, N.; and Peacock, B. "Triangular Distribution."
418 Ch. 40 in Statistical Distributions, 3rd ed. New York: Wiley, pp. 187-188,
419 2000, ISBN - 0471371246.
421 <li class="listitem">
422 <a href="http://www.measurement.sk/2002/S1/Wimmer2.pdf" target="_top">Gejza Wimmer,
423 Viktor Witkovsky and Tomas Duby, Measurement Science Review, Volume
424 2, Section 1, 2002, Proper Rounding Of The Measurement Results Under
425 The Assumption Of Triangular Distribution.</a>
429 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
430 <td align="left"></td>
431 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
432 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
433 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
434 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
435 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>)
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>