]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/doc/html/math_toolkit/dist_ref/dists/bernoulli_dist.html
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / doc / html / math_toolkit / dist_ref / dists / bernoulli_dist.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Bernoulli 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="arcine_dist.html" title="Arcsine Distribution">
10 <link rel="next" href="beta_dist.html" title="Beta 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="arcine_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="beta_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.bernoulli_dist"></a><a class="link" href="bernoulli_dist.html" title="Bernoulli Distribution">Bernoulli
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">bernoulli</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">bernoulli_distribution</span><span class="special">;</span>
35
36 <span class="keyword">typedef</span> <span class="identifier">bernoulli_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">bernoulli</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">bernoulli_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">bernoulli_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span> <span class="comment">// Constructor.</span>
46 <span class="comment">// Accessor function.</span>
47 <span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span>
48 <span class="comment">// Probability of success (as a fraction).</span>
49 <span class="special">};</span>
50 <span class="special">}}</span> <span class="comment">// namespaces</span>
51 </pre>
52 <p>
53 The Bernoulli distribution is a discrete distribution of the outcome of
54 a single trial with only two results, 0 (failure) or 1 (success), with
55 a probability of success p.
56 </p>
57 <p>
58 The Bernoulli distribution is the simplest building block on which other
59 discrete distributions of sequences of independent Bernoulli trials can
60 be based.
61 </p>
62 <p>
63 The Bernoulli is the binomial distribution (k = 1, p) with only one trial.
64 </p>
65 <p>
66 <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
67 density function pdf</a> f(0) = 1 - p, f(1) = p. <a href="http://en.wikipedia.org/wiki/Cumulative_Distribution_Function" target="_top">Cumulative
68 distribution function</a> D(k) = if (k == 0) 1 - p else 1.
69 </p>
70 <p>
71 The following graph illustrates how the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
72 density function pdf</a> varies with the outcome of the single trial:
73 </p>
74 <p>
75 <span class="inlinemediaobject"><img src="../../../../graphs/bernoulli_pdf.svg" align="middle"></span>
76 </p>
77 <p>
78 and the <a href="http://en.wikipedia.org/wiki/Cumulative_Distribution_Function" target="_top">Cumulative
79 distribution function</a>
80 </p>
81 <p>
82 <span class="inlinemediaobject"><img src="../../../../graphs/bernoulli_cdf.svg" align="middle"></span>
83 </p>
84 <h5>
85 <a name="math_toolkit.dist_ref.dists.bernoulli_dist.h0"></a>
86 <span class="phrase"><a name="math_toolkit.dist_ref.dists.bernoulli_dist.member_functions"></a></span><a class="link" href="bernoulli_dist.html#math_toolkit.dist_ref.dists.bernoulli_dist.member_functions">Member
87 Functions</a>
88 </h5>
89 <pre class="programlisting"><span class="identifier">bernoulli_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
90 </pre>
91 <p>
92 Constructs a <a href="http://en.wikipedia.org/wiki/bernoulli_distribution" target="_top">bernoulli
93 distribution</a> with success_fraction <span class="emphasis"><em>p</em></span>.
94 </p>
95 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span>
96 </pre>
97 <p>
98 Returns the <span class="emphasis"><em>success_fraction</em></span> parameter of this distribution.
99 </p>
100 <h5>
101 <a name="math_toolkit.dist_ref.dists.bernoulli_dist.h1"></a>
102 <span class="phrase"><a name="math_toolkit.dist_ref.dists.bernoulli_dist.non_member_accessors"></a></span><a class="link" href="bernoulli_dist.html#math_toolkit.dist_ref.dists.bernoulli_dist.non_member_accessors">Non-member
103 Accessors</a>
104 </h5>
105 <p>
106 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
107 functions</a> that are generic to all distributions are supported:
108 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
109 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
110 <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>,
111 <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>,
112 <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>,
113 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
114 <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>,
115 <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>.
116 </p>
117 <p>
118 The domain of the random variable is 0 and 1, and the useful supported
119 range is only 0 or 1.
120 </p>
121 <p>
122 Outside this range, functions are undefined, or may throw domain_error
123 exception and make an error message available.
124 </p>
125 <h5>
126 <a name="math_toolkit.dist_ref.dists.bernoulli_dist.h2"></a>
127 <span class="phrase"><a name="math_toolkit.dist_ref.dists.bernoulli_dist.accuracy"></a></span><a class="link" href="bernoulli_dist.html#math_toolkit.dist_ref.dists.bernoulli_dist.accuracy">Accuracy</a>
128 </h5>
129 <p>
130 The Bernoulli distribution is implemented with simple arithmetic operators
131 and so should have errors within an epsilon or two.
132 </p>
133 <h5>
134 <a name="math_toolkit.dist_ref.dists.bernoulli_dist.h3"></a>
135 <span class="phrase"><a name="math_toolkit.dist_ref.dists.bernoulli_dist.implementation"></a></span><a class="link" href="bernoulli_dist.html#math_toolkit.dist_ref.dists.bernoulli_dist.implementation">Implementation</a>
136 </h5>
137 <p>
138 In the following table <span class="emphasis"><em>p</em></span> is the probability of success
139 and <span class="emphasis"><em>q = 1-p</em></span>. <span class="emphasis"><em>k</em></span> is the random
140 variate, either 0 or 1.
141 </p>
142 <div class="note"><table border="0" summary="Note">
143 <tr>
144 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
145 <th align="left">Note</th>
146 </tr>
147 <tr><td align="left" valign="top">
148 <p>
149 The Bernoulli distribution is implemented here as a <span class="emphasis"><em>strict
150 discrete</em></span> distribution. If a generalised version, allowing
151 k to be any real, is required then the binomial distribution with a single
152 trial should be used, for example:
153 </p>
154 <p>
155 <code class="computeroutput"><span class="identifier">binomial_distribution</span><span class="special">(</span><span class="number">1</span><span class="special">,</span>
156 <span class="number">0.25</span><span class="special">)</span></code>
157 </p>
158 </td></tr>
159 </table></div>
160 <div class="informaltable"><table class="table">
161 <colgroup>
162 <col>
163 <col>
164 </colgroup>
165 <thead><tr>
166 <th>
167 <p>
168 Function
169 </p>
170 </th>
171 <th>
172 <p>
173 Implementation Notes
174 </p>
175 </th>
176 </tr></thead>
177 <tbody>
178 <tr>
179 <td>
180 <p>
181 Supported range
182 </p>
183 </td>
184 <td>
185 <p>
186 {0, 1}
187 </p>
188 </td>
189 </tr>
190 <tr>
191 <td>
192 <p>
193 pdf
194 </p>
195 </td>
196 <td>
197 <p>
198 Using the relation: pdf = 1 - p for k = 0, else p
199 </p>
200 </td>
201 </tr>
202 <tr>
203 <td>
204 <p>
205 cdf
206 </p>
207 </td>
208 <td>
209 <p>
210 Using the relation: cdf = 1 - p for k = 0, else 1
211 </p>
212 </td>
213 </tr>
214 <tr>
215 <td>
216 <p>
217 cdf complement
218 </p>
219 </td>
220 <td>
221 <p>
222 q = 1 - p
223 </p>
224 </td>
225 </tr>
226 <tr>
227 <td>
228 <p>
229 quantile
230 </p>
231 </td>
232 <td>
233 <p>
234 if x &lt;= (1-p) 0 else 1
235 </p>
236 </td>
237 </tr>
238 <tr>
239 <td>
240 <p>
241 quantile from the complement
242 </p>
243 </td>
244 <td>
245 <p>
246 if x &lt;= (1-p) 1 else 0
247 </p>
248 </td>
249 </tr>
250 <tr>
251 <td>
252 <p>
253 mean
254 </p>
255 </td>
256 <td>
257 <p>
258 p
259 </p>
260 </td>
261 </tr>
262 <tr>
263 <td>
264 <p>
265 variance
266 </p>
267 </td>
268 <td>
269 <p>
270 p * (1 - p)
271 </p>
272 </td>
273 </tr>
274 <tr>
275 <td>
276 <p>
277 mode
278 </p>
279 </td>
280 <td>
281 <p>
282 if (p &lt; 0.5) 0 else 1
283 </p>
284 </td>
285 </tr>
286 <tr>
287 <td>
288 <p>
289 skewness
290 </p>
291 </td>
292 <td>
293 <p>
294 (1 - 2 * p) / sqrt(p * q)
295 </p>
296 </td>
297 </tr>
298 <tr>
299 <td>
300 <p>
301 kurtosis
302 </p>
303 </td>
304 <td>
305 <p>
306 6 * p * p - 6 * p +1/ p * q
307 </p>
308 </td>
309 </tr>
310 <tr>
311 <td>
312 <p>
313 kurtosis excess
314 </p>
315 </td>
316 <td>
317 <p>
318 kurtosis -3
319 </p>
320 </td>
321 </tr>
322 </tbody>
323 </table></div>
324 <h5>
325 <a name="math_toolkit.dist_ref.dists.bernoulli_dist.h4"></a>
326 <span class="phrase"><a name="math_toolkit.dist_ref.dists.bernoulli_dist.references"></a></span><a class="link" href="bernoulli_dist.html#math_toolkit.dist_ref.dists.bernoulli_dist.references">References</a>
327 </h5>
328 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
329 <li class="listitem">
330 <a href="http://en.wikipedia.org/wiki/Bernoulli_distribution" target="_top">Wikpedia
331 Bernoulli distribution</a>
332 </li>
333 <li class="listitem">
334 <a href="http://mathworld.wolfram.com/BernoulliDistribution.html" target="_top">Weisstein,
335 Eric W. "Bernoulli Distribution." From MathWorld--A Wolfram
336 Web Resource.</a>
337 </li>
338 </ul></div>
339 </div>
340 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
341 <td align="left"></td>
342 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2010, 2012-2014 Nikhar Agrawal,
343 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
344 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;de, Gautam Sewani,
345 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
346 Distributed under the Boost Software License, Version 1.0. (See accompanying
347 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>)
348 </p>
349 </div></td>
350 </tr></table>
351 <hr>
352 <div class="spirit-nav">
353 <a accesskey="p" href="arcine_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="beta_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
354 </div>
355 </body>
356 </html>