<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>Triangular Distribution</title> <link rel="stylesheet" href="../../../../../../../../../doc/src/boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.74.0"> <link rel="home" href="../../../../index.html" title="Math Toolkit"> <link rel="up" href="../dists.html" title="Distributions"> <link rel="prev" href="students_t_dist.html" title="Students t Distribution"> <link rel="next" href="weibull.html" title="Weibull Distribution"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table cellpadding="2" width="100%"><tr> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../../boost.png"></td> <td align="center"><a href="../../../../../../../../../index.html">Home</a></td> <td align="center"><a href="../../../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> <td align="center"><a href="../../../../../../../../../more/index.htm">More</a></td> </tr></table> <hr> <div class="spirit-nav"> <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="weibull.html"><img src="../../../../../../../../../doc/src/images/next.png" alt="Next"></a> </div> <div class="section" lang="en"> <div class="titlepage"><div><div><h5 class="title"> <a name="math_toolkit.dist.dist_ref.dists.triangular_dist"></a><a class="link" href="triangular_dist.html" title="Triangular Distribution"> Triangular Distribution</a> </h5></div></div></div> <p> </p> <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> <p> </p> <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> <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> <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Policies">Policy</a> <span class="special">=</span> <a class="link" href="../../../policy/pol_ref/pol_ref_ref.html" title="Policy Class Reference">policies::policy<></a> <span class="special">></span> <span class="keyword">class</span> <span class="identifier">triangular_distribution</span><span class="special">;</span> <span class="keyword">typedef</span> <span class="identifier">triangular_distribution</span><span class="special"><></span> <span class="identifier">triangular</span><span class="special">;</span> <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="Policies">Policy</a><span class="special">></span> <span class="keyword">class</span> <span class="identifier">triangular_distribution</span> <span class="special">{</span> <span class="keyword">public</span><span class="special">:</span> <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span> <span class="keyword">typedef</span> <span class="identifier">Policy</span> <span class="identifier">policy_type</span><span class="special">;</span> <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> <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 triangular distribution. </span> <span class="comment">// Accessor functions. </span> <span class="identifier">RealType</span> <span class="identifier">lower</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="identifier">RealType</span> <span class="identifier">mode</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="identifier">RealType</span> <span class="identifier">upper</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="special">};</span> <span class="comment">// class triangular_distribution </span> <span class="special">}}</span> <span class="comment">// namespaces </span></pre> <p> The <a href="http://en.wikipedia.org/wiki/Triangular_distribution" target="_top">triangular distribution</a> is a <a href="http://en.wikipedia.org/wiki/Continuous_distribution" target="_top">continuous</a> <a href="http://en.wikipedia.org/wiki/Probability_distribution" target="_top">probability distribution</a> with a lower limit a, <a href="http://en.wikipedia.org/wiki/Mode_%28statistics%29" target="_top">mode c</a>, and upper limit b. </p> <p> The triangular distribution is often used where the distribution is only vaguely known, but, like the <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">uniform distribution</a>, upper and limits are 'known', but a 'best guess', the mode or center point, is also added. It has been recommended as a <a href="http://www.worldscibooks.com/mathematics/etextbook/5720/5720_chap1.pdf" target="_top">proxy for the beta distribution.</a> The distribution is used in business decision making and project planning. </p> <p> The <a href="http://en.wikipedia.org/wiki/Triangular_distribution" target="_top">triangular distribution</a> is a distribution with the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability density function</a>: </p> <p> f(x) = </p> <div class="itemizedlist"><ul type="disc"> <li> 2(x-a)/(b-a) (c-a) for a <= x <= c </li> <li> 2(b-x)/(b-a)(b-c) for c < x <= b </li> </ul></div> <p> Parameter a (lower) can be any finite value. Parameter b (upper) can be any finite value > a (lower). Parameter c (mode) a <= c <= b. This is the most probable value. </p> <p> The <a href="http://en.wikipedia.org/wiki/Random_variate" target="_top">random variate</a> x must also be finite, and is supported lower <= x <= upper. </p> <p> The triangular distribution may be appropriate when an assumption of a normal distribution is unjustified because uncertainty is caused by rounding and quantization from analog to digital conversion. Upper and lower limits are known, and the most probable value lies midway. </p> <p> The distribution simplifies when the 'best guess' is either the lower or upper limit - a 90 degree angle triangle. The default chosen is the 001 triangular distribution which expresses an estimate that the lowest value is the most likely; for example, you believe that the next-day quoted delivery date is most likely (knowing that a quicker delivery is impossible - the postman only comes once a day), and that longer delays are decreasingly likely, and delivery is assumed to never take more than your upper limit. </p> <p> The following graph illustrates how the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability density function PDF</a> varies with the various parameters: </p> <p> <span class="inlinemediaobject"><img src="../../../../../graphs/triangular_pdf.png" align="middle"></span> </p> <p> and cumulative distribution function </p> <p> <span class="inlinemediaobject"><img src="../../../../../graphs/triangular_cdf.png" align="middle"></span> </p> <a name="math_toolkit.dist.dist_ref.dists.triangular_dist.member_functions"></a><h5> <a name="id1064476"></a> <a class="link" href="triangular_dist.html#math_toolkit.dist.dist_ref.dists.triangular_dist.member_functions">Member Functions</a> </h5> <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> </pre> <p> Constructs a <a href="http://en.wikipedia.org/wiki/triangular_distribution" target="_top">triangular distribution</a> with lower <span class="emphasis"><em>lower</em></span> (a) and upper <span class="emphasis"><em>upper</em></span> (b). </p> <p> Requires that the <span class="emphasis"><em>lower</em></span>, <span class="emphasis"><em>mode</em></span> and <span class="emphasis"><em>upper</em></span> parameters are all finite, otherwise calls <a class="link" href="../../../main_overview/error_handling.html#domain_error">domain_error</a>. </p> <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> </pre> <p> Returns the <span class="emphasis"><em>lower</em></span> parameter of this distribution (default -1). </p> <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> </pre> <p> Returns the <span class="emphasis"><em>mode</em></span> parameter of this distribution (default 0). </p> <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> </pre> <p> Returns the <span class="emphasis"><em>upper</em></span> parameter of this distribution (default+1). </p> <a name="math_toolkit.dist.dist_ref.dists.triangular_dist.non_member_accessors"></a><h5> <a name="id1064694"></a> <a class="link" href="triangular_dist.html#math_toolkit.dist.dist_ref.dists.triangular_dist.non_member_accessors">Non-member Accessors</a> </h5> <p> All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor functions</a> that are generic to all distributions are supported: <a class="link" href="../nmp.html#math.dist.cdf">Cumulative Distribution Function</a>, <a class="link" href="../nmp.html#math.dist.pdf">Probability Density Function</a>, <a class="link" href="../nmp.html#math.dist.quantile">Quantile</a>, <a class="link" href="../nmp.html#math.dist.hazard">Hazard Function</a>, <a class="link" href="../nmp.html#math.dist.chf">Cumulative Hazard Function</a>, <a class="link" href="../nmp.html#math.dist.mean">mean</a>, <a class="link" href="../nmp.html#math.dist.median">median</a>, <a class="link" href="../nmp.html#math.dist.mode">mode</a>, <a class="link" href="../nmp.html#math.dist.variance">variance</a>, <a class="link" href="../nmp.html#math.dist.sd">standard deviation</a>, <a class="link" href="../nmp.html#math.dist.skewness">skewness</a>, <a class="link" href="../nmp.html#math.dist.kurtosis">kurtosis</a>, <a class="link" href="../nmp.html#math.dist.kurtosis_excess">kurtosis_excess</a>, <a class="link" href="../nmp.html#math.dist.range">range</a> and <a class="link" href="../nmp.html#math.dist.support">support</a>. </p> <p> The domain of the random variable is \lowerto \upper, and the supported range is lower <= x <= upper. </p> <a name="math_toolkit.dist.dist_ref.dists.triangular_dist.accuracy"></a><h5> <a name="id1064794"></a> <a class="link" href="triangular_dist.html#math_toolkit.dist.dist_ref.dists.triangular_dist.accuracy">Accuracy</a> </h5> <p> The triangular distribution is implemented with simple arithmetic operators and so should have errors within an epsilon or two, except quantiles with arguments nearing the extremes of zero and unity. </p> <a name="math_toolkit.dist.dist_ref.dists.triangular_dist.implementation"></a><h5> <a name="id1064815"></a> <a class="link" href="triangular_dist.html#math_toolkit.dist.dist_ref.dists.triangular_dist.implementation">Implementation</a> </h5> <p> In the following table, a is the <span class="emphasis"><em>lower</em></span> parameter of the distribution, c is the <span class="emphasis"><em>mode</em></span> parameter, b is the <span class="emphasis"><em>upper</em></span> parameter, <span class="emphasis"><em>x</em></span> is the random variate, <span class="emphasis"><em>p</em></span> is the probability and <span class="emphasis"><em>q = 1-p</em></span>. </p> <div class="informaltable"><table class="table"> <colgroup> <col> <col> </colgroup> <thead><tr> <th> <p> Function </p> </th> <th> <p> Implementation Notes </p> </th> </tr></thead> <tbody> <tr> <td> <p> pdf </p> </td> <td> <p> Using the relation: pdf = 0 for x < mode, 2(x-a)/(b-a)(c-a) else 2*(b-x)/((b-a)(b-c)) </p> </td> </tr> <tr> <td> <p> cdf </p> </td> <td> <p> Using the relation: cdf = 0 for x < mode (x-a)<sup>2</sup>/((b-a)(c-a)) else 1 - (b-x)<sup>2</sup>/((b-a)(b-c)) </p> </td> </tr> <tr> <td> <p> cdf complement </p> </td> <td> <p> Using the relation: q = 1 - p </p> </td> </tr> <tr> <td> <p> quantile </p> </td> <td> <p> let p0 = (c-a)/(b-a) the point of inflection on the cdf, then given probability p and q = 1-p: </p> <p> x = sqrt((b-a)(c-a)p) + a ; for p < p0 </p> <p> x = c ; for p == p0 </p> <p> x = b - sqrt((b-a)(b-c)q) ; for p > p0 </p> <p> (See <a href="../../../../../../../../../boost/math/distributions/triangular.hpp" target="_top">/boost/math/distributions/triangular.hpp</a> for details.) </p> </td> </tr> <tr> <td> <p> quantile from the complement </p> </td> <td> <p> As quantile (See <a href="../../../../../../../../../boost/math/distributions/triangular.hpp" target="_top">/boost/math/distributions/triangular.hpp</a> for details.) </p> </td> </tr> <tr> <td> <p> mean </p> </td> <td> <p> (a + b + 3) / 3 </p> </td> </tr> <tr> <td> <p> variance </p> </td> <td> <p> (a<sup>2</sup>+b<sup>2</sup>+c<sup>2</sup> - ab - ac - bc)/18 </p> </td> </tr> <tr> <td> <p> mode </p> </td> <td> <p> c </p> </td> </tr> <tr> <td> <p> skewness </p> </td> <td> <p> (See <a href="../../../../../../../../../boost/math/distributions/triangular.hpp" target="_top">/boost/math/distributions/triangular.hpp</a> for details). </p> </td> </tr> <tr> <td> <p> kurtosis </p> </td> <td> <p> 12/5 </p> </td> </tr> <tr> <td> <p> kurtosis excess </p> </td> <td> <p> -3/5 </p> </td> </tr> </tbody> </table></div> <p> Some 'known good' test values were obtained from <a href="http://espse.ed.psu.edu/edpsych/faculty/rhale/hale/507Mat/statlets/free/pdist.htm" target="_top">Statlet: Calculate and plot probability distributions</a> </p> <a name="math_toolkit.dist.dist_ref.dists.triangular_dist.references"></a><h5> <a name="id1065156"></a> <a class="link" href="triangular_dist.html#math_toolkit.dist.dist_ref.dists.triangular_dist.references">References</a> </h5> <div class="itemizedlist"><ul type="disc"> <li> <a href="http://en.wikipedia.org/wiki/Triangular_distribution" target="_top">Wikpedia triangular distribution</a> </li> <li> <a href="http://mathworld.wolfram.com/TriangularDistribution.html" target="_top">Weisstein, Eric W. "Triangular Distribution." From MathWorld--A Wolfram Web Resource.</a> </li> <li> Evans, M.; Hastings, N.; and Peacock, B. "Triangular Distribution." Ch. 40 in Statistical Distributions, 3rd ed. New York: Wiley, pp. 187-188, 2000, ISBN - 0471371246] </li> <li> <a href="http://www.brighton-webs.co.uk/distributions/triangular.asp" target="_top">Brighton Webs Ltd. BW D-Calc 1.0 Distribution Calculator</a> </li> <li> <a href="http://www.worldscibooks.com/mathematics/etextbook/5720/5720_chap1.pdf" target="_top">The Triangular Distribution including its history.</a> </li> <li> <a href="http://www.measurement.sk/2002/S1/Wimmer2.pdf" target="_top">Gejza Wimmer, Viktor Witkovsky and Tomas Duby, Measurement Science Review, Volume 2, Section 1, 2002, Proper Rounding Of The Measurement Results Under The Assumption Of Triangular Distribution.</a> </li> </ul></div> </div> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <td align="left"></td> <td align="right"><div class="copyright-footer">Copyright © 2006 , 2007, 2008, 2009 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan Råde, Gautam Sewani and Thijs van den Berg<p> Distributed under the Boost Software License, Version 1.0. (See accompanying 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>) </p> </div></td> </tr></table> <hr> <div class="spirit-nav"> <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="weibull.html"><img src="../../../../../../../../../doc/src/images/next.png" alt="Next"></a> </div> </body> </html>