72e469da0a
[CI SKIP]
137 lines
9.9 KiB
HTML
137 lines
9.9 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Distributions are Objects</title>
|
|
<link rel="stylesheet" href="../../../math.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
|
<link rel="home" href="../../../index.html" title="Math Toolkit 2.11.0">
|
|
<link rel="up" href="../overview.html" title="Overview of Statistical Distributions">
|
|
<link rel="prev" href="headers.html" title="Headers and Namespaces">
|
|
<link rel="next" href="generic.html" title="Generic operations common to all distributions are non-member functions">
|
|
</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="headers.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.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="generic.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="math_toolkit.stat_tut.overview.objects"></a><a class="link" href="objects.html" title="Distributions are Objects">Distributions
|
|
are Objects</a>
|
|
</h4></div></div></div>
|
|
<p>
|
|
Each kind of distribution in this library is a class type - an object,
|
|
with member functions.
|
|
</p>
|
|
<div class="tip"><table border="0" summary="Tip">
|
|
<tr>
|
|
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../doc/src/images/tip.png"></td>
|
|
<th align="left">Tip</th>
|
|
</tr>
|
|
<tr><td align="left" valign="top"><p>
|
|
If you are familiar with statistics libraries using functions, and 'Distributions
|
|
as Objects' seem alien, see <a class="link" href="../weg/nag_library.html" title="Comparison with C, R, FORTRAN-style Free Functions">the
|
|
comparison to other statistics libraries.</a>
|
|
</p></td></tr>
|
|
</table></div>
|
|
<p>
|
|
<a class="link" href="../../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policies</a> provide optional fine-grained control
|
|
of the behaviour of these classes, allowing the user to customise behaviour
|
|
such as how errors are handled, or how the quantiles of discrete distributions
|
|
behave.
|
|
</p>
|
|
<p>
|
|
Making distributions class types does two things:
|
|
</p>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
It encapsulates the kind of distribution in the C++ type system; so,
|
|
for example, Students-t distributions are always a different C++ type
|
|
from Chi-Squared distributions.
|
|
</li>
|
|
<li class="listitem">
|
|
The distribution objects store any parameters associated with the distribution:
|
|
for example, the Students-t distribution has a <span class="emphasis"><em>degrees of
|
|
freedom</em></span> parameter that controls the shape of the distribution.
|
|
This <span class="emphasis"><em>degrees of freedom</em></span> parameter has to be provided
|
|
to the Students-t object when it is constructed.
|
|
</li>
|
|
</ul></div>
|
|
<p>
|
|
Although the distribution classes in this library are templates, there
|
|
are typedefs on type <span class="emphasis"><em>double</em></span> that mostly take the usual
|
|
name of the distribution (except where there is a clash with a function
|
|
of the same name: beta and gamma, in which case using the default template
|
|
arguments - <code class="computeroutput"><span class="identifier">RealType</span> <span class="special">=</span>
|
|
<span class="keyword">double</span></code> - is nearly as convenient).
|
|
Probably 95% of uses are covered by these typedefs:
|
|
</p>
|
|
<pre class="programlisting"><span class="comment">// using namespace boost::math; // Avoid potential ambiguity with names in std <random></span>
|
|
<span class="comment">// Safer to declare specific functions with using statement(s):</span>
|
|
|
|
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">beta_distribution</span><span class="special">;</span>
|
|
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">binomial_distribution</span><span class="special">;</span>
|
|
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">students_t</span><span class="special">;</span>
|
|
|
|
<span class="comment">// Construct a students_t distribution with 4 degrees of freedom:</span>
|
|
<span class="identifier">students_t</span> <span class="identifier">d1</span><span class="special">(</span><span class="number">4</span><span class="special">);</span>
|
|
|
|
<span class="comment">// Construct a double-precision beta distribution</span>
|
|
<span class="comment">// with parameters a = 10, b = 20</span>
|
|
<span class="identifier">beta_distribution</span><span class="special"><></span> <span class="identifier">d2</span><span class="special">(</span><span class="number">10</span><span class="special">,</span> <span class="number">20</span><span class="special">);</span> <span class="comment">// Note: _distribution<> suffix !</span>
|
|
</pre>
|
|
<p>
|
|
If you need to use the distributions with a type other than <code class="computeroutput"><span class="keyword">double</span></code>, then you can instantiate the template
|
|
directly: the names of the templates are the same as the <code class="computeroutput"><span class="keyword">double</span></code> typedef but with <code class="computeroutput"><span class="identifier">_distribution</span></code>
|
|
appended, for example: <a class="link" href="../../dist_ref/dists/students_t_dist.html" title="Students t Distribution">Students
|
|
t Distribution</a> or <a class="link" href="../../dist_ref/dists/binomial_dist.html" title="Binomial Distribution">Binomial
|
|
Distribution</a>:
|
|
</p>
|
|
<pre class="programlisting"><span class="comment">// Construct a students_t distribution, of float type,</span>
|
|
<span class="comment">// with 4 degrees of freedom:</span>
|
|
<span class="identifier">students_t_distribution</span><span class="special"><</span><span class="keyword">float</span><span class="special">></span> <span class="identifier">d3</span><span class="special">(</span><span class="number">4</span><span class="special">);</span>
|
|
|
|
<span class="comment">// Construct a binomial distribution, of long double type,</span>
|
|
<span class="comment">// with probability of success 0.3</span>
|
|
<span class="comment">// and 20 trials in total:</span>
|
|
<span class="identifier">binomial_distribution</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">double</span><span class="special">></span> <span class="identifier">d4</span><span class="special">(</span><span class="number">20</span><span class="special">,</span> <span class="number">0.3</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
The parameters passed to the distributions can be accessed via getter member
|
|
functions:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">d1</span><span class="special">.</span><span class="identifier">degrees_of_freedom</span><span class="special">();</span> <span class="comment">// returns 4.0</span>
|
|
</pre>
|
|
<p>
|
|
This is all well and good, but not very useful so far. What we often want
|
|
is to be able to calculate the <span class="emphasis"><em>cumulative distribution functions</em></span>
|
|
and <span class="emphasis"><em>quantiles</em></span> etc for these distributions.
|
|
</p>
|
|
</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-2019 Nikhar
|
|
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
|
|
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
|
|
Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
|
|
Daryle Walker and Xiaogang Zhang<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="headers.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.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="generic.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|