Imported Upstream version 1.51.0
[platform/upstream/boost.git] / libs / math / doc / sf_and_dist / distributions / triangular.qbk
1 [section:triangular_dist Triangular Distribution]
2
3
4 ``#include <boost/math/distributions/triangular.hpp>``
5
6    namespace boost{ namespace math{
7     template <class RealType = double, 
8               class ``__Policy``   = ``__policy_class`` >
9     class triangular_distribution;
10       
11     typedef triangular_distribution<> triangular;
12
13     template <class RealType, class ``__Policy``>
14     class triangular_distribution
15     {
16     public:
17        typedef RealType value_type;
18        typedef Policy   policy_type;
19
20        triangular_distribution(RealType lower = -1, RealType mode = 0) RealType upper = 1); // Constructor.
21           : m_lower(lower), m_mode(mode), m_upper(upper) // Default is -1, 0, +1 triangular distribution.
22        // Accessor functions.
23        RealType lower()const;
24        RealType mode()const;
25        RealType upper()const;
26     }; // class triangular_distribution
27    
28    }} // namespaces
29    
30 The [@http://en.wikipedia.org/wiki/Triangular_distribution triangular distribution]
31 is a [@http://en.wikipedia.org/wiki/Continuous_distribution continuous]
32 [@http://en.wikipedia.org/wiki/Probability_distribution probability distribution]
33 with a lower limit a,
34 [@http://en.wikipedia.org/wiki/Mode_%28statistics%29 mode c],
35 and upper limit b.
36
37 The triangular distribution is often used where the distribution is only vaguely known,
38 but, like the [@http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29 uniform distribution],
39 upper and limits are 'known', but a 'best guess', the mode or center point, is also added.
40 It has been recommended as a
41 [@http://www.worldscibooks.com/mathematics/etextbook/5720/5720_chap1.pdf proxy for the beta distribution.]
42 The distribution is used in business decision making and project planning.
43
44 The [@http://en.wikipedia.org/wiki/Triangular_distribution triangular distribution]
45 is a distribution with the 
46 [@http://en.wikipedia.org/wiki/Probability_density_function probability density function]:
47
48 f(x) =
49
50 * 2(x-a)/(b-a) (c-a) for a <= x <= c
51
52 * 2(b-x)/(b-a)(b-c) for c < x <= b
53         
54 Parameter a (lower) can be any finite value.
55 Parameter b (upper) can be any finite value > a (lower).
56 Parameter c (mode) a <= c <= b.  This is the most probable value.
57
58 The [@http://en.wikipedia.org/wiki/Random_variate random variate] x must also be finite, and is supported lower <= x <= upper.
59
60 The triangular distribution may be appropriate when an assumption of a normal distribution
61 is unjustified because uncertainty is caused by rounding and quantization from analog to digital conversion.
62 Upper and lower limits are known, and the most probable value lies midway.
63
64 The distribution simplifies when the 'best guess' is either the lower or upper limit - a 90 degree angle triangle.
65 The default chosen is the 001 triangular distribution which expresses an estimate that the lowest value is the most likely;
66 for example, you believe that the next-day quoted delivery date is most likely
67 (knowing that a quicker delivery is impossible - the postman only comes once a day),
68 and that longer delays are decreasingly likely,
69 and delivery is assumed to never take more than your upper limit.
70
71 The following graph illustrates how the
72 [@http://en.wikipedia.org/wiki/Probability_density_function probability density function PDF]
73 varies with the various parameters:
74
75 [graph triangular_pdf]
76
77 and cumulative distribution function
78
79 [graph triangular_cdf]
80
81 [h4 Member Functions]
82
83    triangular_distribution(RealType lower = 0, RealType mode = 0 RealType upper = 1);
84    
85 Constructs a [@http://en.wikipedia.org/wiki/triangular_distribution triangular distribution]
86 with lower  /lower/ (a) and upper /upper/ (b).
87
88 Requires that the /lower/, /mode/ and /upper/ parameters are all finite, 
89 otherwise calls __domain_error.
90
91    RealType lower()const;
92    
93 Returns the /lower/ parameter of this distribution (default -1).
94    
95    RealType mode()const;
96    
97 Returns the /mode/ parameter of this distribution (default 0).
98
99    RealType upper()const;
100       
101 Returns the /upper/ parameter of this distribution (default+1).
102
103 [h4 Non-member Accessors]
104
105 All the [link math_toolkit.dist.dist_ref.nmp usual non-member accessor functions] that are generic to all
106 distributions are supported: __usual_accessors.
107
108 The domain of the random variable is \lower\ to \upper\,
109 and the supported range is lower <= x <= upper.
110
111 [h4 Accuracy]
112
113 The triangular distribution is implemented with simple arithmetic operators and so should have errors within an epsilon or two,
114 except quantiles with arguments nearing the extremes of zero and unity. 
115
116 [h4 Implementation]
117
118 In the following table, a is the /lower/ parameter of the distribution, 
119 c is the /mode/ parameter,
120 b is the /upper/ parameter,
121 /x/ is the random variate, /p/ is the probability and /q = 1-p/.
122
123 [table
124 [[Function][Implementation Notes]]
125 [[pdf][Using the relation: pdf = 0 for x < mode, 2(x-a)\/(b-a)(c-a) else 2*(b-x)\/((b-a)(b-c))]]
126 [[cdf][Using the relation: cdf = 0 for x < mode (x-a)[super 2]\/((b-a)(c-a)) else 1 - (b-x)[super 2]\/((b-a)(b-c))]]
127 [[cdf complement][Using the relation: q = 1 - p ]]
128 [[quantile][let p0 = (c-a)\/(b-a) the point of inflection on the cdf,
129 then given probability p and q = 1-p:
130
131 x = sqrt((b-a)(c-a)p) + a ; for p < p0
132
133 x = c                     ; for p == p0
134
135 x = b - sqrt((b-a)(b-c)q) ; for p > p0
136
137 (See [@../../../../../boost/math/distributions/triangular.hpp /boost/math/distributions/triangular.hpp] for details.)]]
138 [[quantile from the complement][As quantile (See [@../../../../../boost/math/distributions/triangular.hpp /boost/math/distributions/triangular.hpp] for details.)]]
139 [[mean][(a + b + 3) \/ 3 ]]
140 [[variance][(a[super 2]+b[super 2]+c[super 2] - ab - ac - bc)\/18]]
141 [[mode][c]]
142 [[skewness][(See [@../../../../../boost/math/distributions/triangular.hpp /boost/math/distributions/triangular.hpp] for details). ]]
143 [[kurtosis][12\/5]]
144 [[kurtosis excess][-3\/5]]
145 ]
146
147 Some 'known good' test values were obtained from
148 [@http://espse.ed.psu.edu/edpsych/faculty/rhale/hale/507Mat/statlets/free/pdist.htm Statlet: Calculate and plot probability distributions]
149
150 [h4 References]
151
152 * [@http://en.wikipedia.org/wiki/Triangular_distribution Wikpedia triangular distribution]
153 * [@http://mathworld.wolfram.com/TriangularDistribution.html Weisstein, Eric W. "Triangular Distribution." From MathWorld--A Wolfram Web Resource.]
154 * 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]
155 * [@http://www.brighton-webs.co.uk/distributions/triangular.asp Brighton Webs Ltd. BW D-Calc 1.0 Distribution Calculator]
156 * [@http://www.worldscibooks.com/mathematics/etextbook/5720/5720_chap1.pdf The Triangular Distribution including its history.]
157 * [@http://www.measurement.sk/2002/S1/Wimmer2.pdf Gejza Wimmer, Viktor Witkovsky and Tomas Duby,
158 Measurement Science Review, Volume 2, Section 1, 2002, Proper Rounding Of The Measurement Results Under The Assumption Of Triangular Distribution.]
159
160 [endsect][/section:triangular_dist triangular]
161
162 [/ 
163   Copyright 2006 John Maddock and Paul A. Bristow.
164   Distributed under the Boost Software License, Version 1.0.
165   (See accompanying file LICENSE_1_0.txt or copy at
166   http://www.boost.org/LICENSE_1_0.txt).
167 ]
168