• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Normal (Gaussian) 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.12.0">
8<link rel="up" href="../dists.html" title="Distributions">
9<link rel="prev" href="nc_t_dist.html" title="Noncentral T Distribution">
10<link rel="next" href="pareto.html" title="Pareto 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="nc_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="pareto.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.normal_dist"></a><a class="link" href="normal_dist.html" title="Normal (Gaussian) Distribution">Normal (Gaussian)
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">normal</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
33<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>
34          <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 21. 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>
35<span class="keyword">class</span> <span class="identifier">normal_distribution</span><span class="special">;</span>
36
37<span class="keyword">typedef</span> <span class="identifier">normal_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">normal</span><span class="special">;</span>
38
39<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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
40<span class="keyword">class</span> <span class="identifier">normal_distribution</span>
41<span class="special">{</span>
42<span class="keyword">public</span><span class="special">:</span>
43   <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span>
44   <span class="keyword">typedef</span> <span class="identifier">Policy</span>   <span class="identifier">policy_type</span><span class="special">;</span>
45   <span class="comment">// Construct:</span>
46   <span class="identifier">normal_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">mean</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">sd</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
47   <span class="comment">// Accessors:</span>
48   <span class="identifier">RealType</span> <span class="identifier">mean</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// location.</span>
49   <span class="identifier">RealType</span> <span class="identifier">standard_deviation</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// scale.</span>
50   <span class="comment">// Synonyms, provided to allow generic use of find_location and find_scale.</span>
51   <span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
52   <span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
53<span class="special">};</span>
54
55<span class="special">}}</span> <span class="comment">// namespaces</span>
56</pre>
57<p>
58          The normal distribution is probably the most well known statistical distribution:
59          it is also known as the Gaussian Distribution. A normal distribution with
60          mean zero and standard deviation one is known as the <span class="emphasis"><em>Standard
61          Normal Distribution</em></span>.
62        </p>
63<p>
64          Given mean μ and standard deviation σ it has the PDF:
65        </p>
66<div class="blockquote"><blockquote class="blockquote"><p>
67            <span class="inlinemediaobject"><img src="../../../../equations/normal_ref1.svg"></span>
68
69          </p></blockquote></div>
70<p>
71          The variation the PDF with its parameters is illustrated in the following
72          graph:
73        </p>
74<div class="blockquote"><blockquote class="blockquote"><p>
75            <span class="inlinemediaobject"><img src="../../../../graphs/normal_pdf.svg" align="middle"></span>
76
77          </p></blockquote></div>
78<p>
79          The cumulative distribution function is given by
80        </p>
81<div class="blockquote"><blockquote class="blockquote"><p>
82            <span class="inlinemediaobject"><img src="../../../../equations/normal_cdf.svg"></span>
83
84          </p></blockquote></div>
85<p>
86          and illustrated by this graph
87        </p>
88<div class="blockquote"><blockquote class="blockquote"><p>
89            <span class="inlinemediaobject"><img src="../../../../graphs/normal_cdf.svg" align="middle"></span>
90
91          </p></blockquote></div>
92<h5>
93<a name="math_toolkit.dist_ref.dists.normal_dist.h0"></a>
94          <span class="phrase"><a name="math_toolkit.dist_ref.dists.normal_dist.member_functions"></a></span><a class="link" href="normal_dist.html#math_toolkit.dist_ref.dists.normal_dist.member_functions">Member
95          Functions</a>
96        </h5>
97<pre class="programlisting"><span class="identifier">normal_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">mean</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">sd</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
98</pre>
99<p>
100          Constructs a normal distribution with mean <span class="emphasis"><em>mean</em></span> and
101          standard deviation <span class="emphasis"><em>sd</em></span>.
102        </p>
103<p>
104          Requires <span class="emphasis"><em>sd</em></span> &gt; 0, otherwise <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
105          is called.
106        </p>
107<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">mean</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
108<span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
109</pre>
110<p>
111          both return the <span class="emphasis"><em>mean</em></span> of this distribution.
112        </p>
113<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">standard_deviation</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
114<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
115</pre>
116<p>
117          both return the <span class="emphasis"><em>standard deviation</em></span> of this distribution.
118          (Redundant location and scale function are provided to match other similar
119          distributions, allowing the functions find_location and find_scale to be
120          used generically).
121        </p>
122<h5>
123<a name="math_toolkit.dist_ref.dists.normal_dist.h1"></a>
124          <span class="phrase"><a name="math_toolkit.dist_ref.dists.normal_dist.non_member_accessors"></a></span><a class="link" href="normal_dist.html#math_toolkit.dist_ref.dists.normal_dist.non_member_accessors">Non-member
125          Accessors</a>
126        </h5>
127<p>
128          All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
129          functions</a> that are generic to all distributions are supported:
130          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
131          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
132          <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>,
133          <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>,
134          <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>,
135          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
136          <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>,
137          <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>.
138        </p>
139<p>
140          The domain of the random variable is [-[max_value], +[min_value]]. However,
141          the pdf of +∞ and -∞ = 0 is also supported, and cdf at -∞ = 0, cdf at +∞ = 1, and
142          complement cdf -∞ = 1 and +∞ = 0, if RealType permits.
143        </p>
144<h5>
145<a name="math_toolkit.dist_ref.dists.normal_dist.h2"></a>
146          <span class="phrase"><a name="math_toolkit.dist_ref.dists.normal_dist.accuracy"></a></span><a class="link" href="normal_dist.html#math_toolkit.dist_ref.dists.normal_dist.accuracy">Accuracy</a>
147        </h5>
148<p>
149          The normal distribution is implemented in terms of the <a class="link" href="../../sf_erf/error_function.html" title="Error Function erf and complement erfc">error
150          function</a>, and as such should have very low error rates.
151        </p>
152<h5>
153<a name="math_toolkit.dist_ref.dists.normal_dist.h3"></a>
154          <span class="phrase"><a name="math_toolkit.dist_ref.dists.normal_dist.implementation"></a></span><a class="link" href="normal_dist.html#math_toolkit.dist_ref.dists.normal_dist.implementation">Implementation</a>
155        </h5>
156<p>
157          In the following table <span class="emphasis"><em>m</em></span> is the mean of the distribution,
158          and <span class="emphasis"><em>s</em></span> is its standard deviation.
159        </p>
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                    pdf
182                  </p>
183                </td>
184<td>
185                  <p>
186                    Using the relation: pdf = e<sup>-(x-m)<sup>2</sup>/(2s<sup>2</sup>)</sup> / (s * sqrt(2*pi))
187                  </p>
188                </td>
189</tr>
190<tr>
191<td>
192                  <p>
193                    cdf
194                  </p>
195                </td>
196<td>
197                  <p>
198                    Using the relation: p = 0.5 * <a class="link" href="../../sf_erf/error_function.html" title="Error Function erf and complement erfc">erfc</a>(-(x-m)/(s*sqrt(2)))
199                  </p>
200                </td>
201</tr>
202<tr>
203<td>
204                  <p>
205                    cdf complement
206                  </p>
207                </td>
208<td>
209                  <p>
210                    Using the relation: q = 0.5 * <a class="link" href="../../sf_erf/error_function.html" title="Error Function erf and complement erfc">erfc</a>((x-m)/(s*sqrt(2)))
211                  </p>
212                </td>
213</tr>
214<tr>
215<td>
216                  <p>
217                    quantile
218                  </p>
219                </td>
220<td>
221                  <p>
222                    Using the relation: x = m - s * sqrt(2) * <a class="link" href="../../sf_erf/error_inv.html" title="Error Function Inverses">erfc_inv</a>(2*p)
223                  </p>
224                </td>
225</tr>
226<tr>
227<td>
228                  <p>
229                    quantile from the complement
230                  </p>
231                </td>
232<td>
233                  <p>
234                    Using the relation: x = m + s * sqrt(2) * <a class="link" href="../../sf_erf/error_inv.html" title="Error Function Inverses">erfc_inv</a>(2*p)
235                  </p>
236                </td>
237</tr>
238<tr>
239<td>
240                  <p>
241                    mean and standard deviation
242                  </p>
243                </td>
244<td>
245                  <p>
246                    The same as <code class="computeroutput"><span class="identifier">dist</span><span class="special">.</span><span class="identifier">mean</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">dist</span><span class="special">.</span><span class="identifier">standard_deviation</span><span class="special">()</span></code>
247                  </p>
248                </td>
249</tr>
250<tr>
251<td>
252                  <p>
253                    mode
254                  </p>
255                </td>
256<td>
257                  <p>
258                    The same as the mean.
259                  </p>
260                </td>
261</tr>
262<tr>
263<td>
264                  <p>
265                    median
266                  </p>
267                </td>
268<td>
269                  <p>
270                    The same as the mean.
271                  </p>
272                </td>
273</tr>
274<tr>
275<td>
276                  <p>
277                    skewness
278                  </p>
279                </td>
280<td>
281                  <p>
282                    0
283                  </p>
284                </td>
285</tr>
286<tr>
287<td>
288                  <p>
289                    kurtosis
290                  </p>
291                </td>
292<td>
293                  <p>
294                    3
295                  </p>
296                </td>
297</tr>
298<tr>
299<td>
300                  <p>
301                    kurtosis excess
302                  </p>
303                </td>
304<td>
305                  <p>
306                    0
307                  </p>
308                </td>
309</tr>
310</tbody>
311</table></div>
312</div>
313<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
314<td align="left"></td>
315<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
316      Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
317      Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
318      Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
319      Daryle Walker and Xiaogang Zhang<p>
320        Distributed under the Boost Software License, Version 1.0. (See accompanying
321        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>)
322      </p>
323</div></td>
324</tr></table>
325<hr>
326<div class="spirit-nav">
327<a accesskey="p" href="nc_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="pareto.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
328</div>
329</body>
330</html>
331