[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,643 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Arcsine Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="../dists.html" title="Distributions">
<link rel="next" href="bernoulli_dist.html" title="Bernoulli 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="../dists.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="bernoulli_dist.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.dist_ref.dists.arcine_dist"></a><a class="link" href="arcine_dist.html" title="Arcsine Distribution">Arcsine Distribution</a>
</h4></div></div></div>
<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">arcsine</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">arcsine_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">arcsine_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">arcsine</span><span class="special">;</span> <span class="comment">// double precision standard arcsine distribution [0,1].</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">arcsine_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="comment">// Constructor from two range parameters, x_min and x_max:</span>
<span class="identifier">arcsine_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">);</span>
<span class="comment">// Range Parameter accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The class type <code class="computeroutput"><span class="identifier">arcsine_distribution</span></code>
represents an <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">arcsine</a>
<a href="http://en.wikipedia.org/wiki/Probability_distribution" target="_top">probability
distribution function</a>. The arcsine distribution is named because
its CDF uses the inverse sin<sup>-1</sup> or arcsine.
</p>
<p>
This is implemented as a generalized version with support from <span class="emphasis"><em>x_min</em></span>
to <span class="emphasis"><em>x_max</em></span> providing the 'standard arcsine distribution'
as default with <span class="emphasis"><em>x_min = 0</em></span> and <span class="emphasis"><em>x_max = 1</em></span>.
(A few make other choices for 'standard').
</p>
<p>
The arcsine distribution is generalized to include any bounded support
<span class="emphasis"><em>a &lt;= x &lt;= b</em></span> by <a href="http://reference.wolfram.com/language/ref/ArcSinDistribution.html" target="_top">Wolfram</a>
and <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">Wikipedia</a>,
but also using <span class="emphasis"><em>location</em></span> and <span class="emphasis"><em>scale</em></span>
parameters by <a href="http://www.math.uah.edu/stat/index.html" target="_top">Virtual
Laboratories in Probability and Statistics</a> <a href="http://www.math.uah.edu/stat/special/Arcsine.html" target="_top">Arcsine
distribution</a>. The end-point version is simpler and more obvious,
so we implement that. If desired, <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">this</a>
outlines how the <a class="link" href="beta_dist.html" title="Beta Distribution">Beta
Distribution</a> can be used to add a shape factor.
</p>
<p>
The <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
density function PDF</a> for the <a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">arcsine
distribution</a> defined on the interval [<span class="emphasis"><em>x_min, x_max</em></span>]
is given by:
</p>
<p>
&#8199; &#8199; f(x; x_min, x_max) = 1 /(&#960;&#8901;&#8730;((x - x_min)&#8901;(x_max - x_min))
</p>
<p>
For example, <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a>
arcsine distribution, from input of
</p>
<pre class="programlisting"><span class="identifier">N</span><span class="special">[</span><span class="identifier">PDF</span><span class="special">[</span><span class="identifier">arcsinedistribution</span><span class="special">[</span><span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">],</span> <span class="number">0.5</span><span class="special">],</span> <span class="number">50</span><span class="special">]</span>
</pre>
<p>
computes the PDF value
</p>
<pre class="programlisting"><span class="number">0.63661977236758134307553505349005744813783858296183</span>
</pre>
<p>
The Probability Density Functions (PDF) of generalized arcsine distributions
are symmetric U-shaped curves, centered on <span class="emphasis"><em>(x_max - x_min)/2</em></span>,
highest (infinite) near the two extrema, and quite flat over the central
region.
</p>
<p>
If random variate <span class="emphasis"><em>x</em></span> is <span class="emphasis"><em>x_min</em></span>
or <span class="emphasis"><em>x_max</em></span>, then the PDF is infinity. If random variate
<span class="emphasis"><em>x</em></span> is <span class="emphasis"><em>x_min</em></span> then the CDF is zero.
If random variate <span class="emphasis"><em>x</em></span> is <span class="emphasis"><em>x_max</em></span>
then the CDF is unity.
</p>
<p>
The 'Standard' (0, 1) arcsine distribution is shown in blue and some generalized
examples with other <span class="emphasis"><em>x</em></span> ranges.
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/arcsine_pdf.svg" align="middle"></span>
</p>
<p>
The Cumulative Distribution Function CDF is defined as
</p>
<p>
&#8199; &#8199; F(x) = 2&#8901;arcsin(&#8730;((x-x_min)/(x_max - x))) / &#960;
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/arcsine_cdf.svg" align="middle"></span>
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.constructor"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.constructor">Constructor</a>
</h6>
<pre class="programlisting"><span class="identifier">arcsine_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">);</span>
</pre>
<p>
constructs an arcsine distribution with range parameters <span class="emphasis"><em>x_min</em></span>
and <span class="emphasis"><em>x_max</em></span>.
</p>
<p>
Requires <span class="emphasis"><em>x_min &lt; x_max</em></span>, otherwise <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
is called.
</p>
<p>
For example:
</p>
<pre class="programlisting"><span class="identifier">arcsine_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">myarcsine</span><span class="special">(-</span><span class="number">2</span><span class="special">,</span> <span class="number">4</span><span class="special">);</span>
</pre>
<p>
constructs an arcsine distribution with <span class="emphasis"><em>x_min = -2</em></span>
and <span class="emphasis"><em>x_max = 4</em></span>.
</p>
<p>
Default values of <span class="emphasis"><em>x_min = 0</em></span> and <span class="emphasis"><em>x_max =
1</em></span> and a <code class="computeroutput"> <span class="keyword">typedef</span> <span class="identifier">arcsine_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">arcsine</span><span class="special">;</span></code>
mean that
</p>
<pre class="programlisting"><span class="identifier">arcsine</span> <span class="identifier">as</span><span class="special">;</span>
</pre>
<p>
constructs a 'Standard 01' arcsine distribution.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.parameter_accessors"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.parameter_accessors">Parameter
Accessors</a>
</h6>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">x_min</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">x_max</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Return the parameter <span class="emphasis"><em>x_min</em></span> or <span class="emphasis"><em>x_max</em></span>
from which this distribution was constructed.
</p>
<p>
So, for example:
</p>
<pre class="programlisting"><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">arcsine_distribution</span><span class="special">;</span>
<span class="identifier">arcsine_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">as</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">5</span><span class="special">);</span> <span class="comment">// Cconstructs a double arcsine distribution.</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">as</span><span class="special">.</span><span class="identifier">x_min</span><span class="special">()</span> <span class="special">==</span> <span class="number">2.</span><span class="special">);</span> <span class="comment">// as.x_min() returns 2.</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">as</span><span class="special">.</span><span class="identifier">x_max</span><span class="special">()</span> <span class="special">==</span> <span class="number">5.</span><span class="special">);</span> <span class="comment">// as.x_max() returns 5.</span>
</pre>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.non_member_accessor_functions"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.non_member_accessor_functions">Non-member
Accessor Functions</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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The formulae for calculating these are shown in the table below, and at
<a href="http://mathworld.wolfram.com/arcsineDistribution.html" target="_top">Wolfram
Mathworld</a>.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
There are always <span class="bold"><strong>two</strong></span> values for the
<span class="bold"><strong>mode</strong></span>, at <span class="emphasis"><em>x_min</em></span>
and at <span class="emphasis"><em>x_max</em></span>, default 0 and 1, so instead we raise
the exception <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
At these extrema, the PDFs are infinite, and the CDFs zero or unity.
</p></td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.applications"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.applications">Applications</a>
</h5>
<p>
The arcsine distribution is useful to describe <a href="http://en.wikipedia.org/wiki/Random_walk" target="_top">Random
walks</a>, (including drunken walks) <a href="http://en.wikipedia.org/wiki/Brownian_motion" target="_top">Brownian
motion</a>, <a href="http://en.wikipedia.org/wiki/Wiener_process" target="_top">Weiner
processes</a>, <a href="http://en.wikipedia.org/wiki/Bernoulli_trial" target="_top">Bernoulli
trials</a>, and their appplication to solve stock market and other
<a href="http://en.wikipedia.org/wiki/Gambler%27s_ruin" target="_top">ruinous gambling
games</a>.
</p>
<p>
The random variate <span class="emphasis"><em>x</em></span> is constrained to <span class="emphasis"><em>x_min</em></span>
and <span class="emphasis"><em>x_max</em></span>, (for our 'standard' distribution, 0 and
1), and is usually some fraction. For any other <span class="emphasis"><em>x_min</em></span>
and <span class="emphasis"><em>x_max</em></span> a fraction can be obtained from <span class="emphasis"><em>x</em></span>
using
</p>
<p>
&#8198; fraction = (x - x_min) / (x_max - x_min)
</p>
<p>
The simplest example is tossing heads and tails with a fair coin and modelling
the risk of losing, or winning. Walkers (molecules, drunks...) moving left
or right of a centre line are another common example.
</p>
<p>
The random variate <span class="emphasis"><em>x</em></span> is the fraction of time spent
on the 'winning' side. If half the time is spent on the 'winning' side
(and so the other half on the 'losing' side) then <span class="emphasis"><em>x = 1/2</em></span>.
</p>
<p>
For large numbers of tosses, this is modelled by the (standard [0,1]) arcsine
distribution, and the PDF can be calculated thus:
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1.</span> <span class="special">/</span> <span class="number">2</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.637</span>
<span class="comment">// pdf has a minimum at x = 0.5</span>
</pre>
<p>
From the plot of PDF, it is clear that <span class="emphasis"><em>x</em></span> = &#189; is the
<span class="bold"><strong>minimum</strong></span> of the curve, so this is the
<span class="bold"><strong>least likely</strong></span> scenario. (This is highly
counter-intuitive, considering that fair tosses must <span class="bold"><strong>eventually</strong></span>
become equal. It turns out that <span class="emphasis"><em>eventually</em></span> is not
just very long, but <span class="bold"><strong>infinite</strong></span>!).
</p>
<p>
The <span class="bold"><strong>most likely</strong></span> scenarios are towards
the extrema where <span class="emphasis"><em>x</em></span> = 0 or <span class="emphasis"><em>x</em></span>
= 1.
</p>
<p>
If fraction of time on the left is a &#188;, it is only slightly more likely
because the curve is quite flat bottomed.
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1.</span> <span class="special">/</span> <span class="number">4</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.735</span>
</pre>
<p>
If we consider fair coin-tossing games being played for 100 days (hypothetically
continuously to be 'at-limit') the person winning after day 5 will not
change in fraction 0.144 of the cases.
</p>
<p>
We can easily compute this setting <span class="emphasis"><em>x</em></span> = 5./100 = 0.05
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">cdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.05</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.144</span>
</pre>
<p>
Similarly, we can compute from a fraction of 0.05 /2 = 0.025 (halved because
we are considering both winners and losers) corresponding to 1 - 0.025
or 97.5% of the gamblers, (walkers, particles...) on the <span class="bold"><strong>same
side</strong></span> of the origin
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="number">2</span> <span class="special">*</span> <span class="identifier">cdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1</span> <span class="special">-</span> <span class="number">0.975</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.202</span>
</pre>
<p>
(use of the complement gives a bit more clarity, and avoids potential loss
of accuracy when <span class="emphasis"><em>x</em></span> is close to unity, see <a class="link" href="../../stat_tut/overview/complements.html#why_complements">why
complements?</a>).
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="number">2</span> <span class="special">*</span> <span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.975</span><span class="special">))</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.202</span>
</pre>
<p>
or we can reverse the calculation by assuming a fraction of time on one
side, say fraction 0.2,
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">quantile</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">1</span> <span class="special">-</span> <span class="number">0.2</span> <span class="special">/</span> <span class="number">2</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.976</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">quantile</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.2</span> <span class="special">/</span> <span class="number">2</span><span class="special">))</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 0.976</span>
</pre>
<p>
<span class="bold"><strong>Summary</strong></span>: Every time we toss, the odds
are equal, so on average we have the same change of winning and losing.
</p>
<p>
But this is <span class="bold"><strong>not true</strong></span> for an an individual
game where one will be <span class="bold"><strong>mostly in a bad or good patch</strong></span>.
</p>
<p>
This is quite counter-intuitive to most people, but the mathematics is
clear, and gamblers continue to provide proof.
</p>
<p>
<span class="bold"><strong>Moral</strong></span>: if you in a losing patch, leave
the game. (Because the odds to recover to a good patch are poor).
</p>
<p>
<span class="bold"><strong>Corollary</strong></span>: Quit while you are ahead?
</p>
<p>
A working example is at <a href="../../../../../example/arcsine_example.cpp" target="_top">arcsine_example.cpp</a>
including sample output .
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.related_distributions"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.related_distributions">Related
distributions</a>
</h5>
<p>
The arcsine distribution with <span class="emphasis"><em>x_min = 0</em></span> and <span class="emphasis"><em>x_max
= 1</em></span> is special case of the <a class="link" href="beta_dist.html" title="Beta Distribution">Beta
Distribution</a> with &#945; = 1/2 and &#946; = 1/2.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.accuracy"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.accuracy">Accuracy</a>
</h5>
<p>
This distribution is implemented using sqrt, sine, cos and arc sine and
cos trigonometric functions which are normally accurate to a few <a href="http://en.wikipedia.org/wiki/Machine_epsilon" target="_top">machine epsilon</a>.
But all values suffer from <a href="http://en.wikipedia.org/wiki/Loss_of_significance" target="_top">loss
of significance or cancellation error</a> for values of <span class="emphasis"><em>x</em></span>
close to <span class="emphasis"><em>x_max</em></span>. For example, for a standard [0, 1]
arcsine distribution <span class="emphasis"><em>as</em></span>, the pdf is symmetric about
random variate <span class="emphasis"><em>x = 0.5</em></span> so that one would expect <code class="computeroutput"><span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.01</span><span class="special">)</span> <span class="special">==</span>
<span class="identifier">pdf</span><span class="special">(</span><span class="identifier">as</span><span class="special">,</span> <span class="number">0.99</span><span class="special">)</span></code>. But
as <span class="emphasis"><em>x</em></span> nears unity, there is increasing <a href="http://en.wikipedia.org/wiki/Loss_of_significance" target="_top">loss
of significance</a>. To counteract this, the complement versions of
CDF and quantile are implemented with alternative expressions using <span class="emphasis"><em>cos<sup>-1</sup></em></span>
instead of <span class="emphasis"><em>sin<sup>-1</sup></em></span>. Users should see <a class="link" href="../../stat_tut/overview/complements.html#why_complements">why
complements?</a> for guidance on when to avoid loss of accuracy by using
complements.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h6"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.testing"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.testing">Testing</a>
</h5>
<p>
The results were tested against a few accurate spot values computed by
<a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a>, for example:
</p>
<pre class="programlisting"><span class="identifier">N</span><span class="special">[</span><span class="identifier">PDF</span><span class="special">[</span><span class="identifier">arcsinedistribution</span><span class="special">[</span><span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">],</span> <span class="number">0.5</span><span class="special">],</span> <span class="number">50</span><span class="special">]</span>
<span class="number">0.63661977236758134307553505349005744813783858296183</span>
</pre>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h7"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.implementation"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.implementation">Implementation</a>
</h5>
<p>
In the following table <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span>
are the parameters <span class="emphasis"><em>x_min</em></span> &#160; and <span class="emphasis"><em>x_max</em></span>,
<span class="emphasis"><em>x</em></span> is the random variable, <span class="emphasis"><em>p</em></span> is
the probability and its complement <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>
support
</p>
</td>
<td>
<p>
x &#8712; [a, b], default x &#8712; [0, 1]
</p>
</td>
</tr>
<tr>
<td>
<p>
pdf
</p>
</td>
<td>
<p>
f(x; a, b) = 1/(&#960;&#8901;&#8730;(x - a)&#8901;(b - x))
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
F(x) = 2/&#960;&#8901;sin<sup>-1</sup>(&#8730;(x - a) / (b - a) )
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf of complement
</p>
</td>
<td>
<p>
2/(&#960;&#8901;cos<sup>-1</sup>(&#8730;(x - a) / (b - a)))
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
-a&#8901;sin<sup>2</sup>(&#189;&#960;&#8901;p) + a + b&#8901;sin<sup>2</sup>(&#189;&#960;&#8901;p)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
-a&#8901;cos<sup>2</sup>(&#189;&#960;&#8901;p) + a + b&#8901;cos<sup>2</sup>(&#189;&#960;&#8901;q)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
&#189;(a+b)
</p>
</td>
</tr>
<tr>
<td>
<p>
median
</p>
</td>
<td>
<p>
&#189;(a+b)
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
x &#8712; [a, b], so raises domain_error (returning NaN).
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
(b - a)<sup>2</sup> / 8
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
-3/2
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
kurtosis_excess + 3
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
The quantile was calculated using an expression obtained by using <a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a> to invert the
formula for the CDF thus
</p>
<pre class="programlisting"><span class="identifier">solve</span> <span class="special">[</span><span class="identifier">p</span> <span class="special">-</span> <span class="number">2</span><span class="special">/</span><span class="identifier">pi</span> <span class="identifier">sin</span><span class="special">^-</span><span class="number">1</span><span class="special">(</span><span class="identifier">sqrt</span><span class="special">((</span><span class="identifier">x</span><span class="special">-</span><span class="identifier">a</span><span class="special">)/(</span><span class="identifier">b</span><span class="special">-</span><span class="identifier">a</span><span class="special">)))</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">x</span><span class="special">]</span>
</pre>
<p>
which was interpreted as
</p>
<pre class="programlisting"><span class="identifier">Solve</span><span class="special">[</span><span class="identifier">p</span> <span class="special">-</span> <span class="special">(</span><span class="number">2</span> <span class="identifier">ArcSin</span><span class="special">[</span><span class="identifier">Sqrt</span><span class="special">[(-</span><span class="identifier">a</span> <span class="special">+</span> <span class="identifier">x</span><span class="special">)/(-</span><span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span><span class="special">)]])/</span><span class="identifier">Pi</span> <span class="special">==</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">MaxExtraConditions</span> <span class="special">-&gt;</span> <span class="identifier">Automatic</span><span class="special">]</span>
</pre>
<p>
and produced the resulting expression
</p>
<pre class="programlisting"><span class="identifier">x</span> <span class="special">=</span> <span class="special">-</span><span class="identifier">a</span> <span class="identifier">sin</span><span class="special">^</span><span class="number">2</span><span class="special">((</span><span class="identifier">pi</span> <span class="identifier">p</span><span class="special">)/</span><span class="number">2</span><span class="special">)+</span><span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span> <span class="identifier">sin</span><span class="special">^</span><span class="number">2</span><span class="special">((</span><span class="identifier">pi</span> <span class="identifier">p</span><span class="special">)/</span><span class="number">2</span><span class="special">)</span>
</pre>
<p>
Thanks to Wolfram for providing this facility.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h8"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.references"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/arcsine_distribution" target="_top">Wikipedia
arcsine distribution</a>
</li>
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Beta_distribution" target="_top">Wikipedia
Beta distribution</a>
</li>
<li class="listitem">
<a href="http://mathworld.wolfram.com/BetaDistribution.html" target="_top">Wolfram
MathWorld</a>
</li>
<li class="listitem">
<a href="http://www.wolframalpha.com/" target="_top">Wolfram Alpha</a>
</li>
</ul></div>
<h5>
<a name="math_toolkit.dist_ref.dists.arcine_dist.h9"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.arcine_dist.sources"></a></span><a class="link" href="arcine_dist.html#math_toolkit.dist_ref.dists.arcine_dist.sources">Sources</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://estebanmoro.org/2009/04/the-probability-of-going-through-a-bad-patch" target="_top">The
probability of going through a bad patch</a> Esteban Moro's Blog.
</li>
<li class="listitem">
<a href="http://www.gotohaggstrom.com/What%20do%20schmucks%20and%20the%20arc%20sine%20law%20have%20in%20common.pdf" target="_top">What
soschumcks and the arc sine have in common</a> Peter Haggstrom.
</li>
<li class="listitem">
<a href="http://www.math.uah.edu/stat/special/Arcsine.html" target="_top">arcsine
distribution</a>.
</li>
<li class="listitem">
<a href="http://reference.wolfram.com/language/ref/ArcSinDistribution.html" target="_top">Wolfram
reference arcsine examples</a>.
</li>
<li class="listitem">
<a href="http://www.math.harvard.edu/library/sternberg/slides/1180908.pdf" target="_top">Shlomo
Sternberg slides</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="../dists.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="bernoulli_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,357 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Bernoulli Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="arcine_dist.html" title="Arcsine Distribution">
<link rel="next" href="beta_dist.html" title="Beta 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="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>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="math_toolkit.dist_ref.dists.bernoulli_dist"></a><a class="link" href="bernoulli_dist.html" title="Bernoulli Distribution">Bernoulli
Distribution</a>
</h4></div></div></div>
<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>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">bernoulli_distribution</span><span class="special">;</span>
<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>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">bernoulli_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">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>
<span class="comment">// Accessor function.</span>
<span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span>
<span class="comment">// Probability of success (as a fraction).</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The Bernoulli distribution is a discrete distribution of the outcome of
a single trial with only two results, 0 (failure) or 1 (success), with
a probability of success p.
</p>
<p>
The Bernoulli distribution is the simplest building block on which other
discrete distributions of sequences of independent Bernoulli trials can
be based.
</p>
<p>
The Bernoulli is the binomial distribution (k = 1, p) with only one trial.
</p>
<p>
<a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
density function pdf</a> f(0) = 1 - p, f(1) = p. <a href="http://en.wikipedia.org/wiki/Cumulative_Distribution_Function" target="_top">Cumulative
distribution function</a> D(k) = if (k == 0) 1 - p else 1.
</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 outcome of the single trial:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/bernoulli_pdf.svg" align="middle"></span>
</p>
<p>
and the <a href="http://en.wikipedia.org/wiki/Cumulative_Distribution_Function" target="_top">Cumulative
distribution function</a>
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/bernoulli_cdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.bernoulli_dist.h0"></a>
<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
Functions</a>
</h5>
<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>
</pre>
<p>
Constructs a <a href="http://en.wikipedia.org/wiki/bernoulli_distribution" target="_top">bernoulli
distribution</a> with success_fraction <span class="emphasis"><em>p</em></span>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span>
</pre>
<p>
Returns the <span class="emphasis"><em>success_fraction</em></span> parameter of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.bernoulli_dist.h1"></a>
<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
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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is 0 and 1, and the useful supported
range is only 0 or 1.
</p>
<p>
Outside this range, functions are undefined, or may throw domain_error
exception and make an error message available.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.bernoulli_dist.h2"></a>
<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>
</h5>
<p>
The Bernoulli distribution is implemented with simple arithmetic operators
and so should have errors within an epsilon or two.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.bernoulli_dist.h3"></a>
<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>
</h5>
<p>
In the following table <span class="emphasis"><em>p</em></span> is the probability of success
and <span class="emphasis"><em>q = 1-p</em></span>. <span class="emphasis"><em>k</em></span> is the random
variate, either 0 or 1.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
The Bernoulli distribution is implemented here as a <span class="emphasis"><em>strict
discrete</em></span> distribution. If a generalised version, allowing
k to be any real, is required then the binomial distribution with a single
trial should be used, for example:
</p>
<p>
<code class="computeroutput"><span class="identifier">binomial_distribution</span><span class="special">(</span><span class="number">1</span><span class="special">,</span>
<span class="number">0.25</span><span class="special">)</span></code>
</p>
</td></tr>
</table></div>
<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>
Supported range
</p>
</td>
<td>
<p>
{0, 1}
</p>
</td>
</tr>
<tr>
<td>
<p>
pdf
</p>
</td>
<td>
<p>
Using the relation: pdf = 1 - p for k = 0, else p
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: cdf = 1 - p for k = 0, else 1
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
q = 1 - p
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
if x &lt;= (1-p) 0 else 1
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
if x &lt;= (1-p) 1 else 0
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
p
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
p * (1 - p)
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
if (p &lt; 0.5) 0 else 1
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
(1 - 2 * p) / sqrt(p * q)
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
6 * p * p - 6 * p +1/ p * q
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
kurtosis -3
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.bernoulli_dist.h4"></a>
<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>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Bernoulli_distribution" target="_top">Wikpedia
Bernoulli distribution</a>
</li>
<li class="listitem">
<a href="http://mathworld.wolfram.com/BernoulliDistribution.html" target="_top">Weisstein,
Eric W. "Bernoulli Distribution." From MathWorld--A Wolfram
Web Resource.</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="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>
</div>
</body>
</html>

View File

@@ -0,0 +1,623 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Beta Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="bernoulli_dist.html" title="Bernoulli Distribution">
<link rel="next" href="binomial_dist.html" title="Binomial 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="bernoulli_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="binomial_dist.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.dist_ref.dists.beta_dist"></a><a class="link" href="beta_dist.html" title="Beta Distribution">Beta Distribution</a>
</h4></div></div></div>
<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">beta</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">beta_distribution</span><span class="special">;</span>
<span class="comment">// typedef beta_distribution&lt;double&gt; beta;</span>
<span class="comment">// Note that this is deliberately NOT provided,</span>
<span class="comment">// to avoid a clash with the function name beta.</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">beta_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="comment">// Constructor from two shape parameters, alpha &amp; beta:</span>
<span class="identifier">beta_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">b</span><span class="special">);</span>
<span class="comment">// Parameter accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Parameter estimators of alpha or beta from mean and variance.</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_alpha</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">mean</span><span class="special">,</span> <span class="comment">// Expected value of mean.</span>
<span class="identifier">RealType</span> <span class="identifier">variance</span><span class="special">);</span> <span class="comment">// Expected value of variance.</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_beta</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">mean</span><span class="special">,</span> <span class="comment">// Expected value of mean.</span>
<span class="identifier">RealType</span> <span class="identifier">variance</span><span class="special">);</span> <span class="comment">// Expected value of variance.</span>
<span class="comment">// Parameter estimators from</span>
<span class="comment">// either alpha or beta, and x and probability.</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_alpha</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span> <span class="comment">// from beta.</span>
<span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="comment">// x.</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// cdf</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_beta</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span> <span class="comment">// alpha.</span>
<span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="comment">// probability x.</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// probability cdf.</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The class type <code class="computeroutput"><span class="identifier">beta_distribution</span></code>
represents a <a href="http://en.wikipedia.org/wiki/Beta_distribution" target="_top">beta
</a> <a href="http://en.wikipedia.org/wiki/Probability_distribution" target="_top">probability
distribution function</a>.
</p>
<p>
The <a href="http://mathworld.wolfram.com/BetaDistribution.htm" target="_top">beta
distribution </a> is used as a <a href="http://en.wikipedia.org/wiki/Prior_distribution" target="_top">prior
distribution</a> for binomial proportions in <a href="http://mathworld.wolfram.com/BayesianAnalysis.html" target="_top">Bayesian
analysis</a>.
</p>
<p>
See also: <a href="http://documents.wolfram.com/calculationcenter/v2/Functions/ListsMatrices/Statistics/BetaDistribution.html" target="_top">beta
distribution</a> and <a href="http://en.wikipedia.org/wiki/Bayesian_statistics" target="_top">Bayesian
statistics</a>.
</p>
<p>
How the beta distribution is used for <a href="http://home.uchicago.edu/~grynav/bayes/ABSLec5.ppt" target="_top">Bayesian
analysis of one parameter models</a> is discussed by Jeff Grynaviski.
</p>
<p>
The <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
density function PDF</a> for the <a href="http://en.wikipedia.org/wiki/Beta_distribution" target="_top">beta
distribution</a> defined on the interval [0,1] is given by:
</p>
<p>
f(x;&#945;,&#946;) = x<sup>&#945; - 1</sup> (1 - x)<sup>&#946; -1</sup> / B(&#945;, &#946;)
</p>
<p>
where B(&#945;, &#946;) is the <a href="http://en.wikipedia.org/wiki/Beta_function" target="_top">beta
function</a>, implemented in this library as <a class="link" href="../../sf_beta/beta_function.html" title="Beta">beta</a>.
Division by the beta function ensures that the pdf is normalized to the
range zero to unity.
</p>
<p>
The following graph illustrates examples of the pdf for various values
of the shape parameters. Note the &#945; = &#946; = 2 (blue line) is dome-shaped, and
might be approximated by a symmetrical triangular distribution.
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/beta_pdf.svg" align="middle"></span>
</p>
<p>
If &#945; = &#946; = 1, then it is a __space <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">uniform
distribution</a>, equal to unity in the entire interval x = 0 to 1.
If &#945; __space and &#946; __space are &lt; 1, then the pdf is U-shaped. If &#945; != &#946;, then
the shape is asymmetric and could be approximated by a triangle whose apex
is away from the centre (where x = half).
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.beta_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.member_functions"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.member_functions">Member
Functions</a>
</h5>
<h6>
<a name="math_toolkit.dist_ref.dists.beta_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.constructor"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.constructor">Constructor</a>
</h6>
<pre class="programlisting"><span class="identifier">beta_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">);</span>
</pre>
<p>
Constructs a beta distribution with shape parameters <span class="emphasis"><em>alpha</em></span>
and <span class="emphasis"><em>beta</em></span>.
</p>
<p>
Requires alpha,beta &gt; 0,otherwise <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
is called. Note that technically the beta distribution is defined for alpha,beta
&gt;= 0, but it's not clear whether any program can actually make use of
that latitude or how many of the non-member functions can be usefully defined
in that case. Therefore for now, we regard it as an error if alpha or beta
is zero.
</p>
<p>
For example:
</p>
<pre class="programlisting"><span class="identifier">beta_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">mybeta</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">5</span><span class="special">);</span>
</pre>
<p>
Constructs a the beta distribution with alpha=2 and beta=5 (shown in yellow
in the graph above).
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.beta_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.parameter_accessors"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.parameter_accessors">Parameter
Accessors</a>
</h6>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>alpha</em></span> from which this distribution
was constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>beta</em></span> from which this distribution
was constructed.
</p>
<p>
So for example:
</p>
<pre class="programlisting"><span class="identifier">beta_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">mybeta</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">5</span><span class="special">);</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">mybeta</span><span class="special">.</span><span class="identifier">alpha</span><span class="special">()</span> <span class="special">==</span> <span class="number">2.</span><span class="special">);</span> <span class="comment">// mybeta.alpha() returns 2</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">mybeta</span><span class="special">.</span><span class="identifier">beta</span><span class="special">()</span> <span class="special">==</span> <span class="number">5.</span><span class="special">);</span> <span class="comment">// mybeta.beta() returns 5</span>
</pre>
<h5>
<a name="math_toolkit.dist_ref.dists.beta_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.parameter_estimators"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.parameter_estimators">Parameter
Estimators</a>
</h5>
<p>
Two pairs of parameter estimators are provided.
</p>
<p>
One estimates either &#945; __space or &#946; __space from presumed-known mean and variance.
</p>
<p>
The other pair estimates either &#945; __space or &#946; __space from the cdf and x.
</p>
<p>
It is also possible to estimate &#945; __space and &#946; __space from 'known' mode &amp;
quantile. For example, calculators are provided by the <a href="http://www.ausvet.com.au/pprev/content.php?page=PPscript" target="_top">Pooled
Prevalence Calculator</a> and <a href="http://www.epi.ucdavis.edu/diagnostictests/betabuster.html" target="_top">Beta
Buster</a> but this is not yet implemented here.
</p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_alpha</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">mean</span><span class="special">,</span> <span class="comment">// Expected value of mean.</span>
<span class="identifier">RealType</span> <span class="identifier">variance</span><span class="special">);</span> <span class="comment">// Expected value of variance.</span>
</pre>
<p>
Returns the unique value of &#945; &#160; that corresponds to a beta distribution with
mean <span class="emphasis"><em>mean</em></span> and variance <span class="emphasis"><em>variance</em></span>.
</p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_beta</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">mean</span><span class="special">,</span> <span class="comment">// Expected value of mean.</span>
<span class="identifier">RealType</span> <span class="identifier">variance</span><span class="special">);</span> <span class="comment">// Expected value of variance.</span>
</pre>
<p>
Returns the unique value of &#946; &#160; that corresponds to a beta distribution with
mean <span class="emphasis"><em>mean</em></span> and variance <span class="emphasis"><em>variance</em></span>.
</p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_alpha</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span> <span class="comment">// from beta.</span>
<span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="comment">// x.</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// probability cdf</span>
</pre>
<p>
Returns the value of &#945; &#160; that gives: <code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">beta_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;(</span><span class="identifier">alpha</span><span class="special">,</span> <span class="identifier">beta</span><span class="special">),</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">probability</span></code>.
</p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_beta</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span> <span class="comment">// alpha.</span>
<span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="comment">// probability x.</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// probability cdf.</span>
</pre>
<p>
Returns the value of &#946; &#160; that gives: <code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">beta_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;(</span><span class="identifier">alpha</span><span class="special">,</span> <span class="identifier">beta</span><span class="special">),</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">probability</span></code>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.beta_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.non_member_accessor_functions"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.non_member_accessor_functions">Non-member
Accessor Functions</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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The formulae for calculating these are shown in the table below, and at
<a href="http://mathworld.wolfram.com/BetaDistribution.html" target="_top">Wolfram
Mathworld</a>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.beta_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.applications"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.applications">Applications</a>
</h5>
<p>
The beta distribution can be used to model events constrained to take place
within an interval defined by a minimum and maximum value: so it is used
in project management systems.
</p>
<p>
It is also widely used in <a href="http://en.wikipedia.org/wiki/Bayesian_inference" target="_top">Bayesian
statistical inference</a>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.beta_dist.h6"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.related_distributions"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.related_distributions">Related
distributions</a>
</h5>
<p>
The beta distribution with both &#945; __space and &#946; = 1 follows a <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">uniform
distribution</a>.
</p>
<p>
The <a href="http://en.wikipedia.org/wiki/Triangular_distribution" target="_top">triangular</a>
is used when less precise information is available.
</p>
<p>
The <a href="http://en.wikipedia.org/wiki/Binomial_distribution" target="_top">binomial
distribution</a> is closely related when &#945; __space and &#946; __space are integers.
</p>
<p>
With integer values of &#945; __space and &#946; __space the distribution B(i, j) is
that of the j-th highest of a sample of i + j + 1 independent random variables
uniformly distributed between 0 and 1. The cumulative probability from
0 to x is thus the probability that the j-th highest value is less than
x. Or it is the probability that at least i of the random variables are
less than x, a probability given by summing over the <a class="link" href="binomial_dist.html" title="Binomial Distribution">Binomial
Distribution</a> with its p parameter set to x.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.beta_dist.h7"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.accuracy"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.accuracy">Accuracy</a>
</h5>
<p>
This distribution is implemented using the <a class="link" href="../../sf_beta/beta_function.html" title="Beta">beta
functions</a> <a class="link" href="../../sf_beta/beta_function.html" title="Beta">beta</a>
and <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">incomplete beta
functions</a> <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>
and <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>;
please refer to these functions for information on accuracy.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.beta_dist.h8"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.implementation"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.implementation">Implementation</a>
</h5>
<p>
In the following table <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span>
are the parameters &#945; &#160; and &#946;, <span class="emphasis"><em>x</em></span> is the random variable,
<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>
f(x;&#945;,&#946;) = x<sup>&#945; - 1</sup> (1 - x)<sup>&#946; -1</sup> / B(&#945;, &#946;)
</p>
<p>
Implemented using <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>(a,
b, x).
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the incomplete beta function <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(a,
b, x)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
<a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>(a,
b, x)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the inverse incomplete beta function <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>(a,
b, p)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
<a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibetac_inv</a>(a,
b, q)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">a</span><span class="special">/(</span><span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">a</span> <span class="special">*</span>
<span class="identifier">b</span> <span class="special">/</span>
<span class="special">(</span><span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">)^</span><span class="number">2</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">+</span>
<span class="identifier">b</span> <span class="special">+</span>
<span class="number">1</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">(</span><span class="identifier">a</span><span class="special">-</span><span class="number">1</span><span class="special">)</span> <span class="special">/</span>
<span class="special">(</span><span class="identifier">a</span>
<span class="special">+</span> <span class="identifier">b</span>
<span class="special">-</span> <span class="number">2</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="number">2</span> <span class="special">(</span><span class="identifier">b</span><span class="special">-</span><span class="identifier">a</span><span class="special">)</span>
<span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">+</span><span class="number">1</span><span class="special">)/(</span><span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">+</span><span class="number">2</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">a</span>
<span class="special">*</span> <span class="identifier">b</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/beta_dist_kurtosis.svg"></span>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">kurtosis</span> <span class="special">+</span>
<span class="number">3</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
parameter estimation
</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>
alpha
</p>
<p>
from mean and variance
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">mean</span> <span class="special">*</span>
<span class="special">((</span> <span class="special">(</span><span class="identifier">mean</span> <span class="special">*</span>
<span class="special">(</span><span class="number">1</span>
<span class="special">-</span> <span class="identifier">mean</span><span class="special">))</span> <span class="special">/</span>
<span class="identifier">variance</span><span class="special">)-</span>
<span class="number">1</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
beta
</p>
<p>
from mean and variance
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">(</span><span class="number">1</span>
<span class="special">-</span> <span class="identifier">mean</span><span class="special">)</span> <span class="special">*</span>
<span class="special">(((</span><span class="identifier">mean</span>
<span class="special">*</span> <span class="special">(</span><span class="number">1</span> <span class="special">-</span> <span class="identifier">mean</span><span class="special">))</span>
<span class="special">/</span><span class="identifier">variance</span><span class="special">)-</span><span class="number">1</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
The member functions <code class="computeroutput"><span class="identifier">find_alpha</span></code>
and <code class="computeroutput"><span class="identifier">find_beta</span></code>
</p>
<p>
from cdf and probability x
</p>
<p>
and <span class="bold"><strong>either</strong></span> <code class="computeroutput"><span class="identifier">alpha</span></code>
or <code class="computeroutput"><span class="identifier">beta</span></code>
</p>
</td>
<td>
<p>
Implemented in terms of the inverse incomplete beta functions
</p>
<p>
<a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inva</a>,
and <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_invb</a>
respectively.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_alpha</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">ibeta_inva</span><span class="special">(</span><span class="identifier">beta</span><span class="special">,</span>
<span class="identifier">x</span><span class="special">,</span>
<span class="identifier">probability</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_beta</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">ibeta_invb</span><span class="special">(</span><span class="identifier">alpha</span><span class="special">,</span>
<span class="identifier">x</span><span class="special">,</span>
<span class="identifier">probability</span><span class="special">)</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.beta_dist.h9"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.beta_dist.references"></a></span><a class="link" href="beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.references">References</a>
</h5>
<p>
<a href="http://en.wikipedia.org/wiki/Beta_distribution" target="_top">Wikipedia Beta
distribution</a>
</p>
<p>
<a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm" target="_top">NIST
Exploratory Data Analysis</a>
</p>
<p>
<a href="http://mathworld.wolfram.com/BetaDistribution.html" target="_top">Wolfram
MathWorld</a>
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="bernoulli_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="binomial_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,909 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Binomial Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="beta_dist.html" title="Beta Distribution">
<link rel="next" href="cauchy_dist.html" title="Cauchy-Lorentz 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="beta_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="cauchy_dist.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.dist_ref.dists.binomial_dist"></a><a class="link" href="binomial_dist.html" title="Binomial Distribution">Binomial
Distribution</a>
</h4></div></div></div>
<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">binomial</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">binomial_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">binomial_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">binomial</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">binomial_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="keyword">static</span> <span class="keyword">const</span> <span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">;</span>
<span class="keyword">static</span> <span class="keyword">const</span> <span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">jeffreys_prior_interval</span><span class="special">;</span>
<span class="comment">// construct:</span>
<span class="identifier">binomial_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
<span class="comment">// parameter access::</span>
<span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Bounds on success fraction:</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_lower_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">,</span>
<span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">method</span> <span class="special">=</span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_upper_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">,</span>
<span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">method</span> <span class="special">=</span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">);</span>
<span class="comment">// estimate min/max number of trials:</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of events</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// risk level</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of events</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// risk level</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The class type <code class="computeroutput"><span class="identifier">binomial_distribution</span></code>
represents a <a href="http://mathworld.wolfram.com/BinomialDistribution.html" target="_top">binomial
distribution</a>: it is used when there are exactly two mutually exclusive
outcomes of a trial. These outcomes are labelled "success" and
"failure". The <a class="link" href="binomial_dist.html" title="Binomial Distribution">Binomial
Distribution</a> is used to obtain the probability of observing k successes
in N trials, with the probability of success on a single trial denoted
by p. The binomial distribution assumes that p is fixed for all trials.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
The random variable for the binomial distribution is the number of successes,
(the number of trials is a fixed property of the distribution) whereas
for the negative binomial, the random variable is the number of trials,
for a fixed number of successes.
</p></td></tr>
</table></div>
<p>
The PDF for the binomial distribution is given by:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/binomial_ref2.svg"></span>
</p>
<p>
The following two graphs illustrate how the PDF changes depending upon
the distributions parameters, first we'll keep the success fraction <span class="emphasis"><em>p</em></span>
fixed at 0.5, and vary the sample size:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/binomial_pdf_1.svg" align="middle"></span>
</p>
<p>
Alternatively, we can keep the sample size fixed at N=20 and vary the success
fraction <span class="emphasis"><em>p</em></span>:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/binomial_pdf_2.svg" align="middle"></span>
</p>
<div class="caution"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top">
<p>
The Binomial distribution is a discrete distribution: internally, functions
like the <code class="computeroutput"><span class="identifier">cdf</span></code> and <code class="computeroutput"><span class="identifier">pdf</span></code> are treated "as if" they
are continuous functions, but in reality the results returned from these
functions only have meaning if an integer value is provided for the random
variate argument.
</p>
<p>
The quantile function will by default return an integer result that has
been <span class="emphasis"><em>rounded outwards</em></span>. That is to say lower quantiles
(where the probability is less than 0.5) are rounded downward, and upper
quantiles (where the probability is greater than 0.5) are rounded upwards.
This behaviour ensures that if an X% quantile is requested, then <span class="emphasis"><em>at
least</em></span> the requested coverage will be present in the central
region, and <span class="emphasis"><em>no more than</em></span> the requested coverage
will be present in the tails.
</p>
<p>
This behaviour can be changed so that the quantile functions are rounded
differently, or even return a real-valued result using <a class="link" href="../../pol_overview.html" title="Policy Overview">Policies</a>.
It is strongly recommended that you read the tutorial <a class="link" href="../../pol_tutorial/understand_dis_quant.html" title="Understanding Quantiles of Discrete Distributions">Understanding
Quantiles of Discrete Distributions</a> before using the quantile
function on the Binomial distribution. The <a class="link" href="../../pol_ref/discrete_quant_ref.html" title="Discrete Quantile Policies">reference
docs</a> describe how to change the rounding policy for these distributions.
</p>
</td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.member_functions"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.member_functions">Member
Functions</a>
</h5>
<h6>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.construct"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.construct">Construct</a>
</h6>
<pre class="programlisting"><span class="identifier">binomial_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
</pre>
<p>
Constructor: <span class="emphasis"><em>n</em></span> is the total number of trials, <span class="emphasis"><em>p</em></span>
is the probability of success of a single trial.
</p>
<p>
Requires <code class="computeroutput"><span class="number">0</span> <span class="special">&lt;=</span>
<span class="identifier">p</span> <span class="special">&lt;=</span>
<span class="number">1</span></code>, and <code class="computeroutput"><span class="identifier">n</span>
<span class="special">&gt;=</span> <span class="number">0</span></code>,
otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.accessors"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.accessors">Accessors</a>
</h6>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>p</em></span> from which this distribution
was constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>n</em></span> from which this distribution
was constructed.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.lower_bound_on_the_success_fract"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.lower_bound_on_the_success_fract">Lower
Bound on the Success Fraction</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_lower_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span>
<span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">method</span> <span class="special">=</span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">);</span>
</pre>
<p>
Returns a lower bound on the success fraction:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">trials</span></dt>
<dd><p>
The total number of trials conducted.
</p></dd>
<dt><span class="term">successes</span></dt>
<dd><p>
The number of successes that occurred.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The largest acceptable probability that the true value of the success
fraction is <span class="bold"><strong>less than</strong></span> the value
returned.
</p></dd>
<dt><span class="term">method</span></dt>
<dd><p>
An optional parameter that specifies the method to be used to compute
the interval (See below).
</p></dd>
</dl>
</div>
<p>
For example, if you observe <span class="emphasis"><em>k</em></span> successes from <span class="emphasis"><em>n</em></span>
trials the best estimate for the success fraction is simply <span class="emphasis"><em>k/n</em></span>,
but if you want to be 95% sure that the true value is <span class="bold"><strong>greater
than</strong></span> some value, <span class="emphasis"><em>p<sub>min</sub></em></span>, then:
</p>
<pre class="programlisting"><span class="identifier">p</span><sub>min</sub> <span class="special">=</span> <span class="identifier">binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_lower_bound_on_p</span><span class="special">(</span>
<span class="identifier">n</span><span class="special">,</span> <span class="identifier">k</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
<a class="link" href="../../stat_tut/weg/binom_eg/binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for a Binomial Distribution">See worked
example.</a>
</p>
<p>
There are currently two possible values available for the <span class="emphasis"><em>method</em></span>
optional parameter: <span class="emphasis"><em>clopper_pearson_exact_interval</em></span>
or <span class="emphasis"><em>jeffreys_prior_interval</em></span>. These constants are both
members of class template <code class="computeroutput"><span class="identifier">binomial_distribution</span></code>,
so usage is for example:
</p>
<pre class="programlisting"><span class="identifier">p</span> <span class="special">=</span> <span class="identifier">binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_lower_bound_on_p</span><span class="special">(</span>
<span class="identifier">n</span><span class="special">,</span> <span class="identifier">k</span><span class="special">,</span> <span class="number">0.05</span><span class="special">,</span> <span class="identifier">binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">jeffreys_prior_interval</span><span class="special">);</span>
</pre>
<p>
The default method if this parameter is not specified is the Clopper Pearson
"exact" interval. This produces an interval that guarantees at
least <code class="computeroutput"><span class="number">100</span><span class="special">(</span><span class="number">1</span><span class="special">-</span><span class="identifier">alpha</span><span class="special">)%</span></code> coverage, but which is known to be overly
conservative, sometimes producing intervals with much greater than the
requested coverage.
</p>
<p>
The alternative calculation method produces a non-informative Jeffreys
Prior interval. It produces <code class="computeroutput"><span class="number">100</span><span class="special">(</span><span class="number">1</span><span class="special">-</span><span class="identifier">alpha</span><span class="special">)%</span></code>
coverage only <span class="emphasis"><em>in the average case</em></span>, though is typically
very close to the requested coverage level. It is one of the main methods
of calculation recommended in the review by Brown, Cai and DasGupta.
</p>
<p>
Please note that the "textbook" calculation method using a normal
approximation (the Wald interval) is deliberately not provided: it is known
to produce consistently poor results, even when the sample size is surprisingly
large. Refer to Brown, Cai and DasGupta for a full explanation. Many other
methods of calculation are available, and may be more appropriate for specific
situations. Unfortunately there appears to be no consensus amongst statisticians
as to which is "best": refer to the discussion at the end of
Brown, Cai and DasGupta for examples.
</p>
<p>
The two methods provided here were chosen principally because they can
be used for both one and two sided intervals. See also:
</p>
<p>
Lawrence D. Brown, T. Tony Cai and Anirban DasGupta (2001), Interval Estimation
for a Binomial Proportion, Statistical Science, Vol. 16, No. 2, 101-133.
</p>
<p>
T. Tony Cai (2005), One-sided confidence intervals in discrete distributions,
Journal of Statistical Planning and Inference 131, 63-88.
</p>
<p>
Agresti, A. and Coull, B. A. (1998). Approximate is better than "exact"
for interval estimation of binomial proportions. Amer. Statist. 52 119-126.
</p>
<p>
Clopper, C. J. and Pearson, E. S. (1934). The use of confidence or fiducial
limits illustrated in the case of the binomial. Biometrika 26 404-413.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.upper_bound_on_the_success_fract"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.upper_bound_on_the_success_fract">Upper
Bound on the Success Fraction</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_upper_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span>
<span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">method</span> <span class="special">=</span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">);</span>
</pre>
<p>
Returns an upper bound on the success fraction:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">trials</span></dt>
<dd><p>
The total number of trials conducted.
</p></dd>
<dt><span class="term">successes</span></dt>
<dd><p>
The number of successes that occurred.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The largest acceptable probability that the true value of the success
fraction is <span class="bold"><strong>greater than</strong></span> the value
returned.
</p></dd>
<dt><span class="term">method</span></dt>
<dd><p>
An optional parameter that specifies the method to be used to compute
the interval. Refer to the documentation for <code class="computeroutput"><span class="identifier">find_upper_bound_on_p</span></code>
above for the meaning of the method options.
</p></dd>
</dl>
</div>
<p>
For example, if you observe <span class="emphasis"><em>k</em></span> successes from <span class="emphasis"><em>n</em></span>
trials the best estimate for the success fraction is simply <span class="emphasis"><em>k/n</em></span>,
but if you want to be 95% sure that the true value is <span class="bold"><strong>less
than</strong></span> some value, <span class="emphasis"><em>p<sub>max</sub></em></span>, then:
</p>
<pre class="programlisting"><span class="identifier">p</span><sub>max</sub> <span class="special">=</span> <span class="identifier">binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_upper_bound_on_p</span><span class="special">(</span>
<span class="identifier">n</span><span class="special">,</span> <span class="identifier">k</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
<a class="link" href="../../stat_tut/weg/binom_eg/binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for a Binomial Distribution">See worked
example.</a>
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
In order to obtain a two sided bound on the success fraction, you call
both <code class="computeroutput"><span class="identifier">find_lower_bound_on_p</span></code>
<span class="bold"><strong>and</strong></span> <code class="computeroutput"><span class="identifier">find_upper_bound_on_p</span></code>
each with the same arguments.
</p>
<p>
If the desired risk level that the true success fraction lies outside
the bounds is &#945;, then you pass &#945;/2 to these functions.
</p>
<p>
So for example a two sided 95% confidence interval would be obtained
by passing &#945; = 0.025 to each of the functions.
</p>
<p>
<a class="link" href="../../stat_tut/weg/binom_eg/binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for a Binomial Distribution">See worked
example.</a>
</p>
</td></tr>
</table></div>
<h6>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.estimating_the_number_of_trials_"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.estimating_the_number_of_trials_">Estimating
the Number of Trials Required for a Certain Number of Successes</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of events</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// probability threshold</span>
</pre>
<p>
This function estimates the minimum number of trials required to ensure
that more than k events is observed with a level of risk <span class="emphasis"><em>alpha</em></span>
that k or fewer events occur.
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">k</span></dt>
<dd><p>
The number of success observed.
</p></dd>
<dt><span class="term">p</span></dt>
<dd><p>
The probability of success for each trial.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The maximum acceptable probability that k events or fewer will be
observed.
</p></dd>
</dl>
</div>
<p>
For example:
</p>
<pre class="programlisting"><span class="identifier">binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_number_of_trials</span><span class="special">(</span><span class="number">10</span><span class="special">,</span> <span class="number">0.5</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
Returns the smallest number of trials we must conduct to be 95% sure of
seeing 10 events that occur with frequency one half.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h6"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.estimating_the_maximum_number_of"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.estimating_the_maximum_number_of">Estimating
the Maximum Number of Trials to Ensure no more than a Certain Number of
Successes</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of events</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// probability threshold</span>
</pre>
<p>
This function estimates the maximum number of trials we can conduct to
ensure that k successes or fewer are observed, with a risk <span class="emphasis"><em>alpha</em></span>
that more than k occur.
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">k</span></dt>
<dd><p>
The number of success observed.
</p></dd>
<dt><span class="term">p</span></dt>
<dd><p>
The probability of success for each trial.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The maximum acceptable probability that more than k events will be
observed.
</p></dd>
</dl>
</div>
<p>
For example:
</p>
<pre class="programlisting"><span class="identifier">binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span><span class="number">0</span><span class="special">,</span> <span class="number">1e-6</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
Returns the largest number of trials we can conduct and still be 95% certain
of not observing any events that occur with one in a million frequency.
This is typically used in failure analysis.
</p>
<p>
<a class="link" href="../../stat_tut/weg/binom_eg/binom_size_eg.html" title="Estimating Sample Sizes for a Binomial Distribution.">See Worked
Example.</a>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h7"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.non_member_accessors"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain for the random variable <span class="emphasis"><em>k</em></span> is <code class="computeroutput"><span class="number">0</span> <span class="special">&lt;=</span> <span class="identifier">k</span> <span class="special">&lt;=</span> <span class="identifier">N</span></code>, otherwise a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
is returned.
</p>
<p>
It's worth taking a moment to define what these accessors actually mean
in the context of this distribution:
</p>
<div class="table">
<a name="math_toolkit.dist_ref.dists.binomial_dist.meaning_of_the_non_member_access"></a><p class="title"><b>Table&#160;5.1.&#160;Meaning of the non-member accessors</b></p>
<div class="table-contents"><table class="table" summary="Meaning of the non-member accessors">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Function
</p>
</th>
<th>
<p>
Meaning
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density
Function</a>
</p>
</td>
<td>
<p>
The probability of obtaining <span class="bold"><strong>exactly k
successes</strong></span> from n trials with success fraction p. For
example:
</p>
<p>
<code class="computeroutput"><span class="identifier">pdf</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span>
<span class="identifier">p</span><span class="special">),</span>
<span class="identifier">k</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution
Function</a>
</p>
</td>
<td>
<p>
The probability of obtaining <span class="bold"><strong>k successes
or fewer</strong></span> from n trials with success fraction p. For
example:
</p>
<p>
<code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span>
<span class="identifier">p</span><span class="special">),</span>
<span class="identifier">k</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.ccdf">Complement of
the Cumulative Distribution Function</a>
</p>
</td>
<td>
<p>
The probability of obtaining <span class="bold"><strong>more than
k successes</strong></span> from n trials with success fraction p.
For example:
</p>
<p>
<code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span>
<span class="identifier">p</span><span class="special">),</span>
<span class="identifier">k</span><span class="special">))</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>
</p>
</td>
<td>
<p>
The <span class="bold"><strong>greatest</strong></span> number of successes
that may be observed from n trials with success fraction p, at
probability P. Note that the value returned is a real-number,
and not an integer. Depending on the use case you may want to
take either the floor or ceiling of the result. For example:
</p>
<p>
<code class="computeroutput"><span class="identifier">quantile</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span>
<span class="identifier">p</span><span class="special">),</span>
<span class="identifier">P</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile_c">Quantile
from the complement of the probability</a>
</p>
</td>
<td>
<p>
The <span class="bold"><strong>smallest</strong></span> number of successes
that may be observed from n trials with success fraction p, at
probability P. Note that the value returned is a real-number,
and not an integer. Depending on the use case you may want to
take either the floor or ceiling of the result. For example:
</p>
<p>
<code class="computeroutput"><span class="identifier">quantile</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span>
<span class="identifier">p</span><span class="special">),</span>
<span class="identifier">P</span><span class="special">))</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><h5>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h8"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.examples"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.examples">Examples</a>
</h5>
<p>
Various <a class="link" href="../../stat_tut/weg/binom_eg.html" title="Binomial Distribution Examples">worked examples</a>
are available illustrating the use of the binomial distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h9"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.accuracy"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.accuracy">Accuracy</a>
</h5>
<p>
This distribution is implemented using the incomplete beta functions <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a> and <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>,
please refer to these functions for information on accuracy.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h10"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.implementation"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.implementation">Implementation</a>
</h5>
<p>
In the following table <span class="emphasis"><em>p</em></span> is the probability that one
trial will be successful (the success fraction), <span class="emphasis"><em>n</em></span>
is the number of trials, <span class="emphasis"><em>k</em></span> is the number of successes,
<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>
Implementation is in terms of <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>:
if <sub>n</sub>C<sub>k </sub> is the binomial coefficient of a and b, then we have:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/binomial_ref1.svg"></span>
</p>
<p>
Which can be evaluated as <code class="computeroutput"><span class="identifier">ibeta_derivative</span><span class="special">(</span><span class="identifier">k</span><span class="special">+</span><span class="number">1</span><span class="special">,</span> <span class="identifier">n</span><span class="special">-</span><span class="identifier">k</span><span class="special">+</span><span class="number">1</span><span class="special">,</span> <span class="identifier">p</span><span class="special">)</span> <span class="special">/</span>
<span class="special">(</span><span class="identifier">n</span><span class="special">+</span><span class="number">1</span><span class="special">)</span></code>
</p>
<p>
The function <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>
is used here, since it has already been optimised for the lowest
possible error - indeed this is really just a thin wrapper around
part of the internals of the incomplete beta function.
</p>
<p>
There are also various special cases: refer to the code for details.
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation:
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">p</span> <span class="special">=</span> <span class="identifier">I</span><span class="special">[</span><span class="identifier">sub</span> <span class="number">1</span><span class="special">-</span><span class="identifier">p</span><span class="special">](</span><span class="identifier">n</span> <span class="special">-</span> <span class="identifier">k</span><span class="special">,</span> <span class="identifier">k</span> <span class="special">+</span> <span class="number">1</span><span class="special">)</span>
<span class="special">=</span> <span class="number">1</span> <span class="special">-</span> <span class="identifier">I</span><span class="special">[</span><span class="identifier">sub</span> <span class="identifier">p</span><span class="special">](</span><span class="identifier">k</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">n</span> <span class="special">-</span> <span class="identifier">k</span><span class="special">)</span>
<span class="special">=</span> <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a><span class="special">(</span><span class="identifier">k</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">n</span> <span class="special">-</span> <span class="identifier">k</span><span class="special">,</span> <span class="identifier">p</span><span class="special">)</span></pre>
<p>
There are also various special cases: refer to the code for details.
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(k
+ 1, n - k, p)
</p>
<p>
There are also various special cases: refer to the code for details.
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Since the cdf is non-linear in variate <span class="emphasis"><em>k</em></span>
none of the inverse incomplete beta functions can be used here.
Instead the quantile is found numerically using a derivative
free method (<a class="link" href="../../roots_noderiv/TOMS748.html" title="Algorithm TOMS 748: Alefeld, Potra and Shi: Enclosing zeros of continuous functions">TOMS
748 algorithm</a>).
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Found numerically as above.
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">p</span> <span class="special">*</span>
<span class="identifier">n</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">p</span> <span class="special">*</span>
<span class="identifier">n</span> <span class="special">*</span>
<span class="special">(</span><span class="number">1</span><span class="special">-</span><span class="identifier">p</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">floor</span><span class="special">(</span><span class="identifier">p</span> <span class="special">*</span>
<span class="special">(</span><span class="identifier">n</span>
<span class="special">+</span> <span class="number">1</span><span class="special">))</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">(</span><span class="number">1</span>
<span class="special">-</span> <span class="number">2</span>
<span class="special">*</span> <span class="identifier">p</span><span class="special">)</span> <span class="special">/</span>
<span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">n</span> <span class="special">*</span>
<span class="identifier">p</span> <span class="special">*</span>
<span class="special">(</span><span class="number">1</span>
<span class="special">-</span> <span class="identifier">p</span><span class="special">))</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="number">3</span> <span class="special">-</span>
<span class="special">(</span><span class="number">6</span>
<span class="special">/</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">+</span>
<span class="special">(</span><span class="number">1</span>
<span class="special">/</span> <span class="special">(</span><span class="identifier">n</span> <span class="special">*</span>
<span class="identifier">p</span> <span class="special">*</span>
<span class="special">(</span><span class="number">1</span>
<span class="special">-</span> <span class="identifier">p</span><span class="special">)))</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">(</span><span class="number">1</span>
<span class="special">-</span> <span class="number">6</span>
<span class="special">*</span> <span class="identifier">p</span>
<span class="special">*</span> <span class="identifier">q</span><span class="special">)</span> <span class="special">/</span>
<span class="special">(</span><span class="identifier">n</span>
<span class="special">*</span> <span class="identifier">p</span>
<span class="special">*</span> <span class="identifier">q</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
parameter estimation
</p>
</td>
<td>
<p>
The member functions <code class="computeroutput"><span class="identifier">find_upper_bound_on_p</span></code>
<code class="computeroutput"><span class="identifier">find_lower_bound_on_p</span></code>
and <code class="computeroutput"><span class="identifier">find_number_of_trials</span></code>
are implemented in terms of the inverse incomplete beta functions
<a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibetac_inv</a>,
<a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>,
and <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibetac_invb</a>
respectively
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.binomial_dist.h11"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.references"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://mathworld.wolfram.com/BinomialDistribution.html" target="_top">Weisstein,
Eric W. "Binomial Distribution." From MathWorld--A Wolfram
Web Resource</a>.
</li>
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Beta_distribution" target="_top">Wikipedia
binomial distribution</a>.
</li>
<li class="listitem">
<a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda366i.htm" target="_top">NIST
Explorary Data Analysis</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="beta_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="cauchy_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,306 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Cauchy-Lorentz Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="binomial_dist.html" title="Binomial Distribution">
<link rel="next" href="chi_squared_dist.html" title="Chi Squared 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="binomial_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="chi_squared_dist.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.dist_ref.dists.cauchy_dist"></a><a class="link" href="cauchy_dist.html" title="Cauchy-Lorentz Distribution">Cauchy-Lorentz
Distribution</a>
</h4></div></div></div>
<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">cauchy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<pre class="programlisting"><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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">cauchy_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">cauchy_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">cauchy</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">cauchy_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">cauchy_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
<span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
The <a href="http://en.wikipedia.org/wiki/Cauchy_distribution" target="_top">Cauchy-Lorentz
distribution</a> is named after Augustin Cauchy and Hendrik Lorentz.
It is a <a href="http://en.wikipedia.org/wiki/Probability_distribution" target="_top">continuous
probability distribution</a> with <a href="http://en.wikipedia.org/wiki/Probability_distribution" target="_top">probability
distribution function PDF</a> given by:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/cauchy_ref1.svg"></span>
</p>
<p>
The location parameter x<sub>0</sub> &#160; is the location of the peak of the distribution
(the mode of the distribution), while the scale parameter &#947; &#160; specifies half
the width of the PDF at half the maximum height. If the location is zero,
and the scale 1, then the result is a standard Cauchy distribution.
</p>
<p>
The distribution is important in physics as it is the solution to the differential
equation describing forced resonance, while in spectroscopy it is the description
of the line shape of spectral lines.
</p>
<p>
The following graph shows how the distributions moves as the location parameter
changes:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/cauchy_pdf1.svg" align="middle"></span>
</p>
<p>
While the following graph shows how the shape (scale) parameter alters
the distribution:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/cauchy_pdf2.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.cauchy_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.cauchy_dist.member_functions"></a></span><a class="link" href="cauchy_dist.html#math_toolkit.dist_ref.dists.cauchy_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">cauchy_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
Constructs a Cauchy distribution, with location parameter <span class="emphasis"><em>location</em></span>
and scale parameter <span class="emphasis"><em>scale</em></span>. When these parameters take
their default values (location = 0, scale = 1) then the result is a Standard
Cauchy Distribution.
</p>
<p>
Requires scale &gt; 0, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the location parameter of the distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the scale parameter of the distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.cauchy_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.cauchy_dist.non_member_accessors"></a></span><a class="link" href="cauchy_dist.html#math_toolkit.dist_ref.dists.cauchy_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
Note however that the Cauchy distribution does not have a mean, standard
deviation, etc. See <a class="link" href="../../pol_ref/assert_undefined.html" title="Mathematically Undefined Function Policies">mathematically
undefined function</a> to control whether these should fail to compile
with a BOOST_STATIC_ASSERTION_FAILURE, which is the default.
</p>
<p>
Alternately, the functions <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.sd">standard deviation</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>, <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>
and <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>
will all return a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
if called.
</p>
<p>
The domain of the random variable is [-[max_value], +[min_value]].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.cauchy_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.cauchy_dist.accuracy"></a></span><a class="link" href="cauchy_dist.html#math_toolkit.dist_ref.dists.cauchy_dist.accuracy">Accuracy</a>
</h5>
<p>
The Cauchy distribution is implemented in terms of the standard library
<code class="computeroutput"><span class="identifier">tan</span></code> and <code class="computeroutput"><span class="identifier">atan</span></code>
functions, and as such should have very low error rates.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.cauchy_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.cauchy_dist.implementation"></a></span><a class="link" href="cauchy_dist.html#math_toolkit.dist_ref.dists.cauchy_dist.implementation">Implementation</a>
</h5>
<p>
In the following table x<sub>0 </sub> is the location parameter of the distribution,
&#947; &#160; is its scale 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 = 1 / (&#960; * &#947; * (1 + ((x - x<sub>0 </sub>) / &#947;)<sup>2</sup>)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf and its complement
</p>
</td>
<td>
<p>
The cdf is normally given by:
</p>
<p>
p = 0.5 + atan(x)/&#960;
</p>
<p>
But that suffers from cancellation error as x -&gt; -&#8734;. So recall
that for <code class="computeroutput"><span class="identifier">x</span> <span class="special">&lt;</span>
<span class="number">0</span></code>:
</p>
<p>
atan(x) = -&#960;/2 - atan(1/x)
</p>
<p>
Substituting into the above we get:
</p>
<p>
p = -atan(1/x) ; x &lt; 0
</p>
<p>
So the procedure is to calculate the cdf for -fabs(x) using the
above formula. Note that to factor in the location and scale
parameters you must substitute (x - x<sub>0 </sub>) / &#947; &#160; for x in the above.
</p>
<p>
This procedure yields the smaller of <span class="emphasis"><em>p</em></span> and
<span class="emphasis"><em>q</em></span>, so the result may need subtracting from
1 depending on whether we want the complement or not, and whether
<span class="emphasis"><em>x</em></span> is less than x<sub>0 </sub> or not.
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
The same procedure is used irrespective of whether we're starting
from the probability or its complement. First the argument <span class="emphasis"><em>p</em></span>
is reduced to the range [-0.5, 0.5], then the relation
</p>
<p>
x = x<sub>0 </sub> &#177; &#947; &#160; / tan(&#960; * p)
</p>
<p>
is used to obtain the result. Whether we're adding or subtracting
from x<sub>0 </sub> is determined by whether we're starting from the complement
or not.
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
The location parameter.
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.cauchy_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.cauchy_dist.references"></a></span><a class="link" href="cauchy_dist.html#math_toolkit.dist_ref.dists.cauchy_dist.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Cauchy_distribution" target="_top">Cauchy-Lorentz
distribution</a>
</li>
<li class="listitem">
<a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm" target="_top">NIST
Exploratory Data Analysis</a>
</li>
<li class="listitem">
<a href="http://mathworld.wolfram.com/CauchyDistribution.html" target="_top">Weisstein,
Eric W. "Cauchy Distribution." From MathWorld--A Wolfram
Web Resource.</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="binomial_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="chi_squared_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,412 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chi Squared Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="cauchy_dist.html" title="Cauchy-Lorentz Distribution">
<link rel="next" href="exp_dist.html" title="Exponential 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="cauchy_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="exp_dist.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.dist_ref.dists.chi_squared_dist"></a><a class="link" href="chi_squared_dist.html" title="Chi Squared Distribution">Chi Squared
Distribution</a>
</h4></div></div></div>
<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">chi_squared</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">chi_squared_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">chi_squared_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">chi_squared</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">chi_squared_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="comment">// Constructor:</span>
<span class="identifier">chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">i</span><span class="special">);</span>
<span class="comment">// Accessor to parameter:</span>
<span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Parameter estimation:</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">difference_from_mean</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">sd</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">hint</span> <span class="special">=</span> <span class="number">100</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The Chi-Squared distribution is one of the most widely used distributions
in statistical tests. If &#967;<sub>i</sub> &#160; are &#957; &#160;
independent, normally distributed random
variables with means &#956;<sub>i</sub> &#160; and variances &#963;<sub>i</sub><sup>2</sup>, then the random variable:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/chi_squ_ref1.svg"></span>
</p>
<p>
is distributed according to the Chi-Squared distribution.
</p>
<p>
The Chi-Squared distribution is a special case of the gamma distribution
and has a single parameter &#957; &#160; that specifies the number of degrees of freedom.
The following graph illustrates how the distribution changes for different
values of &#957;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/chi_squared_pdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.chi_squared_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.chi_squared_dist.member_functions"></a></span><a class="link" href="chi_squared_dist.html#math_toolkit.dist_ref.dists.chi_squared_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v</span><span class="special">);</span>
</pre>
<p>
Constructs a Chi-Squared distribution with <span class="emphasis"><em>v</em></span> degrees
of freedom.
</p>
<p>
Requires v &gt; 0, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>v</em></span> from which this object was
constructed.
</p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">difference_from_variance</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">variance</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">hint</span> <span class="special">=</span> <span class="number">100</span><span class="special">);</span>
</pre>
<p>
Estimates the sample size required to detect a difference from a nominal
variance in a Chi-Squared test for equal standard deviations.
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">difference_from_variance</span></dt>
<dd><p>
The difference from the assumed nominal variance that is to be detected:
Note that the sign of this value is critical, see below.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The maximum acceptable risk of rejecting the null hypothesis when
it is in fact true.
</p></dd>
<dt><span class="term">beta</span></dt>
<dd><p>
The maximum acceptable risk of falsely failing to reject the null
hypothesis.
</p></dd>
<dt><span class="term">variance</span></dt>
<dd><p>
The nominal variance being tested against.
</p></dd>
<dt><span class="term">hint</span></dt>
<dd><p>
An optional hint on where to start looking for a result: the current
sample size would be a good choice.
</p></dd>
</dl>
</div>
<p>
Note that this calculation works with <span class="emphasis"><em>variances</em></span> and
not <span class="emphasis"><em>standard deviations</em></span>.
</p>
<p>
The sign of the parameter <span class="emphasis"><em>difference_from_variance</em></span>
is important: the Chi Squared distribution is asymmetric, and the caller
must decide in advance whether they are testing for a variance greater
than a nominal value (positive <span class="emphasis"><em>difference_from_variance</em></span>)
or testing for a variance less than a nominal value (negative <span class="emphasis"><em>difference_from_variance</em></span>).
If the latter, then obviously it is a requirement that <code class="computeroutput"><span class="identifier">variance</span>
<span class="special">+</span> <span class="identifier">difference_from_variance</span>
<span class="special">&gt;</span> <span class="number">0</span></code>,
since no sample can have a negative variance!
</p>
<p>
This procedure uses the method in Diamond, W. J. (1989). Practical Experiment
Designs, Van-Nostrand Reinhold, New York.
</p>
<p>
See also section on Sample sizes required in <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc232.htm" target="_top">the
NIST Engineering Statistics Handbook, Section 7.2.3.2</a>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.chi_squared_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.chi_squared_dist.non_member_accessors"></a></span><a class="link" href="chi_squared_dist.html#math_toolkit.dist_ref.dists.chi_squared_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
(We have followed the usual restriction of the mode to degrees of freedom
&gt;= 2, but note that the maximum of the pdf is actually zero for degrees
of freedom from 2 down to 0, and provide an extended definition that would
avoid a discontinuity in the mode as alternative code in a comment).
</p>
<p>
The domain of the random variable is [0, +&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.chi_squared_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.chi_squared_dist.examples"></a></span><a class="link" href="chi_squared_dist.html#math_toolkit.dist_ref.dists.chi_squared_dist.examples">Examples</a>
</h5>
<p>
Various <a class="link" href="../../stat_tut/weg/cs_eg.html" title="Chi Squared Distribution Examples">worked examples</a>
are available illustrating the use of the Chi Squared Distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.chi_squared_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.chi_squared_dist.accuracy"></a></span><a class="link" href="chi_squared_dist.html#math_toolkit.dist_ref.dists.chi_squared_dist.accuracy">Accuracy</a>
</h5>
<p>
The Chi-Squared distribution is implemented in terms of the <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">incomplete
gamma functions</a>: please refer to the accuracy data for those functions.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.chi_squared_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.chi_squared_dist.implementation"></a></span><a class="link" href="chi_squared_dist.html#math_toolkit.dist_ref.dists.chi_squared_dist.implementation">Implementation</a>
</h5>
<p>
In the following table <span class="emphasis"><em>v</em></span> is the number of degrees
of freedom of the distribution, <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 = <a class="link" href="../../sf_gamma/gamma_derivatives.html" title="Derivative of the Incomplete Gamma Function">gamma_p_derivative</a>(v
/ 2, x / 2) / 2
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>(v
/ 2, x / 2)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a>(v
/ 2, x / 2)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = 2 * <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>(v
/ 2, p)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = 2 * <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>(v
/ 2, p)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
v
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
2v
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
v - 2 (if v &gt;= 2)
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
2 * sqrt(2 / v) == sqrt(8 / v)
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
3 + 12 / v
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
12 / v
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.chi_squared_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.chi_squared_dist.references"></a></span><a class="link" href="chi_squared_dist.html#math_toolkit.dist_ref.dists.chi_squared_dist.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm" target="_top">NIST
Exploratory Data Analysis</a>
</li>
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Chi-square_distribution" target="_top">Chi-square
distribution</a>
</li>
<li class="listitem">
<a href="http://mathworld.wolfram.com/Chi-SquaredDistribution.html" target="_top">Weisstein,
Eric W. "Chi-Squared Distribution." From MathWorld--A Wolfram
Web Resource.</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="cauchy_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="exp_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,329 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Exponential Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="chi_squared_dist.html" title="Chi Squared Distribution">
<link rel="next" href="extreme_dist.html" title="Extreme Value 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="chi_squared_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="extreme_dist.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.dist_ref.dists.exp_dist"></a><a class="link" href="exp_dist.html" title="Exponential Distribution">Exponential Distribution</a>
</h4></div></div></div>
<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">exponential</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<pre class="programlisting"><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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">exponential_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">exponential_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">exponential</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">exponential_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">exponential_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lambda</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
<span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
The <a href="http://en.wikipedia.org/wiki/Exponential_distribution" target="_top">exponential
distribution</a> is a <a href="http://en.wikipedia.org/wiki/Probability_distribution" target="_top">continuous
probability distribution</a> with PDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/exponential_dist_ref1.svg"></span>
</p>
<p>
It is often used to model the time between independent events that happen
at a constant average rate.
</p>
<p>
The following graph shows how the distribution changes for different values
of the rate parameter lambda:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/exponential_pdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.exp_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.exp_dist.member_functions"></a></span><a class="link" href="exp_dist.html#math_toolkit.dist_ref.dists.exp_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">exponential_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lambda</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
Constructs an <a href="http://en.wikipedia.org/wiki/Exponential_distribution" target="_top">Exponential
distribution</a> with parameter <span class="emphasis"><em>lambda</em></span>. Lambda
is defined as the reciprocal of the scale parameter.
</p>
<p>
Requires lambda &gt; 0, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Accessor function returns the lambda parameter of the distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.exp_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.exp_dist.non_member_accessors"></a></span><a class="link" href="exp_dist.html#math_toolkit.dist_ref.dists.exp_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [0, +&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.exp_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.exp_dist.accuracy"></a></span><a class="link" href="exp_dist.html#math_toolkit.dist_ref.dists.exp_dist.accuracy">Accuracy</a>
</h5>
<p>
The exponential distribution is implemented in terms of the standard library
functions <code class="computeroutput"><span class="identifier">exp</span></code>, <code class="computeroutput"><span class="identifier">log</span></code>, <code class="computeroutput"><span class="identifier">log1p</span></code>
and <code class="computeroutput"><span class="identifier">expm1</span></code> and as such should
have very low error rates.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.exp_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.exp_dist.implementation"></a></span><a class="link" href="exp_dist.html#math_toolkit.dist_ref.dists.exp_dist.implementation">Implementation</a>
</h5>
<p>
In the following table &#955; is the parameter lambda of the distribution, <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 = &#955; * exp(-&#955; * x)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = 1 - exp(-x * &#955;) = -expm1(-x * &#955;)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = exp(-x * &#955;)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = -log(1-p) / &#955; = -log1p(-p) / &#955;
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = -log(q) / &#955;
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
1/&#955;
</p>
</td>
</tr>
<tr>
<td>
<p>
standard deviation
</p>
</td>
<td>
<p>
1/&#955;
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
2
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
9
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
6
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.exp_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.exp_dist.references"></a></span><a class="link" href="exp_dist.html#math_toolkit.dist_ref.dists.exp_dist.references">references</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://mathworld.wolfram.com/ExponentialDistribution.html" target="_top">Weisstein,
Eric W. "Exponential Distribution." From MathWorld--A Wolfram
Web Resource</a>
</li>
<li class="listitem">
<a href="http://documents.wolfram.com/calccenter/Functions/ListsMatrices/Statistics/ExponentialDistribution.html" target="_top">Wolfram
Mathematica calculator</a>
</li>
<li class="listitem">
<a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda3667.htm" target="_top">NIST
Exploratory Data Analysis</a>
</li>
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Exponential_distribution" target="_top">Wikipedia
Exponential distribution</a>
</li>
</ul></div>
<p>
(See also the reference documentation for the related <a class="link" href="extreme_dist.html" title="Extreme Value Distribution">Extreme
Distributions</a>.)
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<a href="http://www.worldscibooks.com/mathematics/p191.html" target="_top">Extreme
Value Distributions, Theory and Applications Samuel Kotz &amp; Saralees
Nadarajah</a> discuss the relationship of the types of extreme
value distributions.
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="chi_squared_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="extreme_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,332 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Extreme Value Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="exp_dist.html" title="Exponential Distribution">
<link rel="next" href="f_dist.html" title="F 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="exp_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="f_dist.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.dist_ref.dists.extreme_dist"></a><a class="link" href="extreme_dist.html" title="Extreme Value Distribution">Extreme Value
Distribution</a>
</h4></div></div></div>
<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">extreme</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<pre class="programlisting"><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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">extreme_value_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">extreme_value_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">extreme_value</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">extreme_value_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="identifier">extreme_value_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
There are various <a href="http://mathworld.wolfram.com/ExtremeValueDistribution.html" target="_top">extreme
value distributions</a> : this implementation represents the maximum
case, and is variously known as a Fisher-Tippett distribution, a log-Weibull
distribution or a Gumbel distribution.
</p>
<p>
Extreme value theory is important for assessing risk for highly unusual
events, such as 100-year floods.
</p>
<p>
More information can be found on the <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda366g.htm" target="_top">NIST</a>,
<a href="http://en.wikipedia.org/wiki/Extreme_value_distribution" target="_top">Wikipedia</a>,
<a href="http://mathworld.wolfram.com/ExtremeValueDistribution.html" target="_top">Mathworld</a>,
and <a href="http://en.wikipedia.org/wiki/Extreme_value_theory" target="_top">Extreme
value theory</a> websites.
</p>
<p>
The relationship of the types of extreme value distributions, of which
this is but one, is discussed by <a href="http://www.worldscibooks.com/mathematics/p191.html" target="_top">Extreme
Value Distributions, Theory and Applications Samuel Kotz &amp; Saralees
Nadarajah</a>.
</p>
<p>
The distribution has a PDF given by:
</p>
<p>
f(x) = (1/scale) e<sup>-(x-location)/scale</sup> e<sup>-e<sup>-(x-location)/scale</sup></sup>
</p>
<p>
Which in the standard case (scale = 1, location = 0) reduces to:
</p>
<p>
f(x) = e<sup>-x</sup>e<sup>-e<sup>-x</sup></sup>
</p>
<p>
The following graph illustrates how the PDF varies with the location parameter:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/extreme_value_pdf1.svg" align="middle"></span>
</p>
<p>
And this graph illustrates how the PDF varies with the shape parameter:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/extreme_value_pdf2.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.extreme_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.extreme_dist.member_functions"></a></span><a class="link" href="extreme_dist.html#math_toolkit.dist_ref.dists.extreme_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">extreme_value_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
Constructs an Extreme Value distribution with the specified location and
scale parameters.
</p>
<p>
Requires <code class="computeroutput"><span class="identifier">scale</span> <span class="special">&gt;</span>
<span class="number">0</span></code>, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the location parameter of the distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the scale parameter of the distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.extreme_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.extreme_dist.non_member_accessors"></a></span><a class="link" href="extreme_dist.html#math_toolkit.dist_ref.dists.extreme_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random parameter is [-&#8734;, +&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.extreme_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.extreme_dist.accuracy"></a></span><a class="link" href="extreme_dist.html#math_toolkit.dist_ref.dists.extreme_dist.accuracy">Accuracy</a>
</h5>
<p>
The extreme value distribution is implemented in terms of the standard
library <code class="computeroutput"><span class="identifier">exp</span></code> and <code class="computeroutput"><span class="identifier">log</span></code> functions and as such should have
very low error rates.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.extreme_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.extreme_dist.implementation"></a></span><a class="link" href="extreme_dist.html#math_toolkit.dist_ref.dists.extreme_dist.implementation">Implementation</a>
</h5>
<p>
In the following table: <span class="emphasis"><em>a</em></span> is the location parameter,
<span class="emphasis"><em>b</em></span> is the scale 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 = exp((a-x)/b) * exp(-exp((a-x)/b)) /
b
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = exp(-exp((a-x)/b))
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = -expm1(-exp((a-x)/b))
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: a - log(-log(p)) * b
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: a - log(-log1p(-q)) * b
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
a + <a href="http://en.wikipedia.org/wiki/Euler-Mascheroni_constant" target="_top">Euler-Mascheroni-constant</a>
* b
</p>
</td>
</tr>
<tr>
<td>
<p>
standard deviation
</p>
</td>
<td>
<p>
pi * b / sqrt(6)
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
The same as the location parameter <span class="emphasis"><em>a</em></span>.
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
12 * sqrt(6) * zeta(3) / pi<sup>3</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
27 / 5
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
kurtosis - 3 or 12 / 5
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="exp_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="f_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,435 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>F Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="extreme_dist.html" title="Extreme Value Distribution">
<link rel="next" href="gamma_dist.html" title="Gamma (and Erlang) 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="extreme_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="gamma_dist.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.dist_ref.dists.f_dist"></a><a class="link" href="f_dist.html" title="F Distribution">F Distribution</a>
</h4></div></div></div>
<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">fisher_f</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">fisher_f_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">fisher_f_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">fisher_f</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">fisher_f_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="comment">// Construct:</span>
<span class="identifier">fisher_f_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&amp;</span> <span class="identifier">i</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&amp;</span> <span class="identifier">j</span><span class="special">);</span>
<span class="comment">// Accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom1</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom2</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">//namespaces</span>
</pre>
<p>
The F distribution is a continuous distribution that arises when testing
whether two samples have the same variance. If &#967;<sup>2</sup><sub>m</sub> &#160; and &#967;<sup>2</sup><sub>n</sub> &#160; are independent
variates each distributed as Chi-Squared with <span class="emphasis"><em>m</em></span> and
<span class="emphasis"><em>n</em></span> degrees of freedom, then the test statistic:
</p>
<p>
F<sub>n,m</sub> &#160; = (&#967;<sup>2</sup><sub>n</sub> &#160; / n) / (&#967;<sup>2</sup><sub>m</sub> &#160; / m)
</p>
<p>
Is distributed over the range [0, &#8734;] with an F distribution, and has the
PDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/fisher_pdf.svg"></span>
</p>
<p>
The following graph illustrates how the PDF varies depending on the two
degrees of freedom parameters.
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/fisher_f_pdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.f_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.member_functions"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_dist.member_functions">Member Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">fisher_f_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&amp;</span> <span class="identifier">df1</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&amp;</span> <span class="identifier">df2</span><span class="special">);</span>
</pre>
<p>
Constructs an F-distribution with numerator degrees of freedom <span class="emphasis"><em>df1</em></span>
and denominator degrees of freedom <span class="emphasis"><em>df2</em></span>.
</p>
<p>
Requires that <span class="emphasis"><em>df1</em></span> and <span class="emphasis"><em>df2</em></span> are
both greater than zero, otherwise <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
is called.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom1</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the numerator degrees of freedom parameter of the distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom2</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the denominator degrees of freedom parameter of the distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.f_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.non_member_accessors"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [0, +&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.f_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.examples"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_dist.examples">Examples</a>
</h5>
<p>
Various <a class="link" href="../../stat_tut/weg/f_eg.html" title="F Distribution Examples">worked examples</a>
are available illustrating the use of the F Distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.f_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.accuracy"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_dist.accuracy">Accuracy</a>
</h5>
<p>
The normal distribution is implemented in terms of the <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">incomplete
beta function</a> and its <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">inverses</a>,
refer to those functions for accuracy data.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.f_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.implementation"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_dist.implementation">Implementation</a>
</h5>
<p>
In the following table <span class="emphasis"><em>v1</em></span> and <span class="emphasis"><em>v2</em></span>
are the first and second degrees of freedom parameters of the distribution,
<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>
The usual form of the PDF is given by:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/fisher_pdf.svg"></span>
</p>
<p>
However, that form is hard to evaluate directly without incurring
problems with either accuracy or numeric overflow.
</p>
<p>
Direct differentiation of the CDF expressed in terms of the incomplete
beta function
</p>
<p>
led to the following two formulas:
</p>
<p>
f<sub>v1,v2</sub>(x) = y * <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>(v2
/ 2, v1 / 2, v2 / (v2 + v1 * x))
</p>
<p>
with y = (v2 * v1) / ((v2 + v1 * x) * (v2 + v1 * x))
</p>
<p>
and
</p>
<p>
f<sub>v1,v2</sub>(x) = y * <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>(v1
/ 2, v2 / 2, v1 * x / (v2 + v1 * x))
</p>
<p>
with y = (z * v1 - x * v1 * v1) / z<sup>2</sup>
</p>
<p>
and z = v2 + v1 * x
</p>
<p>
The first of these is used for v1 * x &gt; v2, otherwise the
second is used.
</p>
<p>
The aim is to keep the <span class="emphasis"><em>x</em></span> argument to <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>
away from 1 to avoid rounding error.
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relations:
</p>
<p>
p = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(v1
/ 2, v2 / 2, v1 * x / (v2 + v1 * x))
</p>
<p>
and
</p>
<p>
p = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>(v2
/ 2, v1 / 2, v2 / (v2 + v1 * x))
</p>
<p>
The first is used for v1 * x &gt; v2, otherwise the second is
used.
</p>
<p>
The aim is to keep the <span class="emphasis"><em>x</em></span> argument to <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a> well
away from 1 to avoid rounding error.
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relations:
</p>
<p>
p = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>(v1
/ 2, v2 / 2, v1 * x / (v2 + v1 * x))
</p>
<p>
and
</p>
<p>
p = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(v2
/ 2, v1 / 2, v2 / (v2 + v1 * x))
</p>
<p>
The first is used for v1 * x &lt; v2, otherwise the second is
used.
</p>
<p>
The aim is to keep the <span class="emphasis"><em>x</em></span> argument to <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a> well
away from 1 to avoid rounding error.
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
x = v2 * a / (v1 * b)
</p>
<p>
where:
</p>
<p>
a = <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>(v1
/ 2, v2 / 2, p)
</p>
<p>
and
</p>
<p>
b = 1 - a
</p>
<p>
Quantities <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span>
are both computed by <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>
without the subtraction implied above.
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
<p>
from the complement
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
x = v2 * a / (v1 * b)
</p>
<p>
where
</p>
<p>
a = <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibetac_inv</a>(v1
/ 2, v2 / 2, p)
</p>
<p>
and
</p>
<p>
b = 1 - a
</p>
<p>
Quantities <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span>
are both computed by <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibetac_inv</a>
without the subtraction implied above.
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
v2 / (v2 - 2)
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
2 * v2<sup>2 </sup> * (v1 + v2 - 2) / (v1 * (v2 - 2) * (v2 - 2) * (v2 - 4))
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
v2 * (v1 - 2) / (v1 * (v2 + 2))
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
2 * (v2 + 2 * v1 - 2) * sqrt((2 * v2 - 8) / (v1 * (v2 + v1 -
2))) / (v2 - 6)
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis and kurtosis excess
</p>
</td>
<td>
<p>
Refer to, <a href="http://mathworld.wolfram.com/F-Distribution.html" target="_top">Weisstein,
Eric W. "F-Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="extreme_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="gamma_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,365 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Gamma (and Erlang) Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="f_dist.html" title="F Distribution">
<link rel="next" href="geometric_dist.html" title="Geometric 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="f_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="geometric_dist.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.dist_ref.dists.gamma_dist"></a><a class="link" href="gamma_dist.html" title="Gamma (and Erlang) Distribution">Gamma (and
Erlang) Distribution</a>
</h4></div></div></div>
<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">gamma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">gamma_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">gamma_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">)</span>
<span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The gamma distribution is a continuous probability distribution. When the
shape parameter is an integer then it is known as the Erlang Distribution.
It is also closely related to the Poisson and Chi Squared Distributions.
</p>
<p>
When the shape parameter has an integer value, the distribution is the
<a href="http://en.wikipedia.org/wiki/Erlang_distribution" target="_top">Erlang distribution</a>.
Since this can be produced by ensuring that the shape parameter has an
integer value &gt; 0, the Erlang distribution is not separately implemented.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
To avoid potential confusion with the gamma functions, this distribution
does not provide the typedef:
</p>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">gamma_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">gamma</span><span class="special">;</span></pre>
<p>
Instead if you want a double precision gamma distribution you can write
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gamma_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">my_gamma</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span></pre>
</td></tr>
</table></div>
<p>
For shape parameter <span class="emphasis"><em>k</em></span> and scale parameter &#952; &#160; it is defined
by the probability density function:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/gamma_dist_ref1.svg"></span>
</p>
<p>
Sometimes an alternative formulation is used: given parameters &#945; &#160;= k and
&#946; &#160;= 1 / &#952;, then the distribution can be defined by the PDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/gamma_dist_ref2.svg"></span>
</p>
<p>
In this form the inverse scale parameter is called a <span class="emphasis"><em>rate parameter</em></span>.
</p>
<p>
Both forms are in common usage: this library uses the first definition
throughout. Therefore to construct a Gamma Distribution from a <span class="emphasis"><em>rate
parameter</em></span>, you should pass the reciprocal of the rate as the
scale parameter.
</p>
<p>
The following two graphs illustrate how the PDF of the gamma distribution
varies as the parameters vary:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/gamma1_pdf.svg" align="middle"></span>
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/gamma2_pdf.svg" align="middle"></span>
</p>
<p>
The <span class="bold"><strong>Erlang Distribution</strong></span> is the same as
the Gamma, but with the shape parameter an integer. It is often expressed
using a <span class="emphasis"><em>rate</em></span> rather than a <span class="emphasis"><em>scale</em></span>
as the second parameter (remember that the rate is the reciprocal of the
scale).
</p>
<p>
Internally the functions used to implement the Gamma Distribution are already
optimised for small-integer arguments, so in general there should be no
great loss of performance from using a Gamma Distribution rather than a
dedicated Erlang Distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.gamma_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.gamma_dist.member_functions"></a></span><a class="link" href="gamma_dist.html#math_toolkit.dist_ref.dists.gamma_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">gamma_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
Constructs a gamma distribution with shape <span class="emphasis"><em>shape</em></span> and
scale <span class="emphasis"><em>scale</em></span>.
</p>
<p>
Requires that the shape and scale parameters are greater than zero, otherwise
calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>shape</em></span> parameter of this distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>scale</em></span> parameter of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.gamma_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.gamma_dist.non_member_accessors"></a></span><a class="link" href="gamma_dist.html#math_toolkit.dist_ref.dists.gamma_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [0,+&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.gamma_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.gamma_dist.accuracy"></a></span><a class="link" href="gamma_dist.html#math_toolkit.dist_ref.dists.gamma_dist.accuracy">Accuracy</a>
</h5>
<p>
The lognormal distribution is implemented in terms of the incomplete gamma
functions <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a> and
<a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a> and their inverses
<a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a> and
<a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>: refer
to the accuracy data for those functions for more information.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.gamma_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.gamma_dist.implementation"></a></span><a class="link" href="gamma_dist.html#math_toolkit.dist_ref.dists.gamma_dist.implementation">Implementation</a>
</h5>
<p>
In the following table <span class="emphasis"><em>k</em></span> is the shape parameter of
the distribution, &#952; &#160; is its scale 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 = <a class="link" href="../../sf_gamma/gamma_derivatives.html" title="Derivative of the Incomplete Gamma Function">gamma_p_derivative</a>(k,
x / &#952;) / &#952;
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>(k,
x / &#952;)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a>(k,
x / &#952;)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = &#952; &#160;* <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>(k,
p)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = &#952; &#160;* <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>(k,
p)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
k&#952;
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
k&#952;<sup>2</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
(k-1)&#952; &#160; for <span class="emphasis"><em>k&gt;1</em></span> otherwise a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
2 / sqrt(k)
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
3 + 6 / k
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
6 / k
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="f_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="geometric_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,842 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Geometric Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="gamma_dist.html" title="Gamma (and Erlang) Distribution">
<link rel="next" href="hyperexponential_dist.html" title="Hyperexponential 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="gamma_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="hyperexponential_dist.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.dist_ref.dists.geometric_dist"></a><a class="link" href="geometric_dist.html" title="Geometric Distribution">Geometric
Distribution</a>
</h4></div></div></div>
<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">geometric</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">geometric_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">geometric_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">geometric</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">geometric_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="comment">// Constructor from success_fraction:</span>
<span class="identifier">geometric_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
<span class="comment">// Parameter accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Bounds on success fraction:</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_lower_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// alpha</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_upper_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// alpha</span>
<span class="comment">// Estimate min/max number of trials:</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// Number of failures.</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// Success fraction.</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// Probability threshold alpha.</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// Number of failures.</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// Success fraction.</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// Probability threshold alpha.</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The class type <code class="computeroutput"><span class="identifier">geometric_distribution</span></code>
represents a <a href="http://en.wikipedia.org/wiki/geometric_distribution" target="_top">geometric
distribution</a>: it is used when there are exactly two mutually exclusive
outcomes of a <a href="http://en.wikipedia.org/wiki/Bernoulli_trial" target="_top">Bernoulli
trial</a>: these outcomes are labelled "success" and "failure".
</p>
<p>
For <a href="http://en.wikipedia.org/wiki/Bernoulli_trial" target="_top">Bernoulli
trials</a> each with success fraction <span class="emphasis"><em>p</em></span>, the geometric
distribution gives the probability of observing <span class="emphasis"><em>k</em></span>
trials (failures, events, occurrences, or arrivals) before the first success.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
For this implementation, the set of trials <span class="bold"><strong>includes
zero</strong></span> (unlike another definition where the set of trials starts
at one, sometimes named <span class="emphasis"><em>shifted</em></span>).
</p></td></tr>
</table></div>
<p>
The geometric distribution assumes that success_fraction <span class="emphasis"><em>p</em></span>
is fixed for all <span class="emphasis"><em>k</em></span> trials.
</p>
<p>
The probability that there are <span class="emphasis"><em>k</em></span> failures before the
first success is
</p>
<p>
&#8192;&#8192; Pr(Y=<span class="emphasis"><em>k</em></span>) = (1-<span class="emphasis"><em>p</em></span>)<sup><span class="emphasis"><em>k</em></span></sup><span class="emphasis"><em>p</em></span>
</p>
<p>
For example, when throwing a 6-face dice the success probability <span class="emphasis"><em>p</em></span>
= 1/6 = 0.1666&#8202;&#775; &#160;. Throwing repeatedly until a <span class="emphasis"><em>three</em></span>
appears, the probability distribution of the number of times <span class="emphasis"><em>not-a-three</em></span>
is thrown is geometric.
</p>
<p>
Geometric distribution has the Probability Density Function PDF:
</p>
<p>
&#8192;&#8192; (1-<span class="emphasis"><em>p</em></span>)<sup><span class="emphasis"><em>k</em></span></sup><span class="emphasis"><em>p</em></span>
</p>
<p>
The following graph illustrates how the PDF and CDF vary for three examples
of the success fraction <span class="emphasis"><em>p</em></span>, (when considering the geometric
distribution as a continuous function),
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/geometric_pdf_2.svg" align="middle"></span>
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/geometric_cdf_2.svg" align="middle"></span>
</p>
<p>
and as discrete.
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/geometric_pdf_discrete.svg" align="middle"></span>
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/geometric_cdf_discrete.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.related_distributions"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.related_distributions">Related
Distributions</a>
</h5>
<p>
The geometric distribution is a special case of the <a class="link" href="negative_binomial_dist.html" title="Negative Binomial Distribution">Negative
Binomial Distribution</a> with successes parameter <span class="emphasis"><em>r</em></span>
= 1, so only one first and only success is required : thus by definition
&#8192;&#8192; <code class="computeroutput"><span class="identifier">geometric</span><span class="special">(</span><span class="identifier">p</span><span class="special">)</span> <span class="special">==</span>
<span class="identifier">negative_binomial</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="identifier">p</span><span class="special">)</span></code>
</p>
<pre class="programlisting"><span class="identifier">negative_binomial_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">r</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">);</span>
<span class="identifier">negative_binomial</span> <span class="identifier">nb</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="identifier">success_fraction</span><span class="special">);</span>
<span class="identifier">geometric</span> <span class="identifier">g</span><span class="special">(</span><span class="identifier">success_fraction</span><span class="special">);</span>
<span class="identifier">ASSERT</span><span class="special">(</span><span class="identifier">pdf</span><span class="special">(</span><span class="identifier">nb</span><span class="special">,</span> <span class="number">1</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">g</span><span class="special">,</span> <span class="number">1</span><span class="special">));</span>
</pre>
<p>
This implementation uses real numbers for the computation throughout (because
it uses the <span class="bold"><strong>real-valued</strong></span> power and exponential
functions). So to obtain a conventional strictly-discrete geometric distribution
you must ensure that an integer value is provided for the number of trials
(random variable) <span class="emphasis"><em>k</em></span>, and take integer values (floor
or ceil functions) from functions that return a number of successes.
</p>
<div class="caution"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top">
<p>
The geometric distribution is a discrete distribution: internally, functions
like the <code class="computeroutput"><span class="identifier">cdf</span></code> and <code class="computeroutput"><span class="identifier">pdf</span></code> are treated "as if" they
are continuous functions, but in reality the results returned from these
functions only have meaning if an integer value is provided for the random
variate argument.
</p>
<p>
The quantile function will by default return an integer result that has
been <span class="emphasis"><em>rounded outwards</em></span>. That is to say lower quantiles
(where the probability is less than 0.5) are rounded downward, and upper
quantiles (where the probability is greater than 0.5) are rounded upwards.
This behaviour ensures that if an X% quantile is requested, then <span class="emphasis"><em>at
least</em></span> the requested coverage will be present in the central
region, and <span class="emphasis"><em>no more than</em></span> the requested coverage
will be present in the tails.
</p>
<p>
This behaviour can be changed so that the quantile functions are rounded
differently, or even return a real-valued result using <a class="link" href="../../pol_overview.html" title="Policy Overview">Policies</a>.
It is strongly recommended that you read the tutorial <a class="link" href="../../pol_tutorial/understand_dis_quant.html" title="Understanding Quantiles of Discrete Distributions">Understanding
Quantiles of Discrete Distributions</a> before using the quantile
function on the geometric distribution. The <a class="link" href="../../pol_ref/discrete_quant_ref.html" title="Discrete Quantile Policies">reference
docs</a> describe how to change the rounding policy for these distributions.
</p>
</td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.member_functions"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.member_functions">Member
Functions</a>
</h5>
<h6>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.constructor"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.constructor">Constructor</a>
</h6>
<pre class="programlisting"><span class="identifier">geometric_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
</pre>
<p>
Constructor: <span class="emphasis"><em>p</em></span> or success_fraction is the probability
of success of a single trial.
</p>
<p>
Requires: <code class="computeroutput"><span class="number">0</span> <span class="special">&lt;=</span>
<span class="identifier">p</span> <span class="special">&lt;=</span>
<span class="number">1</span></code>.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.accessors"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.accessors">Accessors</a>
</h6>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> <span class="comment">// successes / trials (0 &lt;= p &lt;= 1)</span>
</pre>
<p>
Returns the success_fraction parameter <span class="emphasis"><em>p</em></span> from which
this distribution was constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> <span class="comment">// required successes always one,</span>
<span class="comment">// included for compatibility with negative binomial distribution</span>
<span class="comment">// with successes r == 1.</span>
</pre>
<p>
Returns unity.
</p>
<p>
The following functions are equivalent to those provided for the negative
binomial, with successes = 1, but are provided here for completeness.
</p>
<p>
The best method of calculation for the following functions is disputed:
see <a class="link" href="binomial_dist.html" title="Binomial Distribution">Binomial
Distribution</a> and <a class="link" href="negative_binomial_dist.html" title="Negative Binomial Distribution">Negative
Binomial Distribution</a> for more discussion.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.lower_bound_on_success_fraction_"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.lower_bound_on_success_fraction_">Lower
Bound on success_fraction Parameter <span class="emphasis"><em>p</em></span></a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_lower_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">failures</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">)</span> <span class="comment">// (0 &lt;= alpha &lt;= 1), 0.05 equivalent to 95% confidence.</span>
</pre>
<p>
Returns a <span class="bold"><strong>lower bound</strong></span> on the success fraction:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">failures</span></dt>
<dd><p>
The total number of failures before the 1st success.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The largest acceptable probability that the true value of the success
fraction is <span class="bold"><strong>less than</strong></span> the value
returned.
</p></dd>
</dl>
</div>
<p>
For example, if you observe <span class="emphasis"><em>k</em></span> failures from <span class="emphasis"><em>n</em></span>
trials the best estimate for the success fraction is simply 1/<span class="emphasis"><em>n</em></span>,
but if you want to be 95% sure that the true value is <span class="bold"><strong>greater
than</strong></span> some value, <span class="emphasis"><em>p<sub>min</sub></em></span>, then:
</p>
<pre class="programlisting"><span class="identifier">p</span><sub>min</sub> <span class="special">=</span> <span class="identifier">geometric_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span>
<span class="identifier">find_lower_bound_on_p</span><span class="special">(</span><span class="identifier">failures</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
<a class="link" href="../../stat_tut/weg/neg_binom_eg/neg_binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for the Negative Binomial Distribution">See
negative_binomial confidence interval example.</a>
</p>
<p>
This function uses the Clopper-Pearson method of computing the lower bound
on the success fraction, whilst many texts refer to this method as giving
an "exact" result in practice it produces an interval that guarantees
<span class="emphasis"><em>at least</em></span> the coverage required, and may produce pessimistic
estimates for some combinations of <span class="emphasis"><em>failures</em></span> and <span class="emphasis"><em>successes</em></span>.
See:
</p>
<p>
<a href="http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf" target="_top">Yong
Cai and K. Krishnamoorthy, A Simple Improved Inferential Method for Some
Discrete Distributions. Computational statistics and data analysis, 2005,
vol. 48, no3, 605-621</a>.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.upper_bound_on_success_fraction_"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.upper_bound_on_success_fraction_">Upper
Bound on success_fraction Parameter p</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_upper_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// (0 &lt;= alpha &lt;= 1), 0.05 equivalent to 95% confidence.</span>
</pre>
<p>
Returns an <span class="bold"><strong>upper bound</strong></span> on the success
fraction:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">trials</span></dt>
<dd><p>
The total number of trials conducted.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The largest acceptable probability that the true value of the success
fraction is <span class="bold"><strong>greater than</strong></span> the value
returned.
</p></dd>
</dl>
</div>
<p>
For example, if you observe <span class="emphasis"><em>k</em></span> successes from <span class="emphasis"><em>n</em></span>
trials the best estimate for the success fraction is simply <span class="emphasis"><em>k/n</em></span>,
but if you want to be 95% sure that the true value is <span class="bold"><strong>less
than</strong></span> some value, <span class="emphasis"><em>p<sub>max</sub></em></span>, then:
</p>
<pre class="programlisting"><span class="identifier">p</span><sub>max</sub> <span class="special">=</span> <span class="identifier">geometric_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_upper_bound_on_p</span><span class="special">(</span>
<span class="identifier">k</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
<a class="link" href="../../stat_tut/weg/neg_binom_eg/neg_binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for the Negative Binomial Distribution">See
negative binomial confidence interval example.</a>
</p>
<p>
This function uses the Clopper-Pearson method of computing the lower bound
on the success fraction, whilst many texts refer to this method as giving
an "exact" result in practice it produces an interval that guarantees
<span class="emphasis"><em>at least</em></span> the coverage required, and may produce pessimistic
estimates for some combinations of <span class="emphasis"><em>failures</em></span> and <span class="emphasis"><em>successes</em></span>.
See:
</p>
<p>
<a href="http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf" target="_top">Yong
Cai and K. Krishnamoorthy, A Simple Improved Inferential Method for Some
Discrete Distributions. Computational statistics and data analysis, 2005,
vol. 48, no3, 605-621</a>.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h6"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.estimating_number_of_trials_to_e"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.estimating_number_of_trials_to_e">Estimating
Number of Trials to Ensure at Least a Certain Number of Failures</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of failures.</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction.</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// probability threshold (0.05 equivalent to 95%).</span>
</pre>
<p>
This functions estimates the number of trials required to achieve a certain
probability that <span class="bold"><strong>more than <span class="emphasis"><em>k</em></span>
failures will be observed</strong></span>.
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">k</span></dt>
<dd><p>
The target number of failures to be observed.
</p></dd>
<dt><span class="term">p</span></dt>
<dd><p>
The probability of <span class="emphasis"><em>success</em></span> for each trial.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The maximum acceptable <span class="emphasis"><em>risk</em></span> that only <span class="emphasis"><em>k</em></span>
failures or fewer will be observed.
</p></dd>
</dl>
</div>
<p>
For example:
</p>
<pre class="programlisting"><span class="identifier">geometric_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span><span class="number">10</span><span class="special">,</span> <span class="number">0.5</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
Returns the smallest number of trials we must conduct to be 95% (1-0.05)
sure of seeing 10 failures that occur with frequency one half.
</p>
<p>
<a class="link" href="../../stat_tut/weg/neg_binom_eg/neg_binom_size_eg.html" title="Estimating Sample Sizes for the Negative Binomial.">Worked
Example.</a>
</p>
<p>
This function uses numeric inversion of the geometric distribution to obtain
the result: another interpretation of the result is that it finds the number
of trials (failures) that will lead to an <span class="emphasis"><em>alpha</em></span> probability
of observing <span class="emphasis"><em>k</em></span> failures or fewer.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h7"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.estimating_number_of_trials_to_0"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.estimating_number_of_trials_to_0">Estimating
Number of Trials to Ensure a Maximum Number of Failures or Less</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of failures.</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction.</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// probability threshold (0.05 equivalent to 95%).</span>
</pre>
<p>
This functions estimates the maximum number of trials we can conduct and
achieve a certain probability that <span class="bold"><strong>k failures or
fewer will be observed</strong></span>.
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">k</span></dt>
<dd><p>
The maximum number of failures to be observed.
</p></dd>
<dt><span class="term">p</span></dt>
<dd><p>
The probability of <span class="emphasis"><em>success</em></span> for each trial.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The maximum acceptable <span class="emphasis"><em>risk</em></span> that more than
<span class="emphasis"><em>k</em></span> failures will be observed.
</p></dd>
</dl>
</div>
<p>
For example:
</p>
<pre class="programlisting"><span class="identifier">geometric_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span><span class="number">0</span><span class="special">,</span> <span class="number">1.0</span><span class="special">-</span><span class="number">1.0</span><span class="special">/</span><span class="number">1000000</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
Returns the largest number of trials we can conduct and still be 95% sure
of seeing no failures that occur with frequency one in one million.
</p>
<p>
This function uses numeric inversion of the geometric distribution to obtain
the result: another interpretation of the result, is that it finds the
number of trials that will lead to an <span class="emphasis"><em>alpha</em></span> probability
of observing more than k failures.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h8"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.non_member_accessors"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
However it's worth taking a moment to define what these actually mean in
the context of this distribution:
</p>
<div class="table">
<a name="math_toolkit.dist_ref.dists.geometric_dist.meaning_of_the_non_member_access"></a><p class="title"><b>Table&#160;5.2.&#160;Meaning of the non-member accessors.</b></p>
<div class="table-contents"><table class="table" summary="Meaning of the non-member accessors.">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Function
</p>
</th>
<th>
<p>
Meaning
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density
Function</a>
</p>
</td>
<td>
<p>
The probability of obtaining <span class="bold"><strong>exactly k
failures</strong></span> from <span class="emphasis"><em>k</em></span> trials with success
fraction p. For example:
</p>
<pre class="programlisting"><span class="identifier">pdf</span><span class="special">(</span><span class="identifier">geometric</span><span class="special">(</span><span class="identifier">p</span><span class="special">),</span> <span class="identifier">k</span><span class="special">)</span></pre>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution
Function</a>
</p>
</td>
<td>
<p>
The probability of obtaining <span class="bold"><strong>k failures
or fewer</strong></span> from <span class="emphasis"><em>k</em></span> trials with success
fraction p and success on the last trial. For example:
</p>
<pre class="programlisting"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">geometric</span><span class="special">(</span><span class="identifier">p</span><span class="special">),</span> <span class="identifier">k</span><span class="special">)</span></pre>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.ccdf">Complement of
the Cumulative Distribution Function</a>
</p>
</td>
<td>
<p>
The probability of obtaining <span class="bold"><strong>more than
k failures</strong></span> from <span class="emphasis"><em>k</em></span> trials with
success fraction p and success on the last trial. For example:
</p>
<pre class="programlisting"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">geometric</span><span class="special">(</span><span class="identifier">p</span><span class="special">),</span> <span class="identifier">k</span><span class="special">))</span></pre>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>
</p>
</td>
<td>
<p>
The <span class="bold"><strong>greatest</strong></span> number of failures
<span class="emphasis"><em>k</em></span> expected to be observed from <span class="emphasis"><em>k</em></span>
trials with success fraction <span class="emphasis"><em>p</em></span>, at probability
<span class="emphasis"><em>P</em></span>. Note that the value returned is a real-number,
and not an integer. Depending on the use case you may want to
take either the floor or ceiling of the real result. For example:
</p>
<pre class="programlisting"><span class="identifier">quantile</span><span class="special">(</span><span class="identifier">geometric</span><span class="special">(</span><span class="identifier">p</span><span class="special">),</span> <span class="identifier">P</span><span class="special">)</span></pre>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile_c">Quantile
from the complement of the probability</a>
</p>
</td>
<td>
<p>
The <span class="bold"><strong>smallest</strong></span> number of failures
<span class="emphasis"><em>k</em></span> expected to be observed from <span class="emphasis"><em>k</em></span>
trials with success fraction <span class="emphasis"><em>p</em></span>, at probability
<span class="emphasis"><em>P</em></span>. Note that the value returned is a real-number,
and not an integer. Depending on the use case you may want to
take either the floor or ceiling of the real result. For example:
</p>
<pre class="programlisting"><span class="identifier">quantile</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">geometric</span><span class="special">(</span><span class="identifier">p</span><span class="special">),</span> <span class="identifier">P</span><span class="special">))</span></pre>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><h5>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h9"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.accuracy"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.accuracy">Accuracy</a>
</h5>
<p>
This distribution is implemented using the pow and exp functions, so most
results are accurate within a few epsilon for the RealType. For extreme
values of <code class="computeroutput"><span class="keyword">double</span></code> <span class="emphasis"><em>p</em></span>,
for example 0.9999999999, accuracy can fall significantly, for example
to 10 decimal digits (from 16).
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.geometric_dist.h10"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.geometric_dist.implementation"></a></span><a class="link" href="geometric_dist.html#math_toolkit.dist_ref.dists.geometric_dist.implementation">Implementation</a>
</h5>
<p>
In the following table, <span class="emphasis"><em>p</em></span> is the probability that
any one trial will be successful (the success fraction), <span class="emphasis"><em>k</em></span>
is the number of failures, <span class="emphasis"><em>p</em></span> is the probability and
<span class="emphasis"><em>q = 1-p</em></span>, <span class="emphasis"><em>x</em></span> is the given probability
to estimate the expected number of failures using the quantile.
</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>
pdf = p * pow(q, k)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
cdf = 1 - q<sup>k=1</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
exp(log1p(-p) * (k+1))
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
k = log1p(-x) / log1p(-p) -1
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
k = log(x) / log1p(-p) -1
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
(1-p)/p
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
(1-p)/p&#178;
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
(2-p)/&#8730;q
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
9+p&#178;/q
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
6 +p&#178;/q
</p>
</td>
</tr>
<tr>
<td>
<p>
parameter estimation member functions
</p>
</td>
<td>
<p>
See <a class="link" href="negative_binomial_dist.html" title="Negative Binomial Distribution">Negative
Binomial Distribution</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_lower_bound_on_p</span></code>
</p>
</td>
<td>
<p>
See <a class="link" href="negative_binomial_dist.html" title="Negative Binomial Distribution">Negative
Binomial Distribution</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_upper_bound_on_p</span></code>
</p>
</td>
<td>
<p>
See <a class="link" href="negative_binomial_dist.html" title="Negative Binomial Distribution">Negative
Binomial Distribution</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_minimum_number_of_trials</span></code>
</p>
</td>
<td>
<p>
See <a class="link" href="negative_binomial_dist.html" title="Negative Binomial Distribution">Negative
Binomial Distribution</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_maximum_number_of_trials</span></code>
</p>
</td>
<td>
<p>
See <a class="link" href="negative_binomial_dist.html" title="Negative Binomial Distribution">Negative
Binomial Distribution</a>
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="gamma_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="hyperexponential_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,340 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Hypergeometric Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="hyperexponential_dist.html" title="Hyperexponential Distribution">
<link rel="next" href="inverse_chi_squared_dist.html" title="Inverse Chi Squared 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="hyperexponential_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="inverse_chi_squared_dist.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.dist_ref.dists.hypergeometric_dist"></a><a class="link" href="hypergeometric_dist.html" title="Hypergeometric Distribution">Hypergeometric
Distribution</a>
</h4></div></div></div>
<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">hypergeometric</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">hypergeometric_distribution</span><span class="special">;</span>
<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> <span class="identifier">Policy</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">hypergeometric_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="comment">// Construct:</span>
<span class="identifier">hypergeometric_distribution</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">r</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">N</span><span class="special">);</span>
<span class="comment">// Accessors:</span>
<span class="keyword">unsigned</span> <span class="identifier">total</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="keyword">unsigned</span> <span class="identifier">defective</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="keyword">unsigned</span> <span class="identifier">sample_count</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">typedef</span> <span class="identifier">hypergeometric_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">hypergeometric</span><span class="special">;</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The hypergeometric distribution describes the number of "events"
<span class="emphasis"><em>k</em></span> from a sample <span class="emphasis"><em>n</em></span> drawn from
a total population <span class="emphasis"><em>N</em></span> <span class="emphasis"><em>without replacement</em></span>.
</p>
<p>
Imagine we have a sample of <span class="emphasis"><em>N</em></span> objects of which <span class="emphasis"><em>r</em></span>
are "defective" and N-r are "not defective" (the terms
"success/failure" or "red/blue" are also used). If
we sample <span class="emphasis"><em>n</em></span> items <span class="emphasis"><em>without replacement</em></span>
then what is the probability that exactly <span class="emphasis"><em>k</em></span> items
in the sample are defective? The answer is given by the pdf of the hypergeometric
distribution <code class="computeroutput"><span class="identifier">f</span><span class="special">(</span><span class="identifier">k</span><span class="special">;</span> <span class="identifier">r</span><span class="special">,</span> <span class="identifier">n</span><span class="special">,</span>
<span class="identifier">N</span><span class="special">)</span></code>,
whilst the probability of <span class="emphasis"><em>k</em></span> defectives or fewer is
given by F(k; r, n, N), where F(k) is the CDF of the hypergeometric distribution.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
Unlike almost all of the other distributions in this library, the hypergeometric
distribution is strictly discrete: it can not be extended to real valued
arguments of its parameters or random variable.
</p></td></tr>
</table></div>
<p>
The following graph shows how the distribution changes as the proportion
of "defective" items changes, while keeping the population and
sample sizes constant:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/hypergeometric_pdf_1.svg" align="middle"></span>
</p>
<p>
Note that since the distribution is symmetrical in parameters <span class="emphasis"><em>n</em></span>
and <span class="emphasis"><em>r</em></span>, if we change the sample size and keep the population
and proportion "defective" the same then we obtain basically
the same graphs:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/hypergeometric_pdf_2.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.hypergeometric_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.hypergeometric_dist.member_functions"></a></span><a class="link" href="hypergeometric_dist.html#math_toolkit.dist_ref.dists.hypergeometric_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">hypergeometric_distribution</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">r</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">N</span><span class="special">);</span>
</pre>
<p>
Constructs a hypergeometric distribution with a population of <span class="emphasis"><em>N</em></span>
objects, of which <span class="emphasis"><em>r</em></span> are defective, and from which
<span class="emphasis"><em>n</em></span> are sampled.
</p>
<pre class="programlisting"><span class="keyword">unsigned</span> <span class="identifier">total</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the total number of objects <span class="emphasis"><em>N</em></span>.
</p>
<pre class="programlisting"><span class="keyword">unsigned</span> <span class="identifier">defective</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the number of objects <span class="emphasis"><em>r</em></span> in population <span class="emphasis"><em>N</em></span>
which are defective.
</p>
<pre class="programlisting"><span class="keyword">unsigned</span> <span class="identifier">sample_count</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the number of objects <span class="emphasis"><em>n</em></span> which are sampled
from the population <span class="emphasis"><em>N</em></span>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.hypergeometric_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.hypergeometric_dist.non_member_accessors"></a></span><a class="link" href="hypergeometric_dist.html#math_toolkit.dist_ref.dists.hypergeometric_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is the unsigned integers in the range
[max(0, n + r - N), min(n, r)]. A <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
is raised if the random variable is outside this range, or is not an integral
value.
</p>
<div class="caution"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top">
<p>
The quantile function will by default return an integer result that has
been <span class="emphasis"><em>rounded outwards</em></span>. That is to say lower quantiles
(where the probability is less than 0.5) are rounded downward, and upper
quantiles (where the probability is greater than 0.5) are rounded upwards.
This behaviour ensures that if an X% quantile is requested, then <span class="emphasis"><em>at
least</em></span> the requested coverage will be present in the central
region, and <span class="emphasis"><em>no more than</em></span> the requested coverage
will be present in the tails.
</p>
<p>
This behaviour can be changed so that the quantile functions are rounded
differently using <a class="link" href="../../pol_overview.html" title="Policy Overview">Policies</a>.
It is strongly recommended that you read the tutorial <a class="link" href="../../pol_tutorial/understand_dis_quant.html" title="Understanding Quantiles of Discrete Distributions">Understanding
Quantiles of Discrete Distributions</a> before using the quantile
function on the Hypergeometric distribution. The <a class="link" href="../../pol_ref/discrete_quant_ref.html" title="Discrete Quantile Policies">reference
docs</a> describe how to change the rounding policy for these distributions.
</p>
<p>
However, note that the implementation method of the quantile function
always returns an integral value, therefore attempting to use a <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a> that requires (or produces) a real valued
result will result in a compile time error.
</p>
</td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.hypergeometric_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.hypergeometric_dist.accuracy"></a></span><a class="link" href="hypergeometric_dist.html#math_toolkit.dist_ref.dists.hypergeometric_dist.accuracy">Accuracy</a>
</h5>
<p>
For small N such that <code class="computeroutput"><span class="identifier">N</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">max_factorial</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">value</span></code>
then table based lookup of the results gives an accuracy to a few epsilon.
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">max_factorial</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">value</span></code> is 170 at double or long double
precision.
</p>
<p>
For larger N such that <code class="computeroutput"><span class="identifier">N</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">prime</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">max_prime</span><span class="special">)</span></code> then only basic arithmetic is required
for the calculation and the accuracy is typically &lt; 20 epsilon. This
takes care of N up to 104729.
</p>
<p>
For <code class="computeroutput"><span class="identifier">N</span> <span class="special">&gt;</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">prime</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">max_prime</span><span class="special">)</span></code>
then accuracy quickly degrades, with 5 or 6 decimal digits being lost for
N = 110000.
</p>
<p>
In general for very large N, the user should expect to lose log<sub>10</sub>N decimal
digits of precision during the calculation, with the results becoming meaningless
for N &gt;= 10<sup>15</sup>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.hypergeometric_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.hypergeometric_dist.testing"></a></span><a class="link" href="hypergeometric_dist.html#math_toolkit.dist_ref.dists.hypergeometric_dist.testing">Testing</a>
</h5>
<p>
There are three sets of tests: our implementation is tested against a table
of values produced by Mathematica's implementation of this distribution.
We also sanity check our implementation against some spot values computed
using the online calculator here <a href="http://stattrek.com/Tables/Hypergeometric.aspx" target="_top">http://stattrek.com/Tables/Hypergeometric.aspx</a>.
Finally we test accuracy against some high precision test data using this
implementation and NTL::RR.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.hypergeometric_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.hypergeometric_dist.implementation"></a></span><a class="link" href="hypergeometric_dist.html#math_toolkit.dist_ref.dists.hypergeometric_dist.implementation">Implementation</a>
</h5>
<p>
The PDF can be calculated directly using the formula:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/hypergeometric1.svg"></span>
</p>
<p>
However, this can only be used directly when the largest of the factorials
is guaranteed not to overflow the floating point representation used. This
formula is used directly when <code class="computeroutput"><span class="identifier">N</span>
<span class="special">&lt;</span> <span class="identifier">max_factorial</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">value</span></code>
in which case table lookup of the factorials gives a rapid and accurate
implementation method.
</p>
<p>
For larger <span class="emphasis"><em>N</em></span> the method described in "An Accurate
Computation of the Hypergeometric Distribution Function", Trong Wu,
ACM Transactions on Mathematical Software, Vol. 19, No. 1, March 1993,
Pages 33-43 is used. The method relies on the fact that there is an easy
method for factorising a factorial into the product of prime numbers:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/hypergeometric2.svg"></span>
</p>
<p>
Where p<sub>i</sub> is the i'th prime number, and e<sub>i</sub> is a small positive integer or
zero, which can be calculated via:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/hypergeometric3.svg"></span>
</p>
<p>
Further we can combine the factorials in the expression for the PDF to
yield the PDF directly as the product of prime numbers:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/hypergeometric4.svg"></span>
</p>
<p>
With this time the exponents e<sub>i</sub> being either positive, negative or zero.
Indeed such a degree of cancellation occurs in the calculation of the e<sub>i</sub> that
many are zero, and typically most have a magnitude or no more than 1 or
2.
</p>
<p>
Calculation of the product of the primes requires some care to prevent
numerical overflow, we use a novel recursive method which splits the calculation
into a series of sub-products, with a new sub-product started each time
the next multiplication would cause either overflow or underflow. The sub-products
are stored in a linked list on the program stack, and combined in an order
that will guarantee no overflow or unnecessary-underflow once the last
sub-product has been calculated.
</p>
<p>
This method can be used as long as N is smaller than the largest prime
number we have stored in our table of primes (currently 104729). The method
is relatively slow (calculating the exponents requires the most time),
but requires only a small number of arithmetic operations to calculate
the result (indeed there is no shorter method involving only basic arithmetic
once the exponents have been found), the method is therefore much more
accurate than the alternatives.
</p>
<p>
For much larger N, we can calculate the PDF from the factorials using either
lgamma, or by directly combining lanczos approximations to avoid calculating
via logarithms. We use the latter method, as it is usually 1 or 2 decimal
digits more accurate than computing via logarithms with lgamma. However,
in this area where N &gt; 104729, the user should expect to lose around
log<sub>10</sub>N decimal digits during the calculation in the worst case.
</p>
<p>
The CDF and its complement is calculated by directly summing the PDF's.
We start by deciding whether the CDF, or its complement, is likely to be
the smaller of the two and then calculate the PDF at <span class="emphasis"><em>k</em></span>
(or <span class="emphasis"><em>k+1</em></span> if we're calculating the complement) and calculate
successive PDF values via the recurrence relations:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/hypergeometric5.svg"></span>
</p>
<p>
Until we either reach the end of the distributions domain, or the next
PDF value to be summed would be too small to affect the result.
</p>
<p>
The quantile is calculated in a similar manner to the CDF: we first guess
which end of the distribution we're nearer to, and then sum PDFs starting
from the end of the distribution this time, until we have some value <span class="emphasis"><em>k</em></span>
that gives the required CDF.
</p>
<p>
The median is simply the quantile at 0.5, and the remaining properties
are calculated via:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/hypergeometric6.svg"></span>
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="hyperexponential_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="inverse_chi_squared_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,472 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Inverse Chi Squared Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="hypergeometric_dist.html" title="Hypergeometric Distribution">
<link rel="next" href="inverse_gamma_dist.html" title="Inverse Gamma 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="hypergeometric_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="inverse_gamma_dist.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.dist_ref.dists.inverse_chi_squared_dist"></a><a class="link" href="inverse_chi_squared_dist.html" title="Inverse Chi Squared Distribution">Inverse
Chi Squared Distribution</a>
</h4></div></div></div>
<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">inverse_chi_squared</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">inverse_chi_squared_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">inverse_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// Not explicitly scaled, default 1/df.</span>
<span class="identifier">inverse_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">/</span><span class="identifier">df</span><span class="special">);</span> <span class="comment">// Scaled.</span>
<span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// Default 1.</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// Optional scale [xi] (variance), default 1/degrees_of_freedom.</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespace boost // namespace math</span>
</pre>
<p>
The inverse chi squared distribution is a continuous probability distribution
of the <span class="bold"><strong>reciprocal</strong></span> of a variable distributed
according to the chi squared distribution.
</p>
<p>
The sources below give confusingly different formulae using different symbols
for the distribution pdf, but they are all the same, or related by a change
of variable, or choice of scale.
</p>
<p>
Two constructors are available to implement both the scaled and (implicitly)
unscaled versions.
</p>
<p>
The main version has an explicit scale parameter which implements the
<a href="http://en.wikipedia.org/wiki/Scaled-inverse-chi-square_distribution" target="_top">scaled
inverse chi_squared distribution</a>.
</p>
<p>
A second version has an implicit scale = 1/degrees of freedom and gives
the 1st definition in the <a href="http://en.wikipedia.org/wiki/Inverse-chi-square_distribution" target="_top">Wikipedia
inverse chi_squared distribution</a>. The 2nd Wikipedia inverse chi_squared
distribution definition can be implemented by explicitly specifying a scale
= 1.
</p>
<p>
Both definitions are also available in Wolfram Mathematica and in <a href="http://www.r-project.org/" target="_top">The R Project for Statistical Computing</a>
(geoR) with default scale = 1/degrees of freedom.
</p>
<p>
See
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Inverse chi_squared distribution <a href="http://en.wikipedia.org/wiki/Inverse-chi-square_distribution" target="_top">http://en.wikipedia.org/wiki/Inverse-chi-square_distribution</a>
</li>
<li class="listitem">
Scaled inverse chi_squared distribution<a href="http://en.wikipedia.org/wiki/Scaled-inverse-chi-square_distribution" target="_top">http://en.wikipedia.org/wiki/Scaled-inverse-chi-square_distribution</a>
</li>
<li class="listitem">
R inverse chi_squared distribution functions <a href="http://hosho.ees.hokudai.ac.jp/~kubo/Rdoc/library/geoR/html/InvChisquare.html" target="_top">R
</a>
</li>
<li class="listitem">
Inverse chi_squared distribution functions <a href="http://mathworld.wolfram.com/InverseChi-SquaredDistribution.html" target="_top">Weisstein,
Eric W. "Inverse Chi-Squared Distribution." From MathWorld--A
Wolfram Web Resource.</a>
</li>
<li class="listitem">
Inverse chi_squared distribution reference <a href="http://reference.wolfram.com/mathematica/ref/InverseChiSquareDistribution.html" target="_top">Weisstein,
Eric W. "Inverse Chi-Squared Distribution reference." From
Wolfram Mathematica.</a>
</li>
</ul></div>
<p>
The inverse_chi_squared distribution is used in <a href="http://en.wikipedia.org/wiki/Bayesian_statistics" target="_top">Bayesian
statistics</a>: the scaled inverse chi-square is conjugate prior for
the normal distribution with known mean, model parameter &#963;&#178; (variance).
</p>
<p>
See <a href="http://en.wikipedia.org/wiki/Conjugate_prior" target="_top">conjugate
priors including a table of distributions and their priors.</a>
</p>
<p>
See also <a class="link" href="inverse_gamma_dist.html" title="Inverse Gamma Distribution">Inverse
Gamma Distribution</a> and <a class="link" href="chi_squared_dist.html" title="Chi Squared Distribution">Chi
Squared Distribution</a>.
</p>
<p>
The inverse_chi_squared distribution is a special case of a inverse_gamma
distribution with &#957; (degrees_of_freedom) shape (&#945;) and scale (&#946;) where
</p>
<p>
&#8192;&#8192; &#945;= &#957; /2 and &#946; = &#189;.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
This distribution <span class="bold"><strong>does</strong></span> provide the typedef:
</p>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">inverse_chi_squared_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">inverse_chi_squared</span><span class="special">;</span></pre>
<p>
If you want a <code class="computeroutput"><span class="keyword">double</span></code> precision
inverse_chi_squared distribution you can use
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">inverse_chi_squared_distribution</span><span class="special">&lt;&gt;</span></pre>
<p>
or you can write <code class="computeroutput"><span class="identifier">inverse_chi_squared</span>
<span class="identifier">my_invchisqr</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span></code>
</p>
</td></tr>
</table></div>
<p>
For degrees of freedom parameter &#957;, the (<span class="bold"><strong>unscaled</strong></span>)
inverse chi_squared distribution is defined by the probability density
function (PDF):
</p>
<p>
&#8192;&#8192; f(x;&#957;) = 2<sup>-&#957;/2</sup> x<sup>-&#957;/2-1</sup> e<sup>-1/2x</sup> / &#915;(&#957;/2)
</p>
<p>
and Cumulative Density Function (CDF)
</p>
<p>
&#8192;&#8192; F(x;&#957;) = &#915;(&#957;/2, 1/2x) / &#915;(&#957;/2)
</p>
<p>
For degrees of freedom parameter &#957; and scale parameter &#958;, the <span class="bold"><strong>scaled</strong></span>
inverse chi_squared distribution is defined by the probability density
function (PDF):
</p>
<p>
&#8192;&#8192; f(x;&#957;, &#958;) = (&#958;&#957;/2)<sup>&#957;/2</sup> e<sup>-&#957;&#958;/2x</sup> x<sup>-1-&#957;/2</sup> / &#915;(&#957;/2)
</p>
<p>
and Cumulative Density Function (CDF)
</p>
<p>
&#8192;&#8192; F(x;&#957;, &#958;) = &#915;(&#957;/2, &#957;&#958;/2x) / &#915;(&#957;/2)
</p>
<p>
The following graphs illustrate how the PDF and CDF of the inverse chi_squared
distribution varies for a few values of parameters &#957; and &#958;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/inverse_chi_squared_pdf.svg" align="middle"></span>
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/inverse_chi_squared_cdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.member_functions"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">inverse_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// Implicitly scaled 1/df.</span>
<span class="identifier">inverse_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">);</span> <span class="comment">// Explicitly scaled.</span>
</pre>
<p>
Constructs an inverse chi_squared distribution with &#957; degrees of freedom
<span class="emphasis"><em>df</em></span>, and scale <span class="emphasis"><em>scale</em></span> with default
value 1/df.
</p>
<p>
Requires that the degrees of freedom &#957; parameter is greater than zero, otherwise
calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the degrees_of_freedom &#957; parameter of this distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the scale &#958; parameter of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.non_member_accessors"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variate is [0,+&#8734;].
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
Unlike some definitions, this implementation supports a random variate
equal to zero as a special case, returning zero for both pdf and cdf.
</p></td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.accuracy"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_dist.accuracy">Accuracy</a>
</h5>
<p>
The inverse gamma distribution is implemented in terms of the incomplete
gamma functions like the <a class="link" href="inverse_gamma_dist.html" title="Inverse Gamma Distribution">Inverse
Gamma Distribution</a> that use <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>
and <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a> and their
inverses <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>
and <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>:
refer to the accuracy data for those functions for more information. But
in general, gamma (and thus inverse gamma) results are often accurate to
a few epsilon, &gt;14 decimal digits accuracy for 64-bit double. unless
iteration is involved, as for the estimation of degrees of freedom.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.implementation"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_dist.implementation">Implementation</a>
</h5>
<p>
In the following table &#957; is the degrees of freedom parameter and &#958; is the scale
parameter of the distribution, <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>
its complement. Parameters &#945; for shape and &#946; for scale are used for the inverse
gamma function: &#945; = &#957;/2 and &#946; = &#957; * &#958;/2.
</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 = <a class="link" href="../../sf_gamma/gamma_derivatives.html" title="Derivative of the Incomplete Gamma Function">gamma_p_derivative</a>(&#945;,
&#946;/ x, &#946;) / x * x
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a>(&#945;,
&#946; / x)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>(&#945;,
&#946; / x)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = &#946; &#160;/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>(&#945;,
p)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = &#945; &#160;/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>(&#945;,
q)
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
&#957; * &#958; / (&#957; + 2)
</p>
</td>
</tr>
<tr>
<td>
<p>
median
</p>
</td>
<td>
<p>
no closed form analytic equation is known, but is evaluated as
quantile(0.5)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
&#957;&#958; / (&#957; - 2) for &#957; &gt; 2, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
2 &#957;&#178; &#958;&#178; / ((&#957; -2)&#178; (&#957; -4)) for &#957; &gt;4, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
4 &#8730;2 &#8730;(&#957;-4) /(&#957;-6) for &#957; &gt;6, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis_excess
</p>
</td>
<td>
<p>
12 * (5&#957; - 22) / ((&#957; - 6) * (&#957; - 8)) for &#957; &gt;8, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
3 + 12 * (5&#957; - 22) / ((&#957; - 6) * (&#957;-8)) for &#957; &gt;8, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.references"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_dist.references">References</a>
</h5>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
Bayesian Data Analysis, Andrew Gelman, John B. Carlin, Hal S. Stern,
Donald B. Rubin, ISBN-13: 978-1584883883, Chapman &amp; Hall; 2 edition
(29 July 2003).
</li>
<li class="listitem">
Bayesian Computation with R, Jim Albert, ISBN-13: 978-0387922973, Springer;
2nd ed. edition (10 Jun 2009)
</li>
</ol></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="hypergeometric_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="inverse_gamma_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,368 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Inverse Gamma Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="inverse_chi_squared_dist.html" title="Inverse Chi Squared Distribution">
<link rel="next" href="inverse_gaussian_dist.html" title="Inverse Gaussian (or Inverse Normal) 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="inverse_chi_squared_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="inverse_gaussian_dist.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.dist_ref.dists.inverse_gamma_dist"></a><a class="link" href="inverse_gamma_dist.html" title="Inverse Gamma Distribution">Inverse
Gamma Distribution</a>
</h4></div></div></div>
<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">inverse_gamma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">inverse_gamma_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">inverse_gamma_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">)</span>
<span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The inverse_gamma distribution is a continuous probability distribution
of the reciprocal of a variable distributed according to the gamma distribution.
</p>
<p>
The inverse_gamma distribution is used in Bayesian statistics.
</p>
<p>
See <a href="http://en.wikipedia.org/wiki/Inverse-gamma_distribution" target="_top">inverse
gamma distribution</a>.
</p>
<p>
<a href="http://rss.acs.unt.edu/Rdoc/library/pscl/html/igamma.html" target="_top">R
inverse gamma distribution functions</a>.
</p>
<p>
<a href="http://reference.wolfram.com/mathematica/ref/InverseGammaDistribution.html" target="_top">Wolfram
inverse gamma distribution</a>.
</p>
<p>
See also <a class="link" href="gamma_dist.html" title="Gamma (and Erlang) Distribution">Gamma Distribution</a>.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
In spite of potential confusion with the inverse gamma function, this
distribution <span class="bold"><strong>does</strong></span> provide the typedef:
</p>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">inverse_gamma_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">gamma</span><span class="special">;</span></pre>
<p>
If you want a <code class="computeroutput"><span class="keyword">double</span></code> precision
gamma distribution you can use
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">inverse_gamma_distribution</span><span class="special">&lt;&gt;</span></pre>
<p>
or you can write <code class="computeroutput"><span class="identifier">inverse_gamma</span>
<span class="identifier">my_ig</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span></code>
</p>
</td></tr>
</table></div>
<p>
For shape parameter &#945; and scale parameter &#946;, it is defined by the probability
density function (PDF):
</p>
<p>
&#8192;&#8192; f(x;&#945;, &#946;) = &#946;<sup>&#945;</sup> * (1/x) <sup>&#945;+1</sup> exp(-&#946;/x) / &#915;(&#945;)
</p>
<p>
and cumulative density function (CDF)
</p>
<p>
&#8192;&#8192; F(x;&#945;, &#946;) = &#915;(&#945;, &#946;/x) / &#915;(&#945;)
</p>
<p>
The following graphs illustrate how the PDF and CDF of the inverse gamma
distribution varies as the parameters vary:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/inverse_gamma_pdf.svg" align="middle"></span>
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/inverse_gamma_cdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.member_functions"></a></span><a class="link" href="inverse_gamma_dist.html#math_toolkit.dist_ref.dists.inverse_gamma_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">inverse_gamma_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">shape</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
Constructs an inverse gamma distribution with shape &#945; and scale &#946;.
</p>
<p>
Requires that the shape and scale parameters are greater than zero, otherwise
calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the &#945; shape parameter of this inverse gamma distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the &#946; scale parameter of this inverse gamma distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.non_member_accessors"></a></span><a class="link" href="inverse_gamma_dist.html#math_toolkit.dist_ref.dists.inverse_gamma_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variate is [0,+&#8734;].
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
Unlike some definitions, this implementation supports a random variate
equal to zero as a special case, returning zero for pdf and cdf.
</p></td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.accuracy"></a></span><a class="link" href="inverse_gamma_dist.html#math_toolkit.dist_ref.dists.inverse_gamma_dist.accuracy">Accuracy</a>
</h5>
<p>
The inverse gamma distribution is implemented in terms of the incomplete
gamma functions <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>
and <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a> and their
inverses <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>
and <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>:
refer to the accuracy data for those functions for more information. But
in general, inverse_gamma results are accurate to a few epsilon, &gt;14
decimal digits accuracy for 64-bit double.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.implementation"></a></span><a class="link" href="inverse_gamma_dist.html#math_toolkit.dist_ref.dists.inverse_gamma_dist.implementation">Implementation</a>
</h5>
<p>
In the following table &#945; is the shape parameter of the distribution, &#945; &#160; is its
scale 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 = <a class="link" href="../../sf_gamma/gamma_derivatives.html" title="Derivative of the Incomplete Gamma Function">gamma_p_derivative</a>(&#945;,
&#946;/ x, &#946;) / x * x
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a>(&#945;,
&#946; / x)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>(&#945;,
&#946; / x)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = &#946; &#160;/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>(&#945;,
p)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = &#945; &#160;/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>(&#945;,
q)
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
&#946; / (&#945; + 1)
</p>
</td>
</tr>
<tr>
<td>
<p>
median
</p>
</td>
<td>
<p>
no analytic equation is known, but is evaluated as quantile(0.5)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
&#946; / (&#945; - 1) for &#945; &gt; 1, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
(&#946; * &#946;) / ((&#945; - 1) * (&#945; - 1) * (&#945; - 2)) for &#945; &gt;2, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
4 * sqrt (&#945; -2) / (&#945; -3) for &#945; &gt;3, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis_excess
</p>
</td>
<td>
<p>
(30 * &#945; - 66) / ((&#945;-3)*(&#945; - 4)) for &#945; &gt;4, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="inverse_chi_squared_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="inverse_gaussian_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,446 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Inverse Gaussian (or Inverse Normal) Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="inverse_gamma_dist.html" title="Inverse Gamma Distribution">
<link rel="next" href="laplace_dist.html" title="Laplace 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="inverse_gamma_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="laplace_dist.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.dist_ref.dists.inverse_gaussian_dist"></a><a class="link" href="inverse_gaussian_dist.html" title="Inverse Gaussian (or Inverse Normal) Distribution">Inverse
Gaussian (or Inverse Normal) Distribution</a>
</h4></div></div></div>
<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">inverse_gaussian</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">inverse_gaussian_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">inverse_gaussian_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">mean</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
<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">// mean default 1.</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// Optional scale, default 1 (unscaled).</span>
<span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// Shape = scale/mean.</span>
<span class="special">};</span>
<span class="keyword">typedef</span> <span class="identifier">inverse_gaussian_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">inverse_gaussian</span><span class="special">;</span>
<span class="special">}}</span> <span class="comment">// namespace boost // namespace math</span>
</pre>
<p>
The Inverse Gaussian distribution distribution is a continuous probability
distribution.
</p>
<p>
The distribution is also called 'normal-inverse Gaussian distribution',
and 'normal Inverse' distribution.
</p>
<p>
It is also convenient to provide unity as default for both mean and scale.
This is the Standard form for all distributions. The Inverse Gaussian distribution
was first studied in relation to Brownian motion. In 1956 M.C.K. Tweedie
used the name Inverse Gaussian because there is an inverse relationship
between the time to cover a unit distance and distance covered in unit
time. The inverse Gaussian is one of family of distributions that have
been called the <a href="http://en.wikipedia.org/wiki/Tweedie_distributions" target="_top">Tweedie
distributions</a>.
</p>
<p>
(So <span class="emphasis"><em>inverse</em></span> in the name may mislead: it does <span class="bold"><strong>not</strong></span> relate to the inverse of a distribution).
</p>
<p>
The tails of the distribution decrease more slowly than the normal distribution.
It is therefore suitable to model phenomena where numerically large values
are more probable than is the case for the normal distribution. For stock
market returns and prices, a key characteristic is that it models that
extremely large variations from typical (crashes) can occur even when almost
all (normal) variations are small.
</p>
<p>
Examples are returns from financial assets and turbulent wind speeds.
</p>
<p>
The normal-inverse Gaussian distributions form a subclass of the generalised
hyperbolic distributions.
</p>
<p>
See <a href="http://en.wikipedia.org/wiki/Normal-inverse_Gaussian_distribution" target="_top">distribution</a>.
<a href="http://mathworld.wolfram.com/InverseGaussianDistribution.html" target="_top">Weisstein,
Eric W. "Inverse Gaussian Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
<p>
If you want a <code class="computeroutput"><span class="keyword">double</span></code> precision
inverse_gaussian distribution you can use
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">inverse_gaussian_distribution</span><span class="special">&lt;&gt;</span></pre>
<p>
or, more conveniently, you can write
</p>
<pre class="programlisting"><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">inverse_gaussian</span><span class="special">;</span>
<span class="identifier">inverse_gaussian</span> <span class="identifier">my_ig</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span>
</pre>
<p>
For mean parameters &#956; and scale (also called precision) parameter &#955;, and random
variate x, the inverse_gaussian distribution is defined by the probability
density function (PDF):
</p>
<p>
&#8192;&#8192; f(x;&#956;, &#955;) = &#8730;(&#955;/2&#960;x<sup>3</sup>) e<sup>-&#955;(x-&#956;)&#178;/2&#956;&#178;x</sup>
</p>
<p>
and Cumulative Density Function (CDF):
</p>
<p>
&#8192;&#8192; F(x;&#956;, &#955;) = &#934;{&#8730;(&#955;<span class="emphasis"><em>x) (x</em></span>&#956;-1)} + e<sup>2&#956;/&#955;</sup> &#934;{-&#8730;(&#955;/&#956;) (1+x/&#956;)}
</p>
<p>
where &#934; is the standard normal distribution CDF.
</p>
<p>
The following graphs illustrate how the PDF and CDF of the inverse_gaussian
distribution varies for a few values of parameters &#956; and &#955;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/inverse_gaussian_pdf.svg" align="middle"></span>
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/inverse_gaussian_cdf.svg" align="middle"></span>
</p>
<p>
Tweedie also provided 3 other parameterisations where (&#956; and &#955;) are replaced
by their ratio &#966; = &#955;/&#956; and by 1/&#956;: these forms may be more suitable for Bayesian
applications. These can be found on Seshadri, page 2 and are also discussed
by Chhikara and Folks on page 105. Another related parameterisation, the
__wald_distrib (where mean &#956; is unity) is also provided.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.member_functions"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">inverse_gaussian_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// optionally scaled.</span>
</pre>
<p>
Constructs an inverse_gaussian distribution with &#956; mean, and scale &#955;, with
both default values 1.
</p>
<p>
Requires that both the mean &#956; parameter and scale &#955; are greater than zero,
otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<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>
</pre>
<p>
Returns the mean &#956; parameter of this distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the scale &#955; parameter of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.non_member_accessors"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variate is [0,+&#8734;).
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
Unlike some definitions, this implementation supports a random variate
equal to zero as a special case, returning zero for both pdf and cdf.
</p></td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.accuracy"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_dist.accuracy">Accuracy</a>
</h5>
<p>
The inverse_gaussian distribution is implemented in terms of the exponential
function and standard normal distribution <span class="emphasis"><em>N</em></span>0,1 &#934; : refer
to the accuracy data for those functions for more information. But in general,
gamma (and thus inverse gamma) results are often accurate to a few epsilon,
&gt;14 decimal digits accuracy for 64-bit double.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.implementation"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_dist.implementation">Implementation</a>
</h5>
<p>
In the following table &#956; is the mean parameter and &#955; is the scale parameter
of the inverse_gaussian distribution, <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>
its complement. Parameters &#956; for shape and &#955; for scale are used for the inverse
gaussian function.
</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>
&#8730;(&#955;/ 2&#960;x<sup>3</sup>) e<sup>-&#955;(x - &#956;)&#178;/ 2&#956;&#178;x</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
&#934;{&#8730;(&#955;<span class="emphasis"><em>x) (x</em></span>&#956;-1)} + e<sup>2&#956;/&#955;</sup> &#934;{-&#8730;(&#955;/&#956;) (1+x/&#956;)}
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
using complement of &#934; above.
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
No closed form known. Estimated using a guess refined by Newton-Raphson
iteration.
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
No closed form known. Estimated using a guess refined by Newton-Raphson
iteration.
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
&#956; {&#8730;(1+9&#956;&#178;/4&#955;&#178;)&#178; - 3&#956;/2&#955;}
</p>
</td>
</tr>
<tr>
<td>
<p>
median
</p>
</td>
<td>
<p>
No closed form analytic equation is known, but is evaluated as
quantile(0.5)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
&#956;
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
&#956;&#179;/&#955;
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
3 &#8730; (&#956;/&#955;)
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis_excess
</p>
</td>
<td>
<p>
15&#956;/&#955;
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
12&#956;/&#955;
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.references"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_dist.references">References</a>
</h5>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
Wald, A. (1947). Sequential analysis. Wiley, NY.
</li>
<li class="listitem">
The Inverse Gaussian distribution : theory, methodology, and applications,
Raj S. Chhikara, J. Leroy Folks. ISBN 0824779975 (1989).
</li>
<li class="listitem">
The Inverse Gaussian distribution : statistical theory and applications,
Seshadri, V , ISBN - 0387986189 (pbk) (Dewey 519.2) (1998).
</li>
<li class="listitem">
<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.wald.html" target="_top">Numpy
and Scipy Documentation</a>.
</li>
<li class="listitem">
<a href="http://bm2.genes.nig.ac.jp/RGM2/R_current/library/statmod/man/invgauss.html" target="_top">R
statmod invgauss functions</a>.
</li>
<li class="listitem">
<a href="http://cran.r-project.org/web/packages/SuppDists/index.html" target="_top">R
SuppDists invGauss functions</a>. (Note that these R implementations
names differ in case).
</li>
<li class="listitem">
<a href="http://www.statsci.org/s/invgauss.html" target="_top">StatSci.org invgauss
help</a>.
</li>
<li class="listitem">
<a href="http://www.statsci.org/s/invgauss.statSci.org" target="_top">invgauss
R source</a>.
</li>
<li class="listitem">
<a href="http://www.biostat.wustl.edu/archives/html/s-news/2001-12/msg00144.html" target="_top">pwald,
qwald</a>.
</li>
<li class="listitem">
<a href="http://www.brighton-webs.co.uk/distributions/wald.asp" target="_top">Brighton
Webs wald</a>.
</li>
</ol></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="inverse_gamma_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="laplace_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,361 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Laplace Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="inverse_gaussian_dist.html" title="Inverse Gaussian (or Inverse Normal) Distribution">
<link rel="next" href="logistic_dist.html" title="Logistic 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="inverse_gaussian_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="logistic_dist.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.dist_ref.dists.laplace_dist"></a><a class="link" href="laplace_dist.html" title="Laplace Distribution">Laplace Distribution</a>
</h4></div></div></div>
<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">laplace</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">laplace_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">laplace_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">laplace</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">laplace_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="comment">// Construct:</span>
<span class="identifier">laplace_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
<span class="comment">// Accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
Laplace distribution is the distribution of differences between two independent
variates with identical exponential distributions (Abramowitz and Stegun
1972, p. 930). It is also called the double exponential distribution.
</p>
<p>
For location parameter &#956; &#160; and scale parameter &#963; &#160;, it is defined by the probability
density function:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/laplace_pdf.svg"></span>
</p>
<p>
The location and scale parameters are equivalent to the mean and standard
deviation of the normal or Gaussian distribution.
</p>
<p>
The following graph illustrates the effect of the parameters &#956; &#160; and &#963; &#160; on the
PDF. Note that the domain of the random variable remains [-&#8734;,+&#8734;] irrespective
of the value of the location parameter:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/laplace_pdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.laplace_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.laplace_dist.member_functions"></a></span><a class="link" href="laplace_dist.html#math_toolkit.dist_ref.dists.laplace_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">laplace_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
Constructs a laplace distribution with location <span class="emphasis"><em>location</em></span>
and scale <span class="emphasis"><em>scale</em></span>.
</p>
<p>
The location parameter is the same as the mean of the random variate.
</p>
<p>
The scale parameter is proportional to the standard deviation of the random
variate.
</p>
<p>
Requires that the scale parameter is greater than zero, otherwise calls
<a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>location</em></span> parameter of this distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>scale</em></span> parameter of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.laplace_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.laplace_dist.non_member_accessors"></a></span><a class="link" href="laplace_dist.html#math_toolkit.dist_ref.dists.laplace_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [-&#8734;,+&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.laplace_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.laplace_dist.accuracy"></a></span><a class="link" href="laplace_dist.html#math_toolkit.dist_ref.dists.laplace_dist.accuracy">Accuracy</a>
</h5>
<p>
The laplace distribution is implemented in terms of the standard library
log and exp functions and as such should have very small errors.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.laplace_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.laplace_dist.implementation"></a></span><a class="link" href="laplace_dist.html#math_toolkit.dist_ref.dists.laplace_dist.implementation">Implementation</a>
</h5>
<p>
In the following table &#956; is the location parameter of the distribution, &#963; is
its scale parameter, <span class="emphasis"><em>x</em></span> is the random variate, <span class="emphasis"><em>p</em></span>
is the probability and its complement <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 = e<sup>-abs(x-&#956;) / &#963;</sup> / (2 * &#963;)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relations:
</p>
<p>
x &lt; &#956; : p = e<sup>(x-&#956;)/&#963; </sup> / &#963;
</p>
<p>
x &gt;= &#956; : p = 1 - e<sup>(&#956;-x)/&#963; </sup> / &#963;
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
-x &lt; &#956; : q = e<sup>(-x-&#956;)/&#963; </sup> / &#963;
</p>
<p>
-x &gt;= &#956; : q = 1 - e<sup>(&#956;+x)/&#963; </sup> / &#963;
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relations:
</p>
<p>
p &lt; 0.5 : x = &#956; + &#963; * log(2*p)
</p>
<p>
p &gt;= 0.5 : x = &#956; - &#963; * log(2-2*p)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
q &gt; 0.5: x = &#956; + &#963;*log(2-2*q)
</p>
<p>
q &lt;=0.5: x = &#956; - &#963;*log( 2*q )
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
&#956;
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
2 * &#963;<sup>2</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
&#956;
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
6
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
3
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.laplace_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.laplace_dist.references"></a></span><a class="link" href="laplace_dist.html#math_toolkit.dist_ref.dists.laplace_dist.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://mathworld.wolfram.com/LaplaceDistribution.html" target="_top">Weisstein,
Eric W. "Laplace Distribution."</a> From MathWorld--A
Wolfram Web Resource.
</li>
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Laplace_distribution" target="_top">Laplace
Distribution</a>
</li>
<li class="listitem">
M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions,
1972, p. 930.
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="inverse_gaussian_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="logistic_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,299 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Logistic Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="laplace_dist.html" title="Laplace Distribution">
<link rel="next" href="lognormal_dist.html" title="Log Normal 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="laplace_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="lognormal_dist.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.dist_ref.dists.logistic_dist"></a><a class="link" href="logistic_dist.html" title="Logistic Distribution">Logistic
Distribution</a>
</h4></div></div></div>
<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">logistic</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">logistic_distribution</span><span class="special">;</span>
<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> <span class="identifier">Policy</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">logistic_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="comment">// Construct:</span>
<span class="identifier">logistic_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
<span class="comment">// Accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// location.</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// scale.</span>
<span class="special">};</span>
<span class="keyword">typedef</span> <span class="identifier">logistic_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">logistic</span><span class="special">;</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The logistic distribution is a continous probability distribution. It has
two parameters - location and scale. The cumulative distribution function
of the logistic distribution appears in logistic regression and feedforward
neural networks. Among other applications, United State Chess Federation
and FIDE use it to calculate chess ratings.
</p>
<p>
The following graph shows how the distribution changes as the parameters
change:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/logistic_pdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.logistic_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.logistic_dist.member_functions"></a></span><a class="link" href="logistic_dist.html#math_toolkit.dist_ref.dists.logistic_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">logistic_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">u</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">s</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
Constructs a logistic distribution with location <span class="emphasis"><em>u</em></span>
and scale <span class="emphasis"><em>s</em></span>.
</p>
<p>
Requires <code class="computeroutput"><span class="identifier">scale</span> <span class="special">&gt;</span>
<span class="number">0</span></code>, otherwise a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
is raised.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the location of this distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the scale of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.logistic_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.logistic_dist.non_member_accessors"></a></span><a class="link" href="logistic_dist.html#math_toolkit.dist_ref.dists.logistic_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [-[max_value], +[min_value]]. However,
the pdf and cdf support inputs of +&#8734; and -&#8734;
as special cases if RealType permits.
</p>
<p>
At <code class="computeroutput"><span class="identifier">p</span><span class="special">=</span><span class="number">1</span></code> and <code class="computeroutput"><span class="identifier">p</span><span class="special">=</span><span class="number">0</span></code>, the quantile
function returns the result of +<a class="link" href="../../error_handling.html#math_toolkit.error_handling.overflow_error">overflow_error</a>
and -<a class="link" href="../../error_handling.html#math_toolkit.error_handling.overflow_error">overflow_error</a>,
while the complement quantile function returns the result of -<a class="link" href="../../error_handling.html#math_toolkit.error_handling.overflow_error">overflow_error</a>
and +<a class="link" href="../../error_handling.html#math_toolkit.error_handling.overflow_error">overflow_error</a>
respectively.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.logistic_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.logistic_dist.accuracy"></a></span><a class="link" href="logistic_dist.html#math_toolkit.dist_ref.dists.logistic_dist.accuracy">Accuracy</a>
</h5>
<p>
The logistic distribution is implemented in terms of the <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">exp</span></code> and the <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">log</span></code>
functions, so its accuracy is related to the accurate implementations of
those functions on a given platform. When calculating the quantile with
a non-zero <span class="emphasis"><em>position</em></span> parameter catastrophic cancellation
errors can occur: in such cases, only a low <span class="emphasis"><em>absolute error</em></span>
can be guaranteed.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.logistic_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.logistic_dist.implementation"></a></span><a class="link" href="logistic_dist.html#math_toolkit.dist_ref.dists.logistic_dist.implementation">Implementation</a>
</h5>
<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 = e<sup>-(x-u)/s</sup> / (s*(1+e<sup>-(x-u)/s</sup>)<sup>2</sup>)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = 1/(1+e<sup>-(x-u)/s</sup>)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = 1/(1+e<sup>(x-u)/s</sup>)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = u - s*log(1/p-1)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = u + s*log(p/1-p)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
u
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
The same as the mean.
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
6/5
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
(&#960;*s)<sup>2</sup> / 3
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="laplace_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="lognormal_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,331 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Log Normal Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="logistic_dist.html" title="Logistic Distribution">
<link rel="next" href="negative_binomial_dist.html" title="Negative Binomial 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="logistic_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="negative_binomial_dist.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.dist_ref.dists.lognormal_dist"></a><a class="link" href="lognormal_dist.html" title="Log Normal Distribution">Log Normal
Distribution</a>
</h4></div></div></div>
<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">lognormal</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">lognormal_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">lognormal_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">lognormal</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">lognormal_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="comment">// Construct:</span>
<span class="identifier">lognormal_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
<span class="comment">// Accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The lognormal distribution is the distribution that arises when the logarithm
of the random variable is normally distributed. A lognormal distribution
results when the variable is the product of a large number of independent,
identically-distributed variables.
</p>
<p>
For location and scale parameters <span class="emphasis"><em>m</em></span> and <span class="emphasis"><em>s</em></span>
it is defined by the probability density function:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/lognormal_ref.svg"></span>
</p>
<p>
The location and scale parameters are equivalent to the mean and standard
deviation of the logarithm of the random variable.
</p>
<p>
The following graph illustrates the effect of the location parameter on
the PDF, note that the range of the random variable remains [0,+&#8734;] irrespective
of the value of the location parameter:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/lognormal_pdf1.svg" align="middle"></span>
</p>
<p>
The next graph illustrates the effect of the scale parameter on the PDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/lognormal_pdf2.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.lognormal_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.lognormal_dist.member_functions"></a></span><a class="link" href="lognormal_dist.html#math_toolkit.dist_ref.dists.lognormal_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">lognormal_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
Constructs a lognormal distribution with location <span class="emphasis"><em>location</em></span>
and scale <span class="emphasis"><em>scale</em></span>.
</p>
<p>
The location parameter is the same as the mean of the logarithm of the
random variate.
</p>
<p>
The scale parameter is the same as the standard deviation of the logarithm
of the random variate.
</p>
<p>
Requires that the scale parameter is greater than zero, otherwise calls
<a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>location</em></span> parameter of this distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>scale</em></span> parameter of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.lognormal_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.lognormal_dist.non_member_accessors"></a></span><a class="link" href="lognormal_dist.html#math_toolkit.dist_ref.dists.lognormal_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [0,+&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.lognormal_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.lognormal_dist.accuracy"></a></span><a class="link" href="lognormal_dist.html#math_toolkit.dist_ref.dists.lognormal_dist.accuracy">Accuracy</a>
</h5>
<p>
The lognormal distribution is implemented in terms of the standard library
log and exp functions, plus the <a class="link" href="../../sf_erf/error_function.html" title="Error Functions">error
function</a>, and as such should have very low error rates.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.lognormal_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.lognormal_dist.implementation"></a></span><a class="link" href="lognormal_dist.html#math_toolkit.dist_ref.dists.lognormal_dist.implementation">Implementation</a>
</h5>
<p>
In the following table <span class="emphasis"><em>m</em></span> is the location parameter
of the distribution, <span class="emphasis"><em>s</em></span> is its scale 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 = e<sup>-(ln(x) - m)<sup>2 </sup> / 2s<sup>2 </sup> </sup> / (x * s * sqrt(2pi))
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = cdf(normal_distribtion&lt;RealType&gt;(m,
s), log(x))
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = cdf(complement(normal_distribtion&lt;RealType&gt;(m,
s), log(x)))
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = exp(quantile(normal_distribtion&lt;RealType&gt;(m,
s), p))
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = exp(quantile(complement(normal_distribtion&lt;RealType&gt;(m,
s), q)))
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
e<sup>m + s<sup>2 </sup> / 2 </sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
(e<sup>s<sup>2</sup> </sup> - 1) * e<sup>2m + s<sup>2 </sup> </sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
e<sup>m - s<sup>2 </sup> </sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
sqrt(e<sup>s<sup>2</sup> </sup> - 1) * (2 + e<sup>s<sup>2</sup> </sup>)
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
e<sup>4s<sup>2</sup> </sup> + 2e<sup>3s<sup>2</sup> </sup> + 3e<sup>2s<sup>2</sup> </sup> - 3
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
e<sup>4s<sup>2</sup> </sup> + 2e<sup>3s<sup>2</sup> </sup> + 3e<sup>2s<sup>2</sup> </sup> - 6
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="logistic_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="negative_binomial_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,485 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Noncentral Beta Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="negative_binomial_dist.html" title="Negative Binomial Distribution">
<link rel="next" href="nc_chi_squared_dist.html" title="Noncentral Chi-Squared 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="negative_binomial_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="nc_chi_squared_dist.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.dist_ref.dists.nc_beta_dist"></a><a class="link" href="nc_beta_dist.html" title="Noncentral Beta Distribution">Noncentral
Beta Distribution</a>
</h4></div></div></div>
<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">non_central_beta</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">non_central_beta_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">non_central_beta_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">non_central_beta</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">non_central_beta_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="comment">// Constructor:</span>
<span class="identifier">non_central_beta_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">);</span>
<span class="comment">// Accessor to shape parameters:</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Accessor to non-centrality parameter lambda:</span>
<span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The noncentral beta distribution is a generalization of the <a class="link" href="beta_dist.html" title="Beta Distribution">Beta
Distribution</a>.
</p>
<p>
It is defined as the ratio X = &#967;<sub>m</sub><sup>2</sup>(&#955;) / (&#967;<sub>m</sub><sup>2</sup>(&#955;) + &#967;<sub>n</sub><sup>2</sup>) where &#967;<sub>m</sub><sup>2</sup>(&#955;) is a noncentral
&#967;<sup>2</sup>
random variable with <span class="emphasis"><em>m</em></span> degrees of freedom, and &#967;<sub>n</sub><sup>2</sup>
is
a central &#967;<sup>2</sup> random variable with <span class="emphasis"><em>n</em></span> degrees of freedom.
</p>
<p>
This gives a PDF that can be expressed as a Poisson mixture of beta distribution
PDFs:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref1.svg"></span>
</p>
<p>
where P(i;&#955;/2) is the discrete Poisson probablity at <span class="emphasis"><em>i</em></span>,
with mean &#955;/2, and I<sub>x</sub><sup>'</sup>(&#945;, &#946;) is the derivative of the incomplete beta function.
This leads to the usual form of the CDF as:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref2.svg"></span>
</p>
<p>
The following graph illustrates how the distribution changes for different
values of &#955;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/nc_beta_pdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_beta_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.member_functions"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">non_central_beta_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">);</span>
</pre>
<p>
Constructs a noncentral beta distribution with shape parameters <span class="emphasis"><em>a</em></span>
and <span class="emphasis"><em>b</em></span> and non-centrality parameter <span class="emphasis"><em>lambda</em></span>.
</p>
<p>
Requires a &gt; 0, b &gt; 0 and lambda &gt;= 0, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>a</em></span> from which this object was
constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>b</em></span> from which this object was
constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>lambda</em></span> from which this object
was constructed.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_beta_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.non_member_accessors"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.non_member_accessors">Non-member
Accessors</a>
</h5>
<p>
Most of the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member
accessor functions</a> are supported: <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative
Distribution Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability
Density Function</a>, <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.mean">mean</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.median">median</a>, <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.hazard">Hazard Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.chf">Cumulative Hazard Function</a>,
<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>.
</p>
<p>
Mean and variance are implemented using hypergeometric pfq functions and
relations given in <a href="http://reference.wolfram.com/mathematica/ref/NoncentralBetaDistribution.html" target="_top">Wolfram
Noncentral Beta Distribution</a>.
</p>
<p>
However, the following are not currently implemented: <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> and
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>.
</p>
<p>
The domain of the random variable is [0, 1].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_beta_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.accuracy"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.accuracy">Accuracy</a>
</h5>
<p>
The following table shows the peak errors (in units of <a href="http://en.wikipedia.org/wiki/Machine_epsilon" target="_top">epsilon</a>)
found on various platforms with various floating point types. The failures
in the comparison to the <a href="http://www.r-project.org/" target="_top">R Math
library</a>, seem to be mostly in the corner cases when the probablity
would be very small. Unless otherwise specified any floating-point type
that is narrower than the one shown will have <a class="link" href="../../relative_error.html#math_toolkit.relative_error.zero_error">effectively
zero error</a>.
</p>
<div class="table">
<a name="math_toolkit.dist_ref.dists.nc_beta_dist.table_non_central_beta_CDF"></a><p class="title"><b>Table&#160;5.4.&#160;Error rates for non central beta CDF</b></p>
<div class="table-contents"><table class="table" summary="Error rates for non central beta CDF">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
</th>
<th>
<p>
Microsoft Visual C++ version 12.0<br> Win32<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5130<br> Sun Solaris<br> long double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Non Central Beta, medium parameters
</p>
</td>
<td>
<p>
<span class="blue">Max = 240&#949; (Mean = 31&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.998&#949; (Mean = 0.0659&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> <span class="red">Max
= 1.46e+26&#949; (Mean = 3.5e+24&#949;) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_double_non_central_beta_CDF_Rmath_3_0_2_Non_Central_Beta_medium_parameters">And
other failures.</a>)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 825&#949; (Mean = 27.4&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 832&#949; (Mean = 38.1&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
Non Central Beta, large parameters
</p>
</td>
<td>
<p>
<span class="blue">Max = 3.41e+003&#949; (Mean = 475&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 1.18&#949; (Mean = 0.175&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> <span class="red">Max
= 1.01e+36&#949; (Mean = 1.19e+35&#949;) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_double_non_central_beta_CDF_Rmath_3_0_2_Non_Central_Beta_large_parameters">And
other failures.</a>)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.5e+04&#949; (Mean = 3.78e+03&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.57e+04&#949; (Mean = 4.43e+03&#949;)</span>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="table">
<a name="math_toolkit.dist_ref.dists.nc_beta_dist.table_non_central_beta_CDF_complement"></a><p class="title"><b>Table&#160;5.5.&#160;Error rates for non central beta CDF complement</b></p>
<div class="table-contents"><table class="table" summary="Error rates for non central beta CDF complement">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
</th>
<th>
<p>
Microsoft Visual C++ version 12.0<br> Win32<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5130<br> Sun Solaris<br> long double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Non Central Beta, medium parameters
</p>
</td>
<td>
<p>
<span class="blue">Max = 619&#949; (Mean = 62.7&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.998&#949; (Mean = 0.0957&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> <span class="red">Max
= 7.5e+97&#949; (Mean = 1.37e+96&#949;) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_double_non_central_beta_CDF_complement_Rmath_3_0_2_Non_Central_Beta_medium_parameters">And
other failures.</a>)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 396&#949; (Mean = 50.7&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 554&#949; (Mean = 57.3&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
Non Central Beta, large parameters
</p>
</td>
<td>
<p>
<span class="blue">Max = 8.67e+003&#949; (Mean = 1.04e+003&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.986&#949; (Mean = 0.188&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> <span class="red">Max
= +INF&#949; (Mean = +INF&#949;) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_double_non_central_beta_CDF_complement_Rmath_3_0_2_Non_Central_Beta_large_parameters">And
other failures.</a>)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 6.83e+03&#949; (Mean = 993&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 3.56e+03&#949; (Mean = 704&#949;)</span>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
Error rates for the PDF, the complement of the CDF and for the quantile
functions are broadly similar.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_beta_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.tests"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.tests">Tests</a>
</h5>
<p>
There are two sets of test data used to verify this implementation: firstly
we can compare with a few sample values generated by the <a href="http://www.r-project.org/" target="_top">R
library</a>. Secondly, we have tables of test data, computed with this
implementation and using interval arithmetic - this data should be accurate
to at least 50 decimal digits - and is the used for our accuracy tests.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_beta_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.implementation"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.implementation">Implementation</a>
</h5>
<p>
The CDF and its complement are evaluated as follows:
</p>
<p>
First we determine which of the two values (the CDF or its complement)
is likely to be the smaller, the crossover point is taken to be the mean
of the distribution: for this we use the approximation due to: R. Chattamvelli
and R. Shanmugam, "Algorithm AS 310: Computing the Non-Central Beta
Distribution Function", Applied Statistics, Vol. 46, No. 1. (1997),
pp. 146-156.
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref3.svg"></span>
</p>
<p>
Then either the CDF or its complement is computed using the relations:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref4.svg"></span>
</p>
<p>
The summation is performed by starting at i = &#955;/2, and then recursing in
both directions, using the usual recurrence relations for the Poisson PDF
and incomplete beta functions. This is the "Method 2" described
by:
</p>
<p>
Denise Benton and K. Krishnamoorthy, "Computing discrete mixtures
of continuous distributions: noncentral chisquare, noncentral t and the
distribution of the square of the sample multiple correlation coefficient",
Computational Statistics &amp; Data Analysis 43 (2003) 249-267.
</p>
<p>
Specific applications of the above formulae to the noncentral beta distribution
can be found in:
</p>
<p>
Russell V. Lenth, "Algorithm AS 226: Computing Noncentral Beta Probabilities",
Applied Statistics, Vol. 36, No. 2. (1987), pp. 241-244.
</p>
<p>
H. Frick, "Algorithm AS R84: A Remark on Algorithm AS 226: Computing
Non-Central Beta Probabilities", Applied Statistics, Vol. 39, No.
2. (1990), pp. 311-312.
</p>
<p>
Ming Long Lam, "Remark AS R95: A Remark on Algorithm AS 226: Computing
Non-Central Beta Probabilities", Applied Statistics, Vol. 44, No.
4. (1995), pp. 551-552.
</p>
<p>
Harry O. Posten, "An Effective Algorithm for the Noncentral Beta Distribution
Function", The American Statistician, Vol. 47, No. 2. (May, 1993),
pp. 129-131.
</p>
<p>
R. Chattamvelli, "A Note on the Noncentral Beta Distribution Function",
The American Statistician, Vol. 49, No. 2. (May, 1995), pp. 231-234.
</p>
<p>
Of these, the Posten reference provides the most complete overview, and
includes the modification starting iteration at &#955;/2.
</p>
<p>
The main difference between this implementation and the above references
is the direct computation of the complement when most efficient to do so,
and the accumulation of the sum to -1 rather than subtracting the result
from 1 at the end: this can substantially reduce the number of iterations
required when the result is near 1.
</p>
<p>
The PDF is computed using the methodology of Benton and Krishnamoorthy
and the relation:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref1.svg"></span>
</p>
<p>
Quantiles are computed using a specially modified version of <a class="link" href="../../roots_noderiv/bracket_solve.html" title="Bracket and Solve Root">bracket
and solve</a>, starting the search for the root at the mean of the distribution.
(A Cornish-Fisher type expansion was also tried, but while this gets quite
close to the root in many cases, when it is wrong it tends to introduce
quite pathological behaviour: more investigation in this area is probably
warranted).
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="negative_binomial_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="nc_chi_squared_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,573 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Noncentral Chi-Squared Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="nc_beta_dist.html" title="Noncentral Beta Distribution">
<link rel="next" href="nc_f_dist.html" title="Noncentral F 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="nc_beta_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="nc_f_dist.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.dist_ref.dists.nc_chi_squared_dist"></a><a class="link" href="nc_chi_squared_dist.html" title="Noncentral Chi-Squared Distribution">Noncentral
Chi-Squared Distribution</a>
</h4></div></div></div>
<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">non_central_chi_squared</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">non_central_chi_squared_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">non_central_chi_squared_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">non_central_chi_squared</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">non_central_chi_squared_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="comment">// Constructor:</span>
<span class="identifier">non_central_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">);</span>
<span class="comment">// Accessor to degrees of freedom parameter v:</span>
<span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Accessor to non centrality parameter lambda:</span>
<span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Parameter finders:</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">&gt;</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">complemented3_type</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">C</span><span class="special">&gt;&amp;</span> <span class="identifier">c</span><span class="special">);</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_non_centrality</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">&gt;</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_non_centrality</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">complemented3_type</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">C</span><span class="special">&gt;&amp;</span> <span class="identifier">c</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The noncentral chi-squared distribution is a generalization of the <a class="link" href="chi_squared_dist.html" title="Chi Squared Distribution">Chi Squared Distribution</a>.
If X<sub>i</sub> are &#957; independent, normally distributed random variables with means
&#956;<sub>i</sub> and variances &#963;<sub>i</sub><sup>2</sup>, then the random variable
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref1.svg"></span>
</p>
<p>
is distributed according to the noncentral chi-squared distribution.
</p>
<p>
The noncentral chi-squared distribution has two parameters: &#957; which specifies
the number of degrees of freedom (i.e. the number of X<sub>i</sub>), and &#955; which is
related to the mean of the random variables X<sub>i</sub> by:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref2.svg"></span>
</p>
<p>
(Note that some references define &#955; as one half of the above sum).
</p>
<p>
This leads to a PDF of:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref3.svg"></span>
</p>
<p>
where <span class="emphasis"><em>f(x;k)</em></span> is the central chi-squared distribution
PDF, and <span class="emphasis"><em>I<sub>v</sub>(x)</em></span> is a modified Bessel function of the
first kind.
</p>
<p>
The following graph illustrates how the distribution changes for different
values of &#955;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/nccs_pdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.member_functions"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">non_central_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">);</span>
</pre>
<p>
Constructs a Chi-Squared distribution with <span class="emphasis"><em>v</em></span> degrees
of freedom and non-centrality parameter <span class="emphasis"><em>lambda</em></span>.
</p>
<p>
Requires v &gt; 0 and lambda &gt;= 0, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>v</em></span> from which this object was
constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>lambda</em></span> from which this object
was constructed.
</p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
</pre>
<p>
This function returns the number of degrees of freedom <span class="emphasis"><em>v</em></span>
such that: <code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">non_central_chi_squared</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">,</span> <span class="identifier">Policy</span><span class="special">&gt;(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">),</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">p</span></code>
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">&gt;</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">complemented3_type</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">C</span><span class="special">&gt;&amp;</span> <span class="identifier">c</span><span class="special">);</span>
</pre>
<p>
When called with argument <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span>
<span class="identifier">q</span><span class="special">)</span></code>
this function returns the number of degrees of freedom <span class="emphasis"><em>v</em></span>
such that:
</p>
<p>
<code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">non_central_chi_squared</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">,</span> <span class="identifier">Policy</span><span class="special">&gt;(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">),</span> <span class="identifier">x</span><span class="special">))</span> <span class="special">==</span> <span class="identifier">q</span></code>.
</p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_non_centrality</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
</pre>
<p>
This function returns the non centrality parameter <span class="emphasis"><em>lambda</em></span>
such that:
</p>
<p>
<code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">non_central_chi_squared</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">,</span> <span class="identifier">Policy</span><span class="special">&gt;(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">),</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">p</span></code>
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">&gt;</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_non_centrality</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">complemented3_type</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">C</span><span class="special">&gt;&amp;</span> <span class="identifier">c</span><span class="special">);</span>
</pre>
<p>
When called with argument <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span>
<span class="identifier">x</span><span class="special">,</span>
<span class="identifier">q</span><span class="special">)</span></code>
this function returns the non centrality parameter <span class="emphasis"><em>lambda</em></span>
such that:
</p>
<p>
<code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">non_central_chi_squared</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">,</span> <span class="identifier">Policy</span><span class="special">&gt;(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">),</span> <span class="identifier">x</span><span class="special">))</span> <span class="special">==</span> <span class="identifier">q</span></code>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.non_member_accessors"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [0, +&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.examples"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.examples">Examples</a>
</h5>
<p>
There is a <a class="link" href="../../stat_tut/weg/nccs_eg.html" title="Non Central Chi Squared Example">worked example</a>
for the noncentral chi-squared distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.accuracy"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.accuracy">Accuracy</a>
</h5>
<p>
The following table shows the peak errors (in units of <a href="http://en.wikipedia.org/wiki/Machine_epsilon" target="_top">epsilon</a>)
found on various platforms with various floating point types. The failures
in the comparison to the <a href="http://www.r-project.org/" target="_top">R Math
library</a>, seem to be mostly in the corner cases when the probablity
would be very small. Unless otherwise specified any floating-point type
that is narrower than the one shown will have <a class="link" href="../../relative_error.html#math_toolkit.relative_error.zero_error">effectively
zero error</a>.
</p>
<div class="table">
<a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.table_non_central_chi_squared_CDF"></a><p class="title"><b>Table&#160;5.6.&#160;Error rates for non central chi squared CDF</b></p>
<div class="table-contents"><table class="table" summary="Error rates for non central chi squared CDF">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
</th>
<th>
<p>
Microsoft Visual C++ version 12.0<br> Win32<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5130<br> Sun Solaris<br> long double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Non Central Chi Squared, medium parameters
</p>
</td>
<td>
<p>
<span class="blue">Max = 48.9&#949; (Mean = 10&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.99&#949; (Mean = 0.0529&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> Max = 727&#949; (Mean = 121&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 46.5&#949; (Mean = 10.3&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 115&#949; (Mean = 13.9&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
Non Central Chi Squared, large parameters
</p>
</td>
<td>
<p>
<span class="blue">Max = 9.79e+003&#949; (Mean = 723&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 1.07&#949; (Mean = 0.102&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> <span class="red">Max
= 3.27e+08&#949; (Mean = 2.23e+07&#949;))</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 3.07e+03&#949; (Mean = 336&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 6.17e+03&#949; (Mean = 677&#949;)</span>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="table">
<a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.table_non_central_chi_squared_CDF_complement"></a><p class="title"><b>Table&#160;5.7.&#160;Error rates for non central chi squared CDF complement</b></p>
<div class="table-contents"><table class="table" summary="Error rates for non central chi squared CDF complement">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
</th>
<th>
<p>
Microsoft Visual C++ version 12.0<br> Win32<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5130<br> Sun Solaris<br> long double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Non Central Chi Squared, medium parameters
</p>
</td>
<td>
<p>
<span class="blue">Max = 98.6&#949; (Mean = 15.8&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.96&#949; (Mean = 0.0635&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> <span class="red">Max
= +INF&#949; (Mean = +INF&#949;) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_double_non_central_chi_squared_CDF_complement_Rmath_3_0_2_Non_Central_Chi_Squared_medium_parameters">And
other failures.</a>)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 107&#949; (Mean = 17.1&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 171&#949; (Mean = 22.8&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
Non Central Chi Squared, large parameters
</p>
</td>
<td>
<p>
<span class="blue">Max = 5.43e+003&#949; (Mean = 705&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.11&#949; (Mean = 0.278&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> <span class="red">Max
= +INF&#949; (Mean = +INF&#949;) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_double_non_central_chi_squared_CDF_complement_Rmath_3_0_2_Non_Central_Chi_Squared_large_parameters">And
other failures.</a>)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 5.02e+03&#949; (Mean = 630&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 5.1e+03&#949; (Mean = 577&#949;)</span>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
Error rates for the quantile functions are broadly similar. Special mention
should go to the <code class="computeroutput"><span class="identifier">mode</span></code> function:
there is no closed form for this function, so it is evaluated numerically
by finding the maxima of the PDF: in principal this can not produce an
accuracy greater than the square root of the machine epsilon.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.tests"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.tests">Tests</a>
</h5>
<p>
There are two sets of test data used to verify this implementation: firstly
we can compare with published data, for example with Table 6 of "Self-Validating
Computations of Probabilities for Selected Central and Noncentral Univariate
Probability Functions", Morgan C. Wang and William J. Kennedy, Journal
of the American Statistical Association, Vol. 89, No. 427. (Sep., 1994),
pp. 878-887. Secondly, we have tables of test data, computed with this
implementation and using interval arithmetic - this data should be accurate
to at least 50 decimal digits - and is the used for our accuracy tests.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.implementation"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.implementation">Implementation</a>
</h5>
<p>
The CDF and its complement are evaluated as follows:
</p>
<p>
First we determine which of the two values (the CDF or its complement)
is likely to be the smaller: for this we can use the relation due to Temme
(see "Asymptotic and Numerical Aspects of the Noncentral Chi-Square
Distribution", N. M. Temme, Computers Math. Applic. Vol 25, No. 5,
55-63, 1993) that:
</p>
<p>
F(&#957;,&#955;;&#957;+&#955;) &#8776; 0.5
</p>
<p>
and so compute the CDF when the random variable is less than &#957;+&#955;, and its
complement when the random variable is greater than &#957;+&#955;. If necessary the
computed result is then subtracted from 1 to give the desired result (the
CDF or its complement).
</p>
<p>
For small values of the non centrality parameter, the CDF is computed using
the method of Ding (see "Algorithm AS 275: Computing the Non-Central
#2 Distribution Function", Cherng G. Ding, Applied Statistics, Vol.
41, No. 2. (1992), pp. 478-482). This uses the following series representation:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref4.svg"></span>
</p>
<p>
which requires just one call to <a class="link" href="../../sf_gamma/gamma_derivatives.html" title="Derivative of the Incomplete Gamma Function">gamma_p_derivative</a>
with the subsequent terms being computed by recursion as shown above.
</p>
<p>
For larger values of the non-centrality parameter, Ding's method can take
an unreasonable number of terms before convergence is achieved. Furthermore,
the largest term is not the first term, so in extreme cases the first term
may be zero, leading to a zero result, even though the true value may be
non-zero.
</p>
<p>
Therefore, when the non-centrality parameter is greater than 200, the method
due to Krishnamoorthy (see "Computing discrete mixtures of continuous
distributions: noncentral chisquare, noncentral t and the distribution
of the square of the sample multiple correlation coefficient", Denise
Benton and K. Krishnamoorthy, Computational Statistics &amp; Data Analysis,
43, (2003), 249-267) is used.
</p>
<p>
This method uses the well known sum:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref5.svg"></span>
</p>
<p>
Where P<sub>a</sub>(x) is the incomplete gamma function.
</p>
<p>
The method starts at the &#955;th term, which is where the Poisson weighting
function achieves its maximum value, although this is not necessarily the
largest overall term. Subsequent terms are calculated via the normal recurrence
relations for the incomplete gamma function, and iteration proceeds both
forwards and backwards until sufficient precision has been achieved. It
should be noted that recurrence in the forwards direction of P<sub>a</sub>(x) is numerically
unstable. However, since we always start <span class="emphasis"><em>after</em></span> the
largest term in the series, numeric instability is introduced more slowly
than the series converges.
</p>
<p>
Computation of the complement of the CDF uses an extension of Krishnamoorthy's
method, given that:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref6.svg"></span>
</p>
<p>
we can again start at the &#955;'th term and proceed in both directions from
there until the required precision is achieved. This time it is backwards
recursion on the incomplete gamma function Q<sub>a</sub>(x) which is unstable. However,
as long as we start well <span class="emphasis"><em>before</em></span> the largest term,
this is not an issue in practice.
</p>
<p>
The PDF is computed directly using the relation:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref3.svg"></span>
</p>
<p>
Where <span class="emphasis"><em>f(x; v)</em></span> is the PDF of the central <a class="link" href="chi_squared_dist.html" title="Chi Squared Distribution">Chi
Squared Distribution</a> and <span class="emphasis"><em>I<sub>v</sub>(x)</em></span> is a modified
Bessel function, see <a class="link" href="../../bessel/mbessel.html" title="Modified Bessel Functions of the First and Second Kinds">cyl_bessel_i</a>.
For small values of the non-centrality parameter the relation in terms
of <a class="link" href="../../bessel/mbessel.html" title="Modified Bessel Functions of the First and Second Kinds">cyl_bessel_i</a> is used.
However, this method fails for large values of the non-centrality parameter,
so in that case the infinite sum is evaluated using the method of Benton
and Krishnamoorthy, and the usual recurrence relations for successive terms.
</p>
<p>
The quantile functions are computed by numeric inversion of the CDF. An
improve starting quess is from Thomas Luu, <a href="http://discovery.ucl.ac.uk/1482128/%2c" target="_top">Fast
and accurate parallel computation of quantile functions for random number
generation, Doctorial Thesis, 2016</a>.
</p>
<p>
There is no <a href="http://en.wikipedia.org/wiki/Closed_form" target="_top">closed
form</a> for the mode of the noncentral chi-squared distribution: it
is computed numerically by finding the maximum of the PDF. Likewise, the
median is computed numerically via the quantile.
</p>
<p>
The remaining non-member functions use the following formulas:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref7.svg"></span>
</p>
<p>
Some analytic properties of noncentral distributions (particularly unimodality,
and monotonicity of their modes) are surveyed and summarized by:
</p>
<p>
Andrea van Aubel &amp; Wolfgang Gawronski, Applied Mathematics and Computation,
141 (2003) 3-12.
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="nc_beta_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="nc_f_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,411 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Noncentral F Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="nc_chi_squared_dist.html" title="Noncentral Chi-Squared Distribution">
<link rel="next" href="nc_t_dist.html" title="Noncentral T 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="nc_chi_squared_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="nc_t_dist.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.dist_ref.dists.nc_f_dist"></a><a class="link" href="nc_f_dist.html" title="Noncentral F Distribution">Noncentral F
Distribution</a>
</h4></div></div></div>
<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">non_central_f</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">non_central_f_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">non_central_f_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">non_central_f</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">non_central_f_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="comment">// Constructor:</span>
<span class="identifier">non_central_f_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">v2</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">);</span>
<span class="comment">// Accessor to degrees_of_freedom parameters v1 &amp; v2:</span>
<span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom1</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom2</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Accessor to non-centrality parameter lambda:</span>
<span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The noncentral F distribution is a generalization of the <a class="link" href="f_dist.html" title="F Distribution">Fisher
F Distribution</a>. It is defined as the ratio
</p>
<pre class="programlisting"><span class="identifier">F</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">X</span><span class="special">/</span><span class="identifier">v1</span><span class="special">)</span> <span class="special">/</span> <span class="special">(</span><span class="identifier">Y</span><span class="special">/</span><span class="identifier">v2</span><span class="special">)</span>
</pre>
<p>
where X is a noncentral &#967;<sup>2</sup>
random variable with <span class="emphasis"><em>v1</em></span> degrees
of freedom and non-centrality parameter &#955;, and Y is a central &#967;<sup>2</sup> random variable
with <span class="emphasis"><em>v2</em></span> degrees of freedom.
</p>
<p>
This gives the following PDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_f_ref1.svg"></span>
</p>
<p>
where L<sub>a</sub><sup>b</sup>(c) is a generalised Laguerre polynomial and B(a,b) is the <a class="link" href="../../sf_beta/beta_function.html" title="Beta">beta</a> function, or
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_f_ref2.svg"></span>
</p>
<p>
The following graph illustrates how the distribution changes for different
values of &#955;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/nc_f_pdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_f_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_f_dist.member_functions"></a></span><a class="link" href="nc_f_dist.html#math_toolkit.dist_ref.dists.nc_f_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">non_central_f_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">v2</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">);</span>
</pre>
<p>
Constructs a non-central beta distribution with parameters <span class="emphasis"><em>v1</em></span>
and <span class="emphasis"><em>v2</em></span> and non-centrality parameter <span class="emphasis"><em>lambda</em></span>.
</p>
<p>
Requires v1 &gt; 0, v2 &gt; 0 and lambda &gt;= 0, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom1</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>v1</em></span> from which this object was
constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom2</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>v2</em></span> from which this object was
constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the non-centrality parameter <span class="emphasis"><em>lambda</em></span> from which
this object was constructed.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_f_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_f_dist.non_member_accessors"></a></span><a class="link" href="nc_f_dist.html#math_toolkit.dist_ref.dists.nc_f_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [0, +&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_f_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_f_dist.accuracy"></a></span><a class="link" href="nc_f_dist.html#math_toolkit.dist_ref.dists.nc_f_dist.accuracy">Accuracy</a>
</h5>
<p>
This distribution is implemented in terms of the <a class="link" href="nc_beta_dist.html" title="Noncentral Beta Distribution">Noncentral
Beta Distribution</a>: refer to that distribution for accuracy data.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_f_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_f_dist.tests"></a></span><a class="link" href="nc_f_dist.html#math_toolkit.dist_ref.dists.nc_f_dist.tests">Tests</a>
</h5>
<p>
Since this distribution is implemented by adapting another distribution,
the tests consist of basic sanity checks computed by the <a href="http://www.r-project.org/" target="_top">R-2.5.1
Math library statistical package</a> and its pbeta and dbeta functions.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_f_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_f_dist.implementation"></a></span><a class="link" href="nc_f_dist.html#math_toolkit.dist_ref.dists.nc_f_dist.implementation">Implementation</a>
</h5>
<p>
In the following table <span class="emphasis"><em>v1</em></span> and <span class="emphasis"><em>v2</em></span>
are the first and second degrees of freedom parameters of the distribution,
&#955;
is the non-centrality 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>
Implemented in terms of the non-central beta PDF using the relation:
</p>
<p>
f(x;v1,v2;&#955;) = (v1/v2) / ((1+y)*(1+y)) * g(y/(1+y);v1/2,v2/2;&#955;)
</p>
<p>
where g(x; a, b; &#955;) is the non central beta PDF, and:
</p>
<p>
y = x * v1 / v2
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
p = B<sub>y</sub>(v1/2, v2/2; &#955;)
</p>
<p>
where B<sub>x</sub>(a, b; &#955;) is the noncentral beta distribution CDF and
</p>
<p>
y = x * v1 / v2
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
q = 1 - B<sub>y</sub>(v1/2, v2/2; &#955;)
</p>
<p>
where 1 - B<sub>x</sub>(a, b; &#955;) is the complement of the noncentral beta
distribution CDF and
</p>
<p>
y = x * v1 / v2
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
x = (bx / (1-bx)) * (v1 / v2)
</p>
<p>
where
</p>
<p>
bx = Q<sub>p</sub><sup>-1</sup>(v1/2, v2/2; &#955;)
</p>
<p>
and
</p>
<p>
Q<sub>p</sub><sup>-1</sup>(v1/2, v2/2; &#955;)
</p>
<p>
is the noncentral beta quantile.
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
<p>
from the complement
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
x = (bx / (1-bx)) * (v1 / v2)
</p>
<p>
where
</p>
<p>
bx = QC<sub>q</sub><sup>-1</sup>(v1/2, v2/2; &#955;)
</p>
<p>
and
</p>
<p>
QC<sub>q</sub><sup>-1</sup>(v1/2, v2/2; &#955;)
</p>
<p>
is the noncentral beta quantile from the complement.
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
v2 * (v1 + l) / (v1 * (v2 - 2))
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
By numeric maximalisation of the PDF.
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
Refer to, <a href="http://mathworld.wolfram.com/NoncentralF-Distribution.html" target="_top">Weisstein,
Eric W. "Noncentral F-Distribution." From MathWorld--A
Wolfram Web Resource.</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
Refer to, <a href="http://mathworld.wolfram.com/NoncentralF-Distribution.html" target="_top">Weisstein,
Eric W. "Noncentral F-Distribution." From MathWorld--A
Wolfram Web Resource.</a>, and to the <a href="http://reference.wolfram.com/mathematica/ref/NoncentralFRatioDistribution.html" target="_top">Mathematica
documentation</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis and kurtosis excess
</p>
</td>
<td>
<p>
Refer to, <a href="http://mathworld.wolfram.com/NoncentralF-Distribution.html" target="_top">Weisstein,
Eric W. "Noncentral F-Distribution." From MathWorld--A
Wolfram Web Resource.</a>, and to the <a href="http://reference.wolfram.com/mathematica/ref/NoncentralFRatioDistribution.html" target="_top">Mathematica
documentation</a>
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
Some analytic properties of noncentral distributions (particularly unimodality,
and monotonicity of their modes) are surveyed and summarized by:
</p>
<p>
Andrea van Aubel &amp; Wolfgang Gawronski, Applied Mathematics and Computation,
141 (2003) 3-12.
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="nc_chi_squared_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="nc_t_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,567 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Noncentral T Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="nc_f_dist.html" title="Noncentral F Distribution">
<link rel="next" href="normal_dist.html" title="Normal (Gaussian) 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="nc_f_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="normal_dist.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.dist_ref.dists.nc_t_dist"></a><a class="link" href="nc_t_dist.html" title="Noncentral T Distribution">Noncentral T
Distribution</a>
</h4></div></div></div>
<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">non_central_t</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">non_central_t_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">non_central_t_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">non_central_t</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">non_central_t_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="comment">// Constructor:</span>
<span class="identifier">non_central_t_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">delta</span><span class="special">);</span>
<span class="comment">// Accessor to degrees_of_freedom parameter v:</span>
<span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Accessor to non-centrality parameter delta:</span>
<span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The noncentral T distribution is a generalization of the <a class="link" href="students_t_dist.html" title="Students t Distribution">Students
t Distribution</a>. Let X have a normal distribution with mean &#948; and variance
1, and let &#957; S<sup>2</sup> have a chi-squared distribution with degrees of freedom &#957;.
Assume that X and S<sup>2</sup> are independent. The distribution of t<sub>&#957;</sub>(&#948;)=X/S is called
a noncentral t distribution with degrees of freedom &#957; and noncentrality parameter
&#948;.
</p>
<p>
This gives the following PDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref1.svg"></span>
</p>
<p>
where <sub>1</sub>F<sub>1</sub>(a;b;x) is a confluent hypergeometric function.
</p>
<p>
The following graph illustrates how the distribution changes for different
values of &#957; and &#948;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/nc_t_pdf.svg" align="middle"></span>
<span class="inlinemediaobject"><img src="../../../../graphs/nc_t_cdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_t_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.member_functions"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">non_central_t_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">delta</span><span class="special">);</span>
</pre>
<p>
Constructs a non-central t distribution with degrees of freedom parameter
<span class="emphasis"><em>v</em></span> and non-centrality parameter <span class="emphasis"><em>delta</em></span>.
</p>
<p>
Requires <span class="emphasis"><em>v</em></span> &gt; 0 (including positive infinity) and
finite <span class="emphasis"><em>delta</em></span>, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>v</em></span> from which this object was
constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the non-centrality parameter <span class="emphasis"><em>delta</em></span> from which
this object was constructed.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_t_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.non_member_accessors"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [-&#8734;, +&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_t_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.accuracy"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_dist.accuracy">Accuracy</a>
</h5>
<p>
The following table shows the peak errors (in units of <a href="http://en.wikipedia.org/wiki/Machine_epsilon" target="_top">epsilon</a>)
found on various platforms with various floating-point types. Unless otherwise
specified, any floating-point type that is narrower than the one shown
will have <a class="link" href="../../relative_error.html#math_toolkit.relative_error.zero_error">effectively
zero error</a>.
</p>
<div class="table">
<a name="math_toolkit.dist_ref.dists.nc_t_dist.table_non_central_t_CDF"></a><p class="title"><b>Table&#160;5.8.&#160;Error rates for non central t CDF</b></p>
<div class="table-contents"><table class="table" summary="Error rates for non central t CDF">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
</th>
<th>
<p>
Microsoft Visual C++ version 12.0<br> Win32<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5130<br> Sun Solaris<br> long double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Non Central T
</p>
</td>
<td>
<p>
<span class="blue">Max = 138&#949; (Mean = 31.5&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.796&#949; (Mean = 0.0691&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> <span class="red">Max
= 5.28e+15&#949; (Mean = 8.49e+14&#949;) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_double_non_central_t_CDF_Rmath_3_0_2_Non_Central_T">And
other failures.</a>)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 141&#949; (Mean = 31.1&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 145&#949; (Mean = 30.2&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
Non Central T (small non-centrality)
</p>
</td>
<td>
<p>
<span class="blue">Max = 3.61&#949; (Mean = 1.03&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>Rmath
3.0.2:</em></span> Max = 2.09e+03&#949; (Mean = 244&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 7.86&#949; (Mean = 1.69&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 9.15&#949; (Mean = 2.25&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
Non Central T (large parameters)
</p>
</td>
<td>
<p>
<span class="blue">Max = 286&#949; (Mean = 62.8&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 257&#949; (Mean = 72.1&#949;)</span><br> <br>
(<span class="emphasis"><em>Rmath 3.0.2:</em></span> Max = 2.46&#949; (Mean = 0.657&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 5.26e+05&#949; (Mean = 1.48e+05&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 5.24e+05&#949; (Mean = 1.47e+05&#949;)</span>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="table">
<a name="math_toolkit.dist_ref.dists.nc_t_dist.table_non_central_t_CDF_complement"></a><p class="title"><b>Table&#160;5.9.&#160;Error rates for non central t CDF complement</b></p>
<div class="table-contents"><table class="table" summary="Error rates for non central t CDF complement">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
</th>
<th>
<p>
Microsoft Visual C++ version 12.0<br> Win32<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 5.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5130<br> Sun Solaris<br> long double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
Non Central T
</p>
</td>
<td>
<p>
<span class="blue">Max = 150&#949; (Mean = 32.3&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.707&#949; (Mean = 0.0497&#949;)</span><br>
<br> (<span class="emphasis"><em>Rmath 3.0.2:</em></span> <span class="red">Max
= 6.19e+15&#949; (Mean = 6.72e+14&#949;) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_double_non_central_t_CDF_complement_Rmath_3_0_2_Non_Central_T">And
other failures.</a>)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 203&#949; (Mean = 31.8&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 340&#949; (Mean = 43.6&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
Non Central T (small non-centrality)
</p>
</td>
<td>
<p>
<span class="blue">Max = 5.21&#949; (Mean = 1.43&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>Rmath
3.0.2:</em></span> Max = 1.87e+03&#949; (Mean = 263&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 7.48&#949; (Mean = 1.86&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 10.9&#949; (Mean = 2.43&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
Non Central T (large parameters)
</p>
</td>
<td>
<p>
<span class="blue">Max = 227&#949; (Mean = 50.4&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 478&#949; (Mean = 96.3&#949;)</span><br> <br>
(<span class="emphasis"><em>Rmath 3.0.2:</em></span> Max = 2.24&#949; (Mean = 0.945&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 9.79e+05&#949; (Mean = 1.97e+05&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 9.79e+05&#949; (Mean = 1.97e+05&#949;)</span>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="caution"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top"><p>
The complexity of the current algorithm is dependent upon &#948;<sup>2</sup>: consequently
the time taken to evaluate the CDF increases rapidly for &#948; &gt; 500, likewise
the accuracy decreases rapidly for very large &#948;.
</p></td></tr>
</table></div>
<p>
Accuracy for the quantile and PDF functions should be broadly similar.
The <span class="emphasis"><em>mode</em></span> is determined numerically and cannot in principal
be more accurate than the square root of floating-point type FPT epsilon,
accessed using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span><span class="special">::</span><span class="identifier">epsilon</span><span class="special">&lt;</span><span class="identifier">FPT</span><span class="special">&gt;()</span></code>.
For 64-bit <code class="computeroutput"><span class="keyword">double</span></code>, epsilon
is about 1e-16, so the fractional accuracy is limited to 1e-8.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_t_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.tests"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_dist.tests">Tests</a>
</h5>
<p>
There are two sets of tests of this distribution:
</p>
<p>
Basic sanity checks compare this implementation to the test values given
in "Computing discrete mixtures of continuous distributions: noncentral
chisquare, noncentral t and the distribution of the square of the sample
multiple correlation coefficient." Denise Benton, K. Krishnamoorthy,
Computational Statistics &amp; Data Analysis 43 (2003) 249-267.
</p>
<p>
Accuracy checks use test data computed with this implementation and arbitary
precision interval arithmetic: this test data is believed to be accurate
to at least 50 decimal places.
</p>
<p>
The cases of large (or infinite) &#957; and/or large &#948; has received special treatment
to avoid catastrophic loss of accuracy. New tests have been added to confirm
the improvement achieved.
</p>
<p>
From Boost 1.52, degrees of freedom &#957; can be +&#8734;
when the normal distribution
located at &#948;
(equivalent to the central Student's t distribution) is used
in place for accuracy and speed.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.nc_t_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.implementation"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_dist.implementation">Implementation</a>
</h5>
<p>
The CDF is computed using a modification of the method described in "Computing
discrete mixtures of continuous distributions: noncentral chisquare, noncentral
t and the distribution of the square of the sample multiple correlation
coefficient." Denise Benton, K. Krishnamoorthy, Computational Statistics
&amp; Data Analysis 43 (2003) 249-267.
</p>
<p>
This uses the following formula for the CDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref2.svg"></span>
</p>
<p>
Where I<sub>x</sub>(a,b) is the incomplete beta function, and &#934;(x) is the normal CDF
at x.
</p>
<p>
Iteration starts at the largest of the Poisson weighting terms (at i =
&#948;<sup>2</sup> / 2) and then proceeds in both directions as per Benton and Krishnamoorthy's
paper.
</p>
<p>
Alternatively, by considering what happens when t = &#8734;, we have x = 1, and
therefore I<sub>x</sub>(a,b) = 1 and:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref3.svg"></span>
</p>
<p>
From this we can easily show that:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref4.svg"></span>
</p>
<p>
and therefore we have a means to compute either the probability or its
complement directly without the risk of cancellation error. The crossover
criterion for choosing whether to calculate the CDF or its complement is
the same as for the <a class="link" href="nc_beta_dist.html" title="Noncentral Beta Distribution">Noncentral
Beta Distribution</a>.
</p>
<p>
The PDF can be computed by a very similar method using:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref5.svg"></span>
</p>
<p>
Where I<sub>x</sub><sup>'</sup>(a,b) is the derivative of the incomplete beta function.
</p>
<p>
For both the PDF and CDF we switch to approximating the distribution by
a Student's t distribution centred on &#948; when &#957; is very large. The crossover
location appears to be when &#948;/(4&#957;) &lt; &#949;, this location was estimated by
inspection of equation 2.6 in "A Comparison of Approximations To Percentiles
of the Noncentral t-Distribution". H. Sahai and M. M. Ojeda, Revista
Investigacion Operacional Vol 21, No 2, 2000, page 123.
</p>
<p>
Equation 2.6 is a Fisher-Cornish expansion by Eeden and Johnson. The second
term includes the ratio &#948;/(4&#957;), so when this term become negligible, this
and following terms can be ignored, leaving just Student's t distribution
centred on &#948;.
</p>
<p>
This was also confirmed by experimental testing.
</p>
<p>
See also
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
"Some Approximations to the Percentage Points of the Noncentral
t-Distribution". C. van Eeden. International Statistical Review,
29, 4-31.
</li>
<li class="listitem">
"Continuous Univariate Distributions". N.L. Johnson, S. Kotz
and N. Balkrishnan. 1995. John Wiley and Sons New York.
</li>
</ul></div>
<p>
The quantile is calculated via the usual <a class="link" href="../../roots_noderiv.html" title="Root Finding Without Derivatives">root-finding
without derivatives</a> method with the initial guess taken as the quantile
of a normal approximation to the noncentral T.
</p>
<p>
There is no closed form for the mode, so this is computed via functional
maximisation of the PDF.
</p>
<p>
The remaining functions (mean, variance etc) are implemented using the
formulas given in Weisstein, Eric W. "Noncentral Student's t-Distribution."
From MathWorld--A Wolfram Web Resource. <a href="http://mathworld.wolfram.com/NoncentralStudentst-Distribution.html" target="_top">http://mathworld.wolfram.com/NoncentralStudentst-Distribution.html</a>
and in the <a href="http://reference.wolfram.com/mathematica/ref/NoncentralStudentTDistribution.html" target="_top">Mathematica
documentation</a>.
</p>
<p>
Some analytic properties of noncentral distributions (particularly unimodality,
and monotonicity of their modes) are surveyed and summarized by:
</p>
<p>
Andrea van Aubel &amp; Wolfgang Gawronski, Applied Mathematics and Computation,
141 (2003) 3-12.
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="nc_f_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="normal_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,884 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Negative Binomial Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="lognormal_dist.html" title="Log Normal Distribution">
<link rel="next" href="nc_beta_dist.html" title="Noncentral Beta 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="lognormal_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="nc_beta_dist.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.dist_ref.dists.negative_binomial_dist"></a><a class="link" href="negative_binomial_dist.html" title="Negative Binomial Distribution">Negative
Binomial Distribution</a>
</h4></div></div></div>
<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">negative_binomial</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">negative_binomial_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">negative_binomial_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">negative_binomial</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">negative_binomial_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="comment">// Constructor from successes and success_fraction:</span>
<span class="identifier">negative_binomial_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">r</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
<span class="comment">// Parameter accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
<span class="comment">// Bounds on success fraction:</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_lower_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// alpha</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_upper_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// alpha</span>
<span class="comment">// Estimate min/max number of trials:</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// Number of failures.</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// Success fraction.</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// Probability threshold alpha.</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// Number of failures.</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// Success fraction.</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">);</span> <span class="comment">// Probability threshold alpha.</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The class type <code class="computeroutput"><span class="identifier">negative_binomial_distribution</span></code>
represents a <a href="http://en.wikipedia.org/wiki/Negative_binomial_distribution" target="_top">negative_binomial
distribution</a>: it is used when there are exactly two mutually exclusive
outcomes of a <a href="http://en.wikipedia.org/wiki/Bernoulli_trial" target="_top">Bernoulli
trial</a>: these outcomes are labelled "success" and "failure".
</p>
<p>
For k + r Bernoulli trials each with success fraction p, the negative_binomial
distribution gives the probability of observing k failures and r successes
with success on the last trial. The negative_binomial distribution assumes
that success_fraction p is fixed for all (k + r) trials.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
The random variable for the negative binomial distribution is the number
of trials, (the number of successes is a fixed property of the distribution)
whereas for the binomial, the random variable is the number of successes,
for a fixed number of trials.
</p></td></tr>
</table></div>
<p>
It has the PDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/neg_binomial_ref.svg"></span>
</p>
<p>
The following graph illustrate how the PDF varies as the success fraction
<span class="emphasis"><em>p</em></span> changes:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/negative_binomial_pdf_1.svg" align="middle"></span>
</p>
<p>
Alternatively, this graph shows how the shape of the PDF varies as the
number of successes changes:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/negative_binomial_pdf_2.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.related_distributions"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.related_distributions">Related
Distributions</a>
</h5>
<p>
The name negative binomial distribution is reserved by some to the case
where the successes parameter r is an integer. This integer version is
also called the <a href="http://mathworld.wolfram.com/PascalDistribution.html" target="_top">Pascal
distribution</a>.
</p>
<p>
This implementation uses real numbers for the computation throughout (because
it uses the <span class="bold"><strong>real-valued</strong></span> incomplete beta
function family of functions). This real-valued version is also called
the Polya Distribution.
</p>
<p>
The Poisson distribution is a generalization of the Pascal distribution,
where the success parameter r is an integer: to obtain the Pascal distribution
you must ensure that an integer value is provided for r, and take integer
values (floor or ceiling) from functions that return a number of successes.
</p>
<p>
For large values of r (successes), the negative binomial distribution converges
to the Poisson distribution.
</p>
<p>
The geometric distribution is a special case where the successes parameter
r = 1, so only a first and only success is required. geometric(p) = negative_binomial(1,
p).
</p>
<p>
The Poisson distribution is a special case for large successes
</p>
<p>
poisson(&#955;) = lim <sub>r &#8594; &#8734;</sub> &#160; negative_binomial(r, r / (&#955; + r)))
</p>
<div class="caution"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top">
<p>
The Negative Binomial distribution is a discrete distribution: internally,
functions like the <code class="computeroutput"><span class="identifier">cdf</span></code>
and <code class="computeroutput"><span class="identifier">pdf</span></code> are treated "as
if" they are continuous functions, but in reality the results returned
from these functions only have meaning if an integer value is provided
for the random variate argument.
</p>
<p>
The quantile function will by default return an integer result that has
been <span class="emphasis"><em>rounded outwards</em></span>. That is to say lower quantiles
(where the probability is less than 0.5) are rounded downward, and upper
quantiles (where the probability is greater than 0.5) are rounded upwards.
This behaviour ensures that if an X% quantile is requested, then <span class="emphasis"><em>at
least</em></span> the requested coverage will be present in the central
region, and <span class="emphasis"><em>no more than</em></span> the requested coverage
will be present in the tails.
</p>
<p>
This behaviour can be changed so that the quantile functions are rounded
differently, or even return a real-valued result using <a class="link" href="../../pol_overview.html" title="Policy Overview">Policies</a>.
It is strongly recommended that you read the tutorial <a class="link" href="../../pol_tutorial/understand_dis_quant.html" title="Understanding Quantiles of Discrete Distributions">Understanding
Quantiles of Discrete Distributions</a> before using the quantile
function on the Negative Binomial distribution. The <a class="link" href="../../pol_ref/discrete_quant_ref.html" title="Discrete Quantile Policies">reference
docs</a> describe how to change the rounding policy for these distributions.
</p>
</td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.member_functions"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.member_functions">Member
Functions</a>
</h5>
<h6>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.construct"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.construct">Construct</a>
</h6>
<pre class="programlisting"><span class="identifier">negative_binomial_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">r</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
</pre>
<p>
Constructor: <span class="emphasis"><em>r</em></span> is the total number of successes,
<span class="emphasis"><em>p</em></span> is the probability of success of a single trial.
</p>
<p>
Requires: <code class="computeroutput"><span class="identifier">r</span> <span class="special">&gt;</span>
<span class="number">0</span></code> and <code class="computeroutput"><span class="number">0</span>
<span class="special">&lt;=</span> <span class="identifier">p</span>
<span class="special">&lt;=</span> <span class="number">1</span></code>.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.accessors"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.accessors">Accessors</a>
</h6>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> <span class="comment">// successes / trials (0 &lt;= p &lt;= 1)</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>p</em></span> from which this distribution
was constructed.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> <span class="comment">// required successes (r &gt; 0)</span>
</pre>
<p>
Returns the parameter <span class="emphasis"><em>r</em></span> from which this distribution
was constructed.
</p>
<p>
The best method of calculation for the following functions is disputed:
see <a class="link" href="binomial_dist.html" title="Binomial Distribution">Binomial
Distribution</a> for more discussion.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.lower_bound_on_parameter_p"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.lower_bound_on_parameter_p">Lower
Bound on Parameter p</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_lower_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">failures</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">)</span> <span class="comment">// (0 &lt;= alpha &lt;= 1), 0.05 equivalent to 95% confidence.</span>
</pre>
<p>
Returns a <span class="bold"><strong>lower bound</strong></span> on the success fraction:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">failures</span></dt>
<dd><p>
The total number of failures before the <span class="emphasis"><em>r</em></span>th
success.
</p></dd>
<dt><span class="term">successes</span></dt>
<dd><p>
The number of successes required.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The largest acceptable probability that the true value of the success
fraction is <span class="bold"><strong>less than</strong></span> the value
returned.
</p></dd>
</dl>
</div>
<p>
For example, if you observe <span class="emphasis"><em>k</em></span> failures and <span class="emphasis"><em>r</em></span>
successes from <span class="emphasis"><em>n</em></span> = k + r trials the best estimate
for the success fraction is simply <span class="emphasis"><em>r/n</em></span>, but if you
want to be 95% sure that the true value is <span class="bold"><strong>greater
than</strong></span> some value, <span class="emphasis"><em>p<sub>min</sub></em></span>, then:
</p>
<pre class="programlisting"><span class="identifier">p</span><sub>min</sub> <span class="special">=</span> <span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_lower_bound_on_p</span><span class="special">(</span>
<span class="identifier">failures</span><span class="special">,</span> <span class="identifier">successes</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
<a class="link" href="../../stat_tut/weg/neg_binom_eg/neg_binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for the Negative Binomial Distribution">See
negative binomial confidence interval example.</a>
</p>
<p>
This function uses the Clopper-Pearson method of computing the lower bound
on the success fraction, whilst many texts refer to this method as giving
an "exact" result in practice it produces an interval that guarantees
<span class="emphasis"><em>at least</em></span> the coverage required, and may produce pessimistic
estimates for some combinations of <span class="emphasis"><em>failures</em></span> and <span class="emphasis"><em>successes</em></span>.
See:
</p>
<p>
<a href="http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf" target="_top">Yong
Cai and K. Krishnamoorthy, A Simple Improved Inferential Method for Some
Discrete Distributions. Computational statistics and data analysis, 2005,
vol. 48, no3, 605-621</a>.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.upper_bound_on_parameter_p"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.upper_bound_on_parameter_p">Upper
Bound on Parameter p</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_upper_bound_on_p</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// (0 &lt;= alpha &lt;= 1), 0.05 equivalent to 95% confidence.</span>
</pre>
<p>
Returns an <span class="bold"><strong>upper bound</strong></span> on the success
fraction:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">trials</span></dt>
<dd><p>
The total number of trials conducted.
</p></dd>
<dt><span class="term">successes</span></dt>
<dd><p>
The number of successes that occurred.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The largest acceptable probability that the true value of the success
fraction is <span class="bold"><strong>greater than</strong></span> the value
returned.
</p></dd>
</dl>
</div>
<p>
For example, if you observe <span class="emphasis"><em>k</em></span> successes from <span class="emphasis"><em>n</em></span>
trials the best estimate for the success fraction is simply <span class="emphasis"><em>k/n</em></span>,
but if you want to be 95% sure that the true value is <span class="bold"><strong>less
than</strong></span> some value, <span class="emphasis"><em>p<sub>max</sub></em></span>, then:
</p>
<pre class="programlisting"><span class="identifier">p</span><sub>max</sub> <span class="special">=</span> <span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_upper_bound_on_p</span><span class="special">(</span>
<span class="identifier">r</span><span class="special">,</span> <span class="identifier">k</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
<a class="link" href="../../stat_tut/weg/neg_binom_eg/neg_binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for the Negative Binomial Distribution">See
negative binomial confidence interval example.</a>
</p>
<p>
This function uses the Clopper-Pearson method of computing the lower bound
on the success fraction, whilst many texts refer to this method as giving
an "exact" result in practice it produces an interval that guarantees
<span class="emphasis"><em>at least</em></span> the coverage required, and may produce pessimistic
estimates for some combinations of <span class="emphasis"><em>failures</em></span> and <span class="emphasis"><em>successes</em></span>.
See:
</p>
<p>
<a href="http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf" target="_top">Yong
Cai and K. Krishnamoorthy, A Simple Improved Inferential Method for Some
Discrete Distributions. Computational statistics and data analysis, 2005,
vol. 48, no3, 605-621</a>.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h6"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.estimating_number_of_trials_to_e"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.estimating_number_of_trials_to_e">Estimating
Number of Trials to Ensure at Least a Certain Number of Failures</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of failures.</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction.</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// probability threshold (0.05 equivalent to 95%).</span>
</pre>
<p>
This functions estimates the number of trials required to achieve a certain
probability that <span class="bold"><strong>more than k failures will be observed</strong></span>.
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">k</span></dt>
<dd><p>
The target number of failures to be observed.
</p></dd>
<dt><span class="term">p</span></dt>
<dd><p>
The probability of <span class="emphasis"><em>success</em></span> for each trial.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The maximum acceptable risk that only k failures or fewer will be
observed.
</p></dd>
</dl>
</div>
<p>
For example:
</p>
<pre class="programlisting"><span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span><span class="number">10</span><span class="special">,</span> <span class="number">0.5</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
Returns the smallest number of trials we must conduct to be 95% sure of
seeing 10 failures that occur with frequency one half.
</p>
<p>
<a class="link" href="../../stat_tut/weg/neg_binom_eg/neg_binom_size_eg.html" title="Estimating Sample Sizes for the Negative Binomial.">Worked
Example.</a>
</p>
<p>
This function uses numeric inversion of the negative binomial distribution
to obtain the result: another interpretation of the result, is that it
finds the number of trials (success+failures) that will lead to an <span class="emphasis"><em>alpha</em></span>
probability of observing k failures or fewer.
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h7"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.estimating_number_of_trials_to_0"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.estimating_number_of_trials_to_0">Estimating
Number of Trials to Ensure a Maximum Number of Failures or Less</a>
</h6>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of failures.</span>
<span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction.</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// probability threshold (0.05 equivalent to 95%).</span>
</pre>
<p>
This functions estimates the maximum number of trials we can conduct and
achieve a certain probability that <span class="bold"><strong>k failures or
fewer will be observed</strong></span>.
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">k</span></dt>
<dd><p>
The maximum number of failures to be observed.
</p></dd>
<dt><span class="term">p</span></dt>
<dd><p>
The probability of <span class="emphasis"><em>success</em></span> for each trial.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The maximum acceptable <span class="emphasis"><em>risk</em></span> that more than k
failures will be observed.
</p></dd>
</dl>
</div>
<p>
For example:
</p>
<pre class="programlisting"><span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="identifier">RealType</span><span class="special">&gt;::</span><span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span><span class="number">0</span><span class="special">,</span> <span class="number">1.0</span><span class="special">-</span><span class="number">1.0</span><span class="special">/</span><span class="number">1000000</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span>
</pre>
<p>
Returns the largest number of trials we can conduct and still be 95% sure
of seeing no failures that occur with frequency one in one million.
</p>
<p>
This function uses numeric inversion of the negative binomial distribution
to obtain the result: another interpretation of the result, is that it
finds the number of trials (success+failures) that will lead to an <span class="emphasis"><em>alpha</em></span>
probability of observing more than k failures.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h8"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.non_member_accessors"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
However it's worth taking a moment to define what these actually mean in
the context of this distribution:
</p>
<div class="table">
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.meaning_of_the_non_member_access"></a><p class="title"><b>Table&#160;5.3.&#160;Meaning of the non-member accessors.</b></p>
<div class="table-contents"><table class="table" summary="Meaning of the non-member accessors.">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Function
</p>
</th>
<th>
<p>
Meaning
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density
Function</a>
</p>
</td>
<td>
<p>
The probability of obtaining <span class="bold"><strong>exactly k
failures</strong></span> from k+r trials with success fraction p.
For example:
</p>
<pre class="programlisting"><span class="identifier">pdf</span><span class="special">(</span><span class="identifier">negative_binomial</span><span class="special">(</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">p</span><span class="special">),</span> <span class="identifier">k</span><span class="special">)</span></pre>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution
Function</a>
</p>
</td>
<td>
<p>
The probability of obtaining <span class="bold"><strong>k failures
or fewer</strong></span> from k+r trials with success fraction p and
success on the last trial. For example:
</p>
<pre class="programlisting"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">negative_binomial</span><span class="special">(</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">p</span><span class="special">),</span> <span class="identifier">k</span><span class="special">)</span></pre>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.ccdf">Complement of
the Cumulative Distribution Function</a>
</p>
</td>
<td>
<p>
The probability of obtaining <span class="bold"><strong>more than
k failures</strong></span> from k+r trials with success fraction p
and success on the last trial. For example:
</p>
<pre class="programlisting"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">negative_binomial</span><span class="special">(</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">p</span><span class="special">),</span> <span class="identifier">k</span><span class="special">))</span></pre>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>
</p>
</td>
<td>
<p>
The <span class="bold"><strong>greatest</strong></span> number of failures
k expected to be observed from k+r trials with success fraction
p, at probability P. Note that the value returned is a real-number,
and not an integer. Depending on the use case you may want to
take either the floor or ceiling of the real result. For example:
</p>
<pre class="programlisting"><span class="identifier">quantile</span><span class="special">(</span><span class="identifier">negative_binomial</span><span class="special">(</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">p</span><span class="special">),</span> <span class="identifier">P</span><span class="special">)</span></pre>
</td>
</tr>
<tr>
<td>
<p>
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile_c">Quantile
from the complement of the probability</a>
</p>
</td>
<td>
<p>
The <span class="bold"><strong>smallest</strong></span> number of failures
k expected to be observed from k+r trials with success fraction
p, at probability P. Note that the value returned is a real-number,
and not an integer. Depending on the use case you may want to
take either the floor or ceiling of the real result. For example:
</p>
<pre class="programlisting"><span class="identifier">quantile</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">negative_binomial</span><span class="special">(</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">p</span><span class="special">),</span> <span class="identifier">P</span><span class="special">))</span></pre>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><h5>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h9"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.accuracy"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.accuracy">Accuracy</a>
</h5>
<p>
This distribution is implemented using the incomplete beta functions <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a> and <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>:
please refer to these functions for information on accuracy.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.negative_binomial_dist.h10"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.negative_binomial_dist.implementation"></a></span><a class="link" href="negative_binomial_dist.html#math_toolkit.dist_ref.dists.negative_binomial_dist.implementation">Implementation</a>
</h5>
<p>
In the following table, <span class="emphasis"><em>p</em></span> is the probability that
any one trial will be successful (the success fraction), <span class="emphasis"><em>r</em></span>
is the number of successes, <span class="emphasis"><em>k</em></span> is the number of failures,
<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>
pdf = exp(lgamma(r + k) - lgamma(r) - lgamma(k+1)) * pow(p, r)
* pow((1-p), k)
</p>
<p>
Implementation is in terms of <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>:
</p>
<p>
(p/(r + k)) * ibeta_derivative(r, static_cast&lt;RealType&gt;(k+1),
p) The function <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>
is used here, since it has already been optimised for the lowest
possible error - indeed this is really just a thin wrapper around
part of the internals of the incomplete beta function.
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
cdf = I<sub>p</sub>(r, k+1) = ibeta(r, k+1, p)
</p>
<p>
= ibeta(r, static_cast&lt;RealType&gt;(k+1), p)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation:
</p>
<p>
1 - cdf = I<sub>p</sub>(k+1, r)
</p>
<p>
= ibetac(r, static_cast&lt;RealType&gt;(k+1), p)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
ibeta_invb(r, p, P) - 1
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
ibetac_invb(r, p, Q) -1)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">r</span><span class="special">(</span><span class="number">1</span><span class="special">-</span><span class="identifier">p</span><span class="special">)/</span><span class="identifier">p</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">r</span> <span class="special">(</span><span class="number">1</span><span class="special">-</span><span class="identifier">p</span><span class="special">)</span>
<span class="special">/</span> <span class="identifier">p</span>
<span class="special">*</span> <span class="identifier">p</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">floor</span><span class="special">((</span><span class="identifier">r</span><span class="special">-</span><span class="number">1</span><span class="special">)</span> <span class="special">*</span> <span class="special">(</span><span class="number">1</span> <span class="special">-</span> <span class="identifier">p</span><span class="special">)/</span><span class="identifier">p</span><span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">(</span><span class="number">2</span>
<span class="special">-</span> <span class="identifier">p</span><span class="special">)</span> <span class="special">/</span>
<span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">r</span> <span class="special">*</span>
<span class="special">(</span><span class="number">1</span>
<span class="special">-</span> <span class="identifier">p</span><span class="special">))</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="number">6</span> <span class="special">/</span>
<span class="identifier">r</span> <span class="special">+</span>
<span class="special">(</span><span class="identifier">p</span>
<span class="special">*</span> <span class="identifier">p</span><span class="special">)</span> <span class="special">/</span>
<span class="identifier">r</span> <span class="special">*</span>
<span class="special">(</span><span class="number">1</span>
<span class="special">-</span> <span class="identifier">p</span>
<span class="special">)</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="number">6</span> <span class="special">/</span>
<span class="identifier">r</span> <span class="special">+</span>
<span class="special">(</span><span class="identifier">p</span>
<span class="special">*</span> <span class="identifier">p</span><span class="special">)</span> <span class="special">/</span>
<span class="identifier">r</span> <span class="special">*</span>
<span class="special">(</span><span class="number">1</span>
<span class="special">-</span> <span class="identifier">p</span>
<span class="special">)</span> <span class="special">-</span><span class="number">3</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
parameter estimation member functions
</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_lower_bound_on_p</span></code>
</p>
</td>
<td>
<p>
ibeta_inv(successes, failures + 1, alpha)
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_upper_bound_on_p</span></code>
</p>
</td>
<td>
<p>
ibetac_inv(successes, failures, alpha) plus see comments in code.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_minimum_number_of_trials</span></code>
</p>
</td>
<td>
<p>
ibeta_inva(k + 1, p, alpha)
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">find_maximum_number_of_trials</span></code>
</p>
</td>
<td>
<p>
ibetac_inva(k + 1, p, alpha)
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
Implementation notes:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
The real concept type (that deliberately lacks the Lanczos approximation),
was found to take several minutes to evaluate some extreme test values,
so the test has been disabled for this type.
</li>
<li class="listitem">
Much greater speed, and perhaps greater accuracy, might be achieved
for extreme values by using a normal approximation. This is NOT been
tested or implemented.
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="lognormal_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="nc_beta_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,326 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Normal (Gaussian) Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="nc_t_dist.html" title="Noncentral T Distribution">
<link rel="next" href="pareto.html" title="Pareto 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="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>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="math_toolkit.dist_ref.dists.normal_dist"></a><a class="link" href="normal_dist.html" title="Normal (Gaussian) Distribution">Normal (Gaussian)
Distribution</a>
</h4></div></div></div>
<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>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">normal_distribution</span><span class="special">;</span>
<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>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">normal_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="comment">// Construct:</span>
<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>
<span class="comment">// Accessors:</span>
<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>
<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>
<span class="comment">// Synonyms, provided to allow generic use of find_location and find_scale.</span>
<span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The normal distribution is probably the most well known statistical distribution:
it is also known as the Gaussian Distribution. A normal distribution with
mean zero and standard deviation one is known as the <span class="emphasis"><em>Standard
Normal Distribution</em></span>.
</p>
<p>
Given mean &#956; &#160;and standard deviation &#963; &#160;it has the PDF:
</p>
<p>
&#160; <span class="inlinemediaobject"><img src="../../../../equations/normal_ref1.svg"></span>
</p>
<p>
The variation the PDF with its parameters is illustrated in the following
graph:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/normal_pdf.svg" align="middle"></span>
</p>
<p>
The cumulative distribution function is given by
</p>
<p>
&#160; <span class="inlinemediaobject"><img src="../../../../equations/normal_cdf.svg"></span>
</p>
<p>
and illustrated by this graph
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/normal_cdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.normal_dist.h0"></a>
<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
Functions</a>
</h5>
<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>
</pre>
<p>
Constructs a normal distribution with mean <span class="emphasis"><em>mean</em></span> and
standard deviation <span class="emphasis"><em>sd</em></span>.
</p>
<p>
Requires sd &gt; 0, otherwise <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
is called.
</p>
<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>
<span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
both return the <span class="emphasis"><em>mean</em></span> of this distribution.
</p>
<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>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
both return the <span class="emphasis"><em>standard deviation</em></span> of this distribution.
(Redundant location and scale function are provided to match other similar
distributions, allowing the functions find_location and find_scale to be
used generically).
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.normal_dist.h1"></a>
<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
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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [-[max_value], +[min_value]]. However,
the pdf of +&#8734; and -&#8734; = 0 is also supported, and cdf at -&#8734; = 0, cdf at +&#8734; = 1, and
complement cdf -&#8734; = 1 and +&#8734; = 0, if RealType permits.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.normal_dist.h2"></a>
<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>
</h5>
<p>
The normal distribution is implemented in terms of the <a class="link" href="../../sf_erf/error_function.html" title="Error Functions">error
function</a>, and as such should have very low error rates.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.normal_dist.h3"></a>
<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>
</h5>
<p>
In the following table <span class="emphasis"><em>m</em></span> is the mean of the distribution,
and <span class="emphasis"><em>s</em></span> is its standard deviation.
</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 = e<sup>-(x-m)<sup>2</sup>/(2s<sup>2</sup>)</sup> / (s * sqrt(2*pi))
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = 0.5 * <a class="link" href="../../sf_erf/error_function.html" title="Error Functions">erfc</a>(-(x-m)/(s*sqrt(2)))
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = 0.5 * <a class="link" href="../../sf_erf/error_function.html" title="Error Functions">erfc</a>((x-m)/(s*sqrt(2)))
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
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)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
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)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean and standard deviation
</p>
</td>
<td>
<p>
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>
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
The same as the mean.
</p>
</td>
</tr>
<tr>
<td>
<p>
median
</p>
</td>
<td>
<p>
The same as the mean.
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
3
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="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>
</div>
</body>
</html>

View File

@@ -0,0 +1,351 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Pareto Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="normal_dist.html" title="Normal (Gaussian) Distribution">
<link rel="next" href="poisson_dist.html" title="Poisson 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="normal_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="poisson_dist.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.dist_ref.dists.pareto"></a><a class="link" href="pareto.html" title="Pareto Distribution">Pareto Distribution</a>
</h4></div></div></div>
<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">pareto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">pareto_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">pareto_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">pareto</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">pareto_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="comment">// Constructor:</span>
<span class="identifier">pareto_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">shape</span> <span class="special">=</span> <span class="number">1</span><span class="special">)</span>
<span class="comment">// Accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The <a href="http://en.wikipedia.org/wiki/pareto_distribution" target="_top">Pareto
distribution</a> is a continuous distribution with the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
density function (pdf)</a>:
</p>
<p>
f(x; &#945;, &#946;) = &#945;&#946;<sup>&#945;</sup> / x<sup>&#945;+ 1</sup>
</p>
<p>
For shape parameter &#945; &#160; &gt; 0, and scale parameter &#946; &#160; &gt; 0. If x &lt; &#946; &#160;, the
pdf is zero.
</p>
<p>
The <a href="http://mathworld.wolfram.com/ParetoDistribution.html" target="_top">Pareto
distribution</a> often describes the larger compared to the smaller.
A classic example is that 80% of the wealth is owned by 20% of the population.
</p>
<p>
The following graph illustrates how the PDF varies with the scale parameter
&#946;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/pareto_pdf1.svg" align="middle"></span>
</p>
<p>
And this graph illustrates how the PDF varies with the shape parameter
&#945;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/pareto_pdf2.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.pareto.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.pareto.related_distributions"></a></span><a class="link" href="pareto.html#math_toolkit.dist_ref.dists.pareto.related_distributions">Related
distributions</a>
</h5>
<h5>
<a name="math_toolkit.dist_ref.dists.pareto.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.pareto.member_functions"></a></span><a class="link" href="pareto.html#math_toolkit.dist_ref.dists.pareto.member_functions">Member Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">pareto_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">shape</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/pareto_distribution" target="_top">pareto
distribution</a> with shape <span class="emphasis"><em>shape</em></span> and scale <span class="emphasis"><em>scale</em></span>.
</p>
<p>
Requires that the <span class="emphasis"><em>shape</em></span> and <span class="emphasis"><em>scale</em></span>
parameters are both greater than zero, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>scale</em></span> parameter of this distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>shape</em></span> parameter of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.pareto.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.pareto.non_member_accessors"></a></span><a class="link" href="pareto.html#math_toolkit.dist_ref.dists.pareto.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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The supported domain of the random variable is [scale, &#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.pareto.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.pareto.accuracy"></a></span><a class="link" href="pareto.html#math_toolkit.dist_ref.dists.pareto.accuracy">Accuracy</a>
</h5>
<p>
The Pareto distribution is implemented in terms of the standard library
<code class="computeroutput"><span class="identifier">exp</span></code> functions plus <a class="link" href="../../powers/expm1.html" title="expm1">expm1</a> and so should have very
small errors, usually only a few epsilon.
</p>
<p>
If probability is near to unity (or the complement of a probability near
zero) see also <a class="link" href="../../stat_tut/overview/complements.html#why_complements">why complements?</a>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.pareto.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.pareto.implementation"></a></span><a class="link" href="pareto.html#math_toolkit.dist_ref.dists.pareto.implementation">Implementation</a>
</h5>
<p>
In the following table &#945; &#160; is the shape parameter of the distribution, and
&#946; &#160; is its scale parameter, <span class="emphasis"><em>x</em></span> is the random variate,
<span class="emphasis"><em>p</em></span> is the probability and its complement <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 p = &#945;&#946;<sup>&#945;</sup>/x<sup>&#945; +1</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: cdf p = 1 - (&#946; &#160; / x)<sup>&#945;</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = 1 - p = -(&#946; &#160; / x)<sup>&#945;</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = &#946; / (1 - p)<sup>1/&#945;</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = &#946; / (q)<sup>1/&#945;</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
&#945;&#946; / (&#946; - 1)
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
&#946;&#945;<sup>2</sup> / (&#946; - 1)<sup>2</sup> (&#946; - 2)
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
&#945;
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
Refer to <a href="http://mathworld.wolfram.com/ParetoDistribution.html" target="_top">Weisstein,
Eric W. "Pareto Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
Refer to <a href="http://mathworld.wolfram.com/ParetoDistribution.html" target="_top">Weisstein,
Eric W. "Pareto Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
Refer to <a href="http://mathworld.wolfram.com/ParetoDistribution.html" target="_top">Weisstein,
Eric W. "pareto Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.pareto.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.pareto.references"></a></span><a class="link" href="pareto.html#math_toolkit.dist_ref.dists.pareto.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/pareto_distribution" target="_top">Pareto
Distribution</a>
</li>
<li class="listitem">
<a href="http://mathworld.wolfram.com/paretoDistribution.html" target="_top">Weisstein,
Eric W. "Pareto Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</li>
<li class="listitem">
Handbook of Statistical Distributions with Applications, K Krishnamoorthy,
ISBN 1-58488-635-8, Chapter 23, pp 257 - 267. (Note the meaning of
a and b is reversed in Wolfram and Krishnamoorthy).
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="normal_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="poisson_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,331 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Poisson Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="pareto.html" title="Pareto Distribution">
<link rel="next" href="rayleigh.html" title="Rayleigh 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="pareto.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="rayleigh.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.dist_ref.dists.poisson_dist"></a><a class="link" href="poisson_dist.html" title="Poisson Distribution">Poisson Distribution</a>
</h4></div></div></div>
<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">poisson</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">poisson_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">poisson_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">poisson</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">poisson_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">poisson_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">mean</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// Constructor.</span>
<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">// Accessor.</span>
<span class="special">}</span>
<span class="special">}}</span> <span class="comment">// namespaces boost::math</span>
</pre>
<p>
The <a href="http://en.wikipedia.org/wiki/Poisson_distribution" target="_top">Poisson
distribution</a> is a well-known statistical discrete distribution.
It expresses the probability of a number of events (or failures, arrivals,
occurrences ...) occurring in a fixed period of time, provided these events
occur with a known mean rate &#955; &#160;
(events/time), and are independent of the
time since the last event.
</p>
<p>
The distribution was discovered by Sim&#233; on-Denis Poisson (1781 to 1840).
</p>
<p>
It has the Probability Mass Function:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/poisson_ref1.svg"></span>
</p>
<p>
for k events, with an expected number of events &#955;.
</p>
<p>
The following graph illustrates how the PDF varies with the parameter &#955;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/poisson_pdf_1.svg" align="middle"></span>
</p>
<div class="caution"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top">
<p>
The Poisson distribution is a discrete distribution: internally, functions
like the <code class="computeroutput"><span class="identifier">cdf</span></code> and <code class="computeroutput"><span class="identifier">pdf</span></code> are treated "as if" they
are continuous functions, but in reality the results returned from these
functions only have meaning if an integer value is provided for the random
variate argument.
</p>
<p>
The quantile function will by default return an integer result that has
been <span class="emphasis"><em>rounded outwards</em></span>. That is to say lower quantiles
(where the probability is less than 0.5) are rounded downward, and upper
quantiles (where the probability is greater than 0.5) are rounded upwards.
This behaviour ensures that if an X% quantile is requested, then <span class="emphasis"><em>at
least</em></span> the requested coverage will be present in the central
region, and <span class="emphasis"><em>no more than</em></span> the requested coverage
will be present in the tails.
</p>
<p>
This behaviour can be changed so that the quantile functions are rounded
differently, or even return a real-valued result using <a class="link" href="../../pol_overview.html" title="Policy Overview">Policies</a>.
It is strongly recommended that you read the tutorial <a class="link" href="../../pol_tutorial/understand_dis_quant.html" title="Understanding Quantiles of Discrete Distributions">Understanding
Quantiles of Discrete Distributions</a> before using the quantile
function on the Poisson distribution. The <a class="link" href="../../pol_ref/discrete_quant_ref.html" title="Discrete Quantile Policies">reference
docs</a> describe how to change the rounding policy for these distributions.
</p>
</td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.poisson_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.poisson_dist.member_functions"></a></span><a class="link" href="poisson_dist.html#math_toolkit.dist_ref.dists.poisson_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">poisson_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">mean</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
Constructs a poisson distribution with mean <span class="emphasis"><em>mean</em></span>.
</p>
<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>
</pre>
<p>
Returns the <span class="emphasis"><em>mean</em></span> of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.poisson_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.poisson_dist.non_member_accessors"></a></span><a class="link" href="poisson_dist.html#math_toolkit.dist_ref.dists.poisson_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [0, &#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.poisson_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.poisson_dist.accuracy"></a></span><a class="link" href="poisson_dist.html#math_toolkit.dist_ref.dists.poisson_dist.accuracy">Accuracy</a>
</h5>
<p>
The Poisson distribution is implemented in terms of the incomplete gamma
functions <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a> and
<a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a> and as such
should have low error rates: but refer to the documentation of those functions
for more information. The quantile and its complement use the inverse gamma
functions and are therefore probably slightly less accurate: this is because
the inverse gamma functions are implemented using an iterative method with
a lower tolerance to avoid excessive computation.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.poisson_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.poisson_dist.implementation"></a></span><a class="link" href="poisson_dist.html#math_toolkit.dist_ref.dists.poisson_dist.implementation">Implementation</a>
</h5>
<p>
In the following table &#955; &#160; is the mean of the distribution, <span class="emphasis"><em>k</em></span>
is the random variable, <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 = e<sup>-&#955;</sup> &#955;<sup>k</sup> / k!
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = &#915;(k+1, &#955;) / k! = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a>(k+1,
&#955;)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>(k+1,
&#955;)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: k = <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inva</a>(&#955;,
p) - 1
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: k = <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inva</a>(&#955;,
q) - 1
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
&#955;
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
floor (&#955;) or &#8970;&#955;&#8971;
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
1/&#8730;&#955;
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
3 + 1/&#955;
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
1/&#955;
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="pareto.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="rayleigh.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,348 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Rayleigh Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="poisson_dist.html" title="Poisson Distribution">
<link rel="next" href="skew_normal_dist.html" title="Skew Normal 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="poisson_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="skew_normal_dist.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.dist_ref.dists.rayleigh"></a><a class="link" href="rayleigh.html" title="Rayleigh Distribution">Rayleigh Distribution</a>
</h4></div></div></div>
<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">rayleigh</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">rayleigh_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">rayleigh_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">rayleigh</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">rayleigh_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="comment">// Construct:</span>
<span class="identifier">rayleigh_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">sigma</span> <span class="special">=</span> <span class="number">1</span><span class="special">)</span>
<span class="comment">// Accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">sigma</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The <a href="http://en.wikipedia.org/wiki/Rayleigh_distribution" target="_top">Rayleigh
distribution</a> is a continuous distribution with the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
density function</a>:
</p>
<p>
f(x; sigma) = x * exp(-x<sup>2</sup>/2 &#963;<sup>2</sup>) / &#963;<sup>2</sup>
</p>
<p>
For sigma parameter &#963; &#160; &gt; 0, and x &gt; 0.
</p>
<p>
The Rayleigh distribution is often used where two orthogonal components
have an absolute value, for example, wind velocity and direction may be
combined to yield a wind speed, or real and imaginary components may have
absolute values that are Rayleigh distributed.
</p>
<p>
The following graph illustrates how the Probability density Function(pdf)
varies with the shape parameter &#963;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/rayleigh_pdf.svg" align="middle"></span>
</p>
<p>
and the Cumulative Distribution Function (cdf)
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/rayleigh_cdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.rayleigh.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.rayleigh.related_distributions"></a></span><a class="link" href="rayleigh.html#math_toolkit.dist_ref.dists.rayleigh.related_distributions">Related
distributions</a>
</h5>
<p>
The absolute value of two independent normal distributions X and Y, &#8730; (X<sup>2</sup> +
Y<sup>2</sup>) is a Rayleigh distribution.
</p>
<p>
The <a href="http://en.wikipedia.org/wiki/Chi_distribution" target="_top">Chi</a>,
<a href="http://en.wikipedia.org/wiki/Rice_distribution" target="_top">Rice</a>
and <a href="http://en.wikipedia.org/wiki/Weibull_distribution" target="_top">Weibull</a>
distributions are generalizations of the <a href="http://en.wikipedia.org/wiki/Rayleigh_distribution" target="_top">Rayleigh
distribution</a>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.rayleigh.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.rayleigh.member_functions"></a></span><a class="link" href="rayleigh.html#math_toolkit.dist_ref.dists.rayleigh.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">rayleigh_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">sigma</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/Rayleigh_distribution" target="_top">Rayleigh
distribution</a> with &#963; <span class="emphasis"><em>sigma</em></span>.
</p>
<p>
Requires that the &#963; parameter is greater than zero, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">sigma</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>sigma</em></span> parameter of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.rayleigh.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.rayleigh.non_member_accessors"></a></span><a class="link" href="rayleigh.html#math_toolkit.dist_ref.dists.rayleigh.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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [0, max_value].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.rayleigh.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.rayleigh.accuracy"></a></span><a class="link" href="rayleigh.html#math_toolkit.dist_ref.dists.rayleigh.accuracy">Accuracy</a>
</h5>
<p>
The Rayleigh distribution is implemented in terms of the standard library
<code class="computeroutput"><span class="identifier">sqrt</span></code> and <code class="computeroutput"><span class="identifier">exp</span></code> and as such should have very low
error rates. Some constants such as skewness and kurtosis were calculated
using NTL RR type with 150-bit accuracy, about 50 decimal digits.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.rayleigh.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.rayleigh.implementation"></a></span><a class="link" href="rayleigh.html#math_toolkit.dist_ref.dists.rayleigh.implementation">Implementation</a>
</h5>
<p>
In the following table &#963; &#160; is the sigma parameter of the distribution, <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 = x * exp(-x<sup>2</sup>)/2 &#963;<sup>2</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = 1 - exp(-x<sup>2</sup>/2) &#963;<sup>2</sup> &#160; = -<a class="link" href="../../powers/expm1.html" title="expm1">expm1</a>(-x<sup>2</sup>/2)
&#963;<sup>2</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = exp(-x<sup>2</sup>/ 2) * &#963;<sup>2</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = sqrt(-2 * &#963; <sup>2</sup>) * log(1 - p)) = sqrt(-2
* &#963; <sup>2</sup>) * <a class="link" href="../../powers/log1p.html" title="log1p">log1p</a>(-p))
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = sqrt(-2 * &#963; <sup>2</sup>) * log(q))
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
&#963; * sqrt(&#960;/2)
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
&#963;<sup>2</sup> * (4 - &#960;/2)
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
&#963;
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
Constant from <a href="http://mathworld.wolfram.com/RayleighDistribution.html" target="_top">Weisstein,
Eric W. "Weibull Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
Constant from <a href="http://mathworld.wolfram.com/RayleighDistribution.html" target="_top">Weisstein,
Eric W. "Weibull Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
Constant from <a href="http://mathworld.wolfram.com/RayleighDistribution.html" target="_top">Weisstein,
Eric W. "Weibull Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.rayleigh.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.rayleigh.references"></a></span><a class="link" href="rayleigh.html#math_toolkit.dist_ref.dists.rayleigh.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Rayleigh_distribution" target="_top">http://en.wikipedia.org/wiki/Rayleigh_distribution</a>
</li>
<li class="listitem">
<a href="http://mathworld.wolfram.com/RayleighDistribution.html" target="_top">Weisstein,
Eric W. "Rayleigh Distribution." From MathWorld--A Wolfram
Web Resource.</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="poisson_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="skew_normal_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,499 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Skew Normal Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="rayleigh.html" title="Rayleigh Distribution">
<link rel="next" href="students_t_dist.html" title="Students t 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="rayleigh.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="students_t_dist.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.dist_ref.dists.skew_normal_dist"></a><a class="link" href="skew_normal_dist.html" title="Skew Normal Distribution">Skew
Normal Distribution</a>
</h4></div></div></div>
<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">skew_normal</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">skew_normal_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">skew_normal_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">normal</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">skew_normal_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="comment">// Constructor:</span>
<span class="identifier">skew_normal_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">shape</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
<span class="comment">// Accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// mean if normal.</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// width, standard deviation if normal.</span>
<span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// The distribution is right skewed if shape &gt; 0 and is left skewed if shape &lt; 0.</span>
<span class="comment">// The distribution is normal if shape is zero.</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The skew normal distribution is a variant of the most well known Gaussian
statistical distribution.
</p>
<p>
The skew normal distribution with shape zero resembles the <a href="http://en.wikipedia.org/wiki/Normal_distribution" target="_top">Normal
Distribution</a>, hence the latter can be regarded as a special case
of the more generic skew normal distribution.
</p>
<p>
If the standard (mean = 0, scale = 1) normal distribution probability density
function is
</p>
<p>
&#160; &#160; <span class="inlinemediaobject"><img src="../../../../equations/normal01_pdf.svg"></span>
</p>
<p>
and the cumulative distribution function
</p>
<p>
&#160; &#160; <span class="inlinemediaobject"><img src="../../../../equations/normal01_cdf.svg"></span>
</p>
<p>
then the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">PDF</a>
of the <a href="http://en.wikipedia.org/wiki/Skew_normal_distribution" target="_top">skew
normal distribution</a> with shape parameter &#945;, defined by O'Hagan and
Leonhard (1976) is
</p>
<p>
&#160; &#160; <span class="inlinemediaobject"><img src="../../../../equations/skew_normal_pdf0.svg"></span>
</p>
<p>
Given <a href="http://en.wikipedia.org/wiki/Location_parameter" target="_top">location</a>
&#958;, <a href="http://en.wikipedia.org/wiki/Scale_parameter" target="_top">scale</a>
&#969;, and <a href="http://en.wikipedia.org/wiki/Shape_parameter" target="_top">shape</a>
&#945;, it can be <a href="http://en.wikipedia.org/wiki/Skew_normal_distribution" target="_top">transformed</a>,
to the form:
</p>
<p>
&#160; &#160; <span class="inlinemediaobject"><img src="../../../../equations/skew_normal_pdf.svg"></span>
</p>
<p>
and <a href="http://en.wikipedia.org/wiki/Cumulative_distribution_function" target="_top">CDF</a>:
</p>
<p>
&#160; &#160; <span class="inlinemediaobject"><img src="../../../../equations/skew_normal_cdf.svg"></span>
</p>
<p>
where <span class="emphasis"><em>T(h,a)</em></span> is Owen's T function, and <span class="emphasis"><em>&#934;(x)</em></span>
is the normal distribution.
</p>
<p>
The variation the PDF and CDF with its parameters is illustrated in the
following graphs:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/skew_normal_pdf.svg" align="middle"></span>
<span class="inlinemediaobject"><img src="../../../../graphs/skew_normal_cdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.skew_normal_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.skew_normal_dist.member_functions"></a></span><a class="link" href="skew_normal_dist.html#math_toolkit.dist_ref.dists.skew_normal_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">skew_normal_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">location</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">shape</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
</pre>
<p>
Constructs a skew_normal distribution with location &#958;, scale &#969; and shape &#945;.
</p>
<p>
Requires scale &gt; 0, otherwise <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
is called.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">location</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
returns the location &#958; of this distribution,
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
returns the scale &#969; of this distribution,
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
returns the shape &#945; of this distribution.
</p>
<p>
(Location and scale function match other similar distributions, allowing
the functions <code class="computeroutput"><span class="identifier">find_location</span></code>
and <code class="computeroutput"><span class="identifier">find_scale</span></code> to be used
generically).
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
While the shape parameter may be chosen arbitrarily (finite), the resulting
<span class="bold"><strong>skewness</strong></span> of the distribution is in fact
limited to about (-1, 1); strictly, the interval is (-0.9952717, 0.9952717).
</p>
<p>
A parameter &#948; is related to the shape &#945; by &#948; = &#945; / (1 + &#945;&#178;), and used in the expression
for skewness <span class="inlinemediaobject"><img src="../../../../equations/skew_normal_skewness.svg"></span>
</p>
</td></tr>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.skew_normal_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.skew_normal_dist.references"></a></span><a class="link" href="skew_normal_dist.html#math_toolkit.dist_ref.dists.skew_normal_dist.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://azzalini.stat.unipd.it/SN/" target="_top">Skew-Normal Probability
Distribution</a> for many links and bibliography.
</li>
<li class="listitem">
<a href="http://azzalini.stat.unipd.it/SN/Intro/intro.html" target="_top">A very
brief introduction to the skew-normal distribution</a> by Adelchi
Azzalini (2005-11-2).
</li>
<li class="listitem">
See a <a href="http://www.tri.org.au/azzalini.html" target="_top">skew-normal
function animation</a>.
</li>
</ul></div>
<h5>
<a name="math_toolkit.dist_ref.dists.skew_normal_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.skew_normal_dist.non_member_accessors"></a></span><a class="link" href="skew_normal_dist.html#math_toolkit.dist_ref.dists.skew_normal_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is <span class="emphasis"><em>-[max_value], +[min_value]</em></span>.
Infinite values are not supported.
</p>
<p>
There are no <a href="http://en.wikipedia.org/wiki/Closed-form_expression" target="_top">closed-form
expression</a> known for the mode and median, but these are computed
for the
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
mode - by finding the maximum of the PDF.
</li>
<li class="listitem">
median - by computing <code class="computeroutput"><span class="identifier">quantile</span><span class="special">(</span><span class="number">1</span><span class="special">/</span><span class="number">2</span><span class="special">)</span></code>.
</li>
</ul></div>
<p>
The maximum of the PDF is sought through searching the root of f'(x)=0.
</p>
<p>
Both involve iterative methods that will have lower accuracy than other
estimates.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.skew_normal_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.skew_normal_dist.testing"></a></span><a class="link" href="skew_normal_dist.html#math_toolkit.dist_ref.dists.skew_normal_dist.testing">Testing</a>
</h5>
<p>
<a href="http://www.r-project.org/" target="_top">The R Project for Statistical Computing</a>
using library(sn) described at <a href="http://azzalini.stat.unipd.it/SN/" target="_top">Skew-Normal
Probability Distribution</a>, and at <a href="http://cran.r-project.org/web/packages/sn/sn.pd" target="_top">R
skew-normal(sn) package</a>.
</p>
<p>
Package sn provides functions related to the skew-normal (SN) and the skew-t
(ST) probability distributions, both for the univariate and for the the
multivariate case, including regression models.
</p>
<p>
<a href="http://www.wolfram.com/products/mathematica/index.html" target="_top">Wolfram
Mathematica</a> was also used to generate some more accurate spot test
data.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.skew_normal_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.skew_normal_dist.accuracy"></a></span><a class="link" href="skew_normal_dist.html#math_toolkit.dist_ref.dists.skew_normal_dist.accuracy">Accuracy</a>
</h5>
<p>
The skew_normal distribution with shape = zero is implemented as a special
case, equivalent to the normal distribution in terms of the <a class="link" href="../../sf_erf/error_function.html" title="Error Functions">error
function</a>, and therefore should have excellent accuracy.
</p>
<p>
The PDF and mean, variance, skewness and kurtosis are also accurately evaluated
using <a href="http://en.wikipedia.org/wiki/Analytical_expression" target="_top">analytical
expressions</a>. The CDF requires <a href="http://en.wikipedia.org/wiki/Owen%27s_T_function" target="_top">Owen's
T function</a> that is evaluated using a Boost C++ <a class="link" href="../../owens_t.html" title="Owen's T function">Owens
T</a> implementation of the algorithms of M. Patefield and D. Tandy,
Journal of Statistical Software, 5(5), 1-25 (2000); the complicated accuracy
of this function is discussed in detail at <a class="link" href="../../owens_t.html" title="Owen's T function">Owens
T</a>.
</p>
<p>
The median and mode are calculated by iterative root finding, and both
will be less accurate.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.skew_normal_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.skew_normal_dist.implementation"></a></span><a class="link" href="skew_normal_dist.html#math_toolkit.dist_ref.dists.skew_normal_dist.implementation">Implementation</a>
</h5>
<p>
In the following table, &#958; is the location of the distribution, and &#969; is its
scale, and &#945; is its shape.
</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: <span class="inlinemediaobject"><img src="../../../../equations/skew_normal_pdf.svg"></span>
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using: <span class="inlinemediaobject"><img src="../../../../equations/skew_normal_cdf.svg"></span><br> where <span class="emphasis"><em>T(h,a)</em></span>
is Owen's T function, and <span class="emphasis"><em>&#934;(x)</em></span> is the normal
distribution.
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using: complement of normal distribution + 2 * Owens_t
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Maximum of the pdf is sought through searching the root of f'(x)=0
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
-quantile(SN(-location &#958;, scale &#969;, -shape&#945;), p)
</p>
</td>
</tr>
<tr>
<td>
<p>
location
</p>
</td>
<td>
<p>
location &#958;
</p>
</td>
</tr>
<tr>
<td>
<p>
scale
</p>
</td>
<td>
<p>
scale &#969;
</p>
</td>
</tr>
<tr>
<td>
<p>
shape
</p>
</td>
<td>
<p>
shape &#945;
</p>
</td>
</tr>
<tr>
<td>
<p>
median
</p>
</td>
<td>
<p>
quantile(1/2)
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/skew_normal_mean.svg"></span>
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
Maximum of the pdf is sought through searching the root of f'(x)=0
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/skew_normal_variance.svg"></span>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/skew_normal_skewness.svg"></span>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
kurtosis excess-3
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/skew_normal_kurt_ex.svg"></span>
</p>
</td>
</tr>
</tbody>
</table></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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="rayleigh.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="students_t_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,441 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Students t Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="skew_normal_dist.html" title="Skew Normal Distribution">
<link rel="next" href="triangular_dist.html" title="Triangular 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="skew_normal_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="triangular_dist.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.dist_ref.dists.students_t_dist"></a><a class="link" href="students_t_dist.html" title="Students t Distribution">Students
t Distribution</a>
</h4></div></div></div>
<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">students_t</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">students_t_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">students_t_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">students_t</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">students_t_distribution</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="comment">// Constructor:</span>
<span class="identifier">students_t_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&amp;</span> <span class="identifier">v</span><span class="special">);</span>
<span class="comment">// Accessor:</span>
<span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="comment">// degrees of freedom estimation:</span>
<span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">difference_from_mean</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">sd</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">hint</span> <span class="special">=</span> <span class="number">100</span><span class="special">);</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
Student's t-distribution is a statistical distribution published by William
Gosset in 1908. His employer, Guinness Breweries, required him to publish
under a pseudonym (possibly to hide that they were using statistics to
improve beer quality), so he chose "Student".
</p>
<p>
Given N independent measurements, let
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/students_t_dist.svg"></span>
</p>
<p>
where <span class="emphasis"><em>M</em></span> is the population mean, <span class="emphasis"><em>&#956;</em></span>
is the sample mean, and <span class="emphasis"><em>s</em></span> is the sample variance.
</p>
<p>
<a href="https://en.wikipedia.org/wiki/Student%27s_t-distribution" target="_top">Student's
t-distribution</a> is defined as the distribution of the random variable
t which is - very loosely - the "best" that we can do not knowing
the true standard deviation of the sample. It has the PDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../equations/students_t_ref1.svg"></span>
</p>
<p>
The Student's t-distribution takes a single parameter: the number of degrees
of freedom of the sample. When the degrees of freedom is <span class="emphasis"><em>one</em></span>
then this distribution is the same as the Cauchy-distribution. As the number
of degrees of freedom tends towards infinity, then this distribution approaches
the normal-distribution. The following graph illustrates how the PDF varies
with the degrees of freedom &#957;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/students_t_pdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.students_t_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.member_functions"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">students_t_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&amp;</span> <span class="identifier">v</span><span class="special">);</span>
</pre>
<p>
Constructs a Student's t-distribution with <span class="emphasis"><em>v</em></span> degrees
of freedom.
</p>
<p>
Requires <span class="emphasis"><em>v</em></span> &gt; 0, including infinity (if RealType
permits), otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
Note that non-integral degrees of freedom are supported, and are meaningful
under certain circumstances.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
returns the number of degrees of freedom of this distribution.
</p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span>
<span class="identifier">RealType</span> <span class="identifier">difference_from_mean</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">sd</span><span class="special">,</span>
<span class="identifier">RealType</span> <span class="identifier">hint</span> <span class="special">=</span> <span class="number">100</span><span class="special">);</span>
</pre>
<p>
returns the number of degrees of freedom required to observe a significant
result in the Student's t test when the mean differs from the "true"
mean by <span class="emphasis"><em>difference_from_mean</em></span>.
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">difference_from_mean</span></dt>
<dd><p>
The difference between the true mean and the sample mean that we
wish to show is significant.
</p></dd>
<dt><span class="term">alpha</span></dt>
<dd><p>
The maximum acceptable probability of rejecting the null hypothesis
when it is in fact true.
</p></dd>
<dt><span class="term">beta</span></dt>
<dd><p>
The maximum acceptable probability of failing to reject the null
hypothesis when it is in fact false.
</p></dd>
<dt><span class="term">sd</span></dt>
<dd><p>
The sample standard deviation.
</p></dd>
<dt><span class="term">hint</span></dt>
<dd><p>
A hint for the location to start looking for the result, a good choice
for this would be the sample size of a previous borderline Student's
t test.
</p></dd>
</dl>
</div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
Remember that for a two-sided test, you must divide alpha by two before
calling this function.
</p></td></tr>
</table></div>
<p>
For more information on this function see the <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc222.htm" target="_top">NIST
Engineering Statistics Handbook</a>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.students_t_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.non_member_accessors"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [-&#8734;, +&#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.students_t_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.examples"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.examples">Examples</a>
</h5>
<p>
Various <a class="link" href="../../stat_tut/weg/st_eg.html" title="Student's t Distribution Examples">worked examples</a>
are available illustrating the use of the Student's t distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.students_t_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.accuracy"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.accuracy">Accuracy</a>
</h5>
<p>
The normal distribution is implemented in terms of the <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">incomplete
beta function</a> and <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">its
inverses</a>, refer to accuracy data on those functions for more information.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.students_t_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.implementation0"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.implementation0">Implementation</a>
</h5>
<p>
In the following table <span class="emphasis"><em>v</em></span> is the degrees of freedom
of the distribution, <span class="emphasis"><em>t</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 = (v / (v + t<sup>2</sup>))<sup>(1+v)/2 </sup> / (sqrt(v) *
<a class="link" href="../../sf_beta/beta_function.html" title="Beta">beta</a>(v/2,
0.5))
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relations:
</p>
<p>
p = 1 - z <span class="emphasis"><em>iff t &gt; 0</em></span>
</p>
<p>
p = z <span class="emphasis"><em>otherwise</em></span>
</p>
<p>
where z is given by:
</p>
<p>
<a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(v
/ 2, 0.5, v / (v + t<sup>2</sup>)) / 2 <span class="emphasis"><em>iff v &lt; 2t<sup>2</sup></em></span>
</p>
<p>
<a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>(0.5,
v / 2, t<sup>2 </sup> / (v + t<sup>2</sup>) / 2 <span class="emphasis"><em>otherwise</em></span>
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = cdf(-t)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: t = sign(p - 0.5) * sqrt(v * y / x)
</p>
<p>
where:
</p>
<p>
x = <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>(v
/ 2, 0.5, 2 * min(p, q))
</p>
<p>
y = 1 - x
</p>
<p>
The quantities <span class="emphasis"><em>x</em></span> and <span class="emphasis"><em>y</em></span>
are both returned by <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>
without the subtraction implied above.
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: t = -quantile(q)
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
if (v &gt; 2) v / (v - 2) else NaN
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
if (v &gt; 3) 0 else NaN
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
if (v &gt; 4) 3 * (v - 2) / (v - 4) else NaN
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
if (v &gt; 4) 6 / (df - 4) else NaN
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
If the moment index <span class="emphasis"><em>k</em></span> is less than <span class="emphasis"><em>v</em></span>,
then the moment is undefined. Evaluating the moment will throw a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
unless ignored by a policy, when it will return <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">();</span></code>
</p>
<h6>
<a name="math_toolkit.dist_ref.dists.students_t_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.implementation"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.implementation">Implementation</a>
</h6>
<p>
(By popular demand, we now support infinite argument and random deviate.
But we have not implemented the return of infinity as suggested by <a href="http://en.wikipedia.org/wiki/Student%27s_t-distribution" target="_top">Wikipedia
Student's t</a>, instead throwing a domain error or return NaN. See
also <a href="https://svn.boost.org/trac/boost/ticket/7177" target="_top">https://svn.boost.org/trac/boost/ticket/7177</a>.)
</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="skew_normal_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="triangular_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,447 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Triangular Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="students_t_dist.html" title="Students t Distribution">
<link rel="next" href="uniform_dist.html" title="Uniform 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="uniform_dist.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.dist_ref.dists.triangular_dist"></a><a class="link" href="triangular_dist.html" title="Triangular Distribution">Triangular
Distribution</a>
</h4></div></div></div>
<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">triangular</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<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">&lt;&gt;</span> <span class="identifier">triangular</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</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 symmetric 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>
&#8192;&#8192; f(x) =
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
2(x-a)/(b-a) (c-a) for a &lt;= x &lt;= c
</li>
<li class="listitem">
2(b-x)/(b-a)(b-c) for c &lt; x &lt;= b
</li>
</ul></div>
<p>
Parameter <span class="emphasis"><em>a</em></span> (lower) can be any finite value. Parameter
<span class="emphasis"><em>b</em></span> (upper) can be any finite value &gt; a (lower).
Parameter <span class="emphasis"><em>c</em></span> (mode) a &lt;= c &lt;= 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 &lt;= x &lt;= 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 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.svg" align="middle"></span>
</p>
<p>
and cumulative distribution function
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/triangular_cdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.triangular_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.member_functions"></a></span><a class="link" href="triangular_dist.html#math_toolkit.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="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top">
<p>
These constructors are slightly different from the analogs provided by
<a href="http://mathworld.wolfram.com" target="_top">Wolfram MathWorld</a>
<a href="http://reference.wolfram.com/language/ref/TriangularDistribution.html" target="_top">Triangular
distribution</a>, where
</p>
<p>
<code class="literal">TriangularDistribution[{min, max}]</code> represents a <span class="bold"><strong>symmetric</strong></span> triangular statistical distribution
giving values between min and max.<br> <code class="literal">TriangularDistribution[]</code>
represents a <span class="bold"><strong>symmetric</strong></span> triangular statistical
distribution giving values between 0 and 1.<br> <code class="literal">TriangularDistribution[{min,
max}, c]</code> represents a triangular distribution with mode at
c (usually <span class="bold"><strong>asymmetric</strong></span>).<br>
</p>
<p>
So, for example, to compute a variance using <a href="http://www.wolframalpha.com/" target="_top">Wolfram
Alpha</a>, use <code class="literal">N[variance[TriangularDistribution{1, +2}],
50]</code>
</p>
</td></tr>
</table></div>
<p>
The parameters of a distribution can be obtained using these member functions:
</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>
<h5>
<a name="math_toolkit.dist_ref.dists.triangular_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.non_member_accessors"></a></span><a class="link" href="triangular_dist.html#math_toolkit.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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is \lowerto \upper, and the supported
range is lower &lt;= x &lt;= upper.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.triangular_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.accuracy"></a></span><a class="link" href="triangular_dist.html#math_toolkit.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>
<h5>
<a name="math_toolkit.dist_ref.dists.triangular_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.implementation"></a></span><a class="link" href="triangular_dist.html#math_toolkit.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 &lt; 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 &lt; 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 &lt; p0
</p>
<p>
x = c ; for p == p0
</p>
<p>
x = b - sqrt((b-a)(b-c)q) ; for p &gt; 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 using <a href="http://www.wolframalpha.com/" target="_top">Wolfram
Alpha</a>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.triangular_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.triangular_dist.references"></a></span><a class="link" href="triangular_dist.html#math_toolkit.dist_ref.dists.triangular_dist.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Triangular_distribution" target="_top">Wikpedia
triangular distribution</a>
</li>
<li class="listitem">
<a href="http://mathworld.wolfram.com/TriangularDistribution.html" target="_top">Weisstein,
Eric W. "Triangular Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</li>
<li class="listitem">
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 class="listitem">
<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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="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="uniform_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,368 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Uniform Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="triangular_dist.html" title="Triangular Distribution">
<link rel="next" href="weibull_dist.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="triangular_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_dist.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.dist_ref.dists.uniform_dist"></a><a class="link" href="uniform_dist.html" title="Uniform Distribution">Uniform Distribution</a>
</h4></div></div></div>
<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">uniform</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">uniform_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">uniform_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">uniform</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">uniform_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="identifier">uniform_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">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_upper</span><span class="special">(</span><span class="identifier">upper</span><span class="special">)</span> <span class="comment">// Default is standard uniform 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">upper</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span> <span class="comment">// class uniform_distribution</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The uniform distribution, also known as a rectangular distribution, is
a probability distribution that has constant probability.
</p>
<p>
The <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">continuous
uniform 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 class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
1 / (upper - lower) for lower &lt; x &lt; upper
</li>
<li class="listitem">
zero for x &lt; lower or x &gt; upper
</li>
</ul></div>
<p>
and in this implementation:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
1 / (upper - lower) for x = lower or x = upper
</li></ul></div>
<p>
The choice of x = lower or x = upper is made because statistical use of
this distribution judged is most likely: the method of maximum likelihood
uses this definition.
</p>
<p>
There is also a <a href="http://en.wikipedia.org/wiki/Discrete_uniform_distribution" target="_top"><span class="bold"><strong>discrete</strong></span> uniform distribution</a>.
</p>
<p>
Parameters lower and upper can be any finite 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 &lt;= x &lt;= upper.
</p>
<p>
The lower parameter is also called the <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda364.htm" target="_top">location
parameter</a>, <a href="http://en.wikipedia.org/wiki/Location_parameter" target="_top">that
is where the origin of a plot will lie</a>, and (upper - lower) is
also called the <a href="http://en.wikipedia.org/wiki/Scale_parameter" target="_top">scale
parameter</a>.
</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 shape parameter:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/uniform_pdf.svg" align="middle"></span>
</p>
<p>
Likewise for the CDF:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/uniform_cdf.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.member_functions"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">uniform_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">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/uniform_distribution" target="_top">uniform
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> and <span class="emphasis"><em>upper</em></span>
parameters are both finite; otherwise if infinity or NaN then calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.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.
</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.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.non_member_accessors"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is any finite value, but the supported
range is only <span class="emphasis"><em>lower</em></span> &lt;= x &lt;= <span class="emphasis"><em>upper</em></span>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.accuracy"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.accuracy">Accuracy</a>
</h5>
<p>
The uniform distribution is implemented with simple arithmetic operators
and so should have errors within an epsilon or two.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.implementation"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.implementation">Implementation</a>
</h5>
<p>
In the following table a is the <span class="emphasis"><em>lower</em></span> parameter of
the distribution, 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 &lt; a, 1 / (b - a) for a &lt;=
x &lt;= b, 0 for x &gt; b
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: cdf = 0 for x &lt; a, (x - a) / (b - a) for
a &lt;= x &lt;= b, 1 for x &gt; b
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = 1 - p, (b - x) / (b - a)
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = p * (b - a) + a;
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
x = -q * (b - a) + b
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
(a + b) / 2
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
(b - a) <sup>2</sup> / 12
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
any value in [a, b] but a is chosen. (Would NaN be better?)
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
0
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
-6/5 = -1.2 exactly. (kurtosis - 3)
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
9/5
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.references"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">Wikpedia
continuous uniform distribution</a>
</li>
<li class="listitem">
<a href="http://mathworld.wolfram.com/UniformDistribution.html" target="_top">Weisstein,
Weisstein, Eric W. "Uniform Distribution." From MathWorld--A
Wolfram Web Resource.</a>
</li>
<li class="listitem">
<a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda3662.htm" target="_top">http://www.itl.nist.gov/div898/handbook/eda/section3/eda3662.htm</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="triangular_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_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,370 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Weibull Distribution</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.6.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="uniform_dist.html" title="Uniform Distribution">
<link rel="next" href="../dist_algorithms.html" title="Distribution Algorithms">
</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="uniform_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="../dist_algorithms.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.dist_ref.dists.weibull_dist"></a><a class="link" href="weibull_dist.html" title="Weibull Distribution">Weibull Distribution</a>
</h4></div></div></div>
<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">weibull</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<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">&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>
<span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter&#160;18.&#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>
<span class="keyword">class</span> <span class="identifier">weibull_distribution</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">weibull_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">weibull</span><span class="special">;</span>
<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;18.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">weibull_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="comment">// Construct:</span>
<span class="identifier">weibull_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">)</span>
<span class="comment">// Accessors:</span>
<span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
The <a href="http://en.wikipedia.org/wiki/Weibull_distribution" target="_top">Weibull
distribution</a> is a continuous distribution with the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
density function</a>:
</p>
<p>
f(x; &#945;, &#946;) = (&#945;/&#946;) * (x / &#946;)<sup>&#945; - 1</sup> * e<sup>-(x/&#946;)<sup>&#945;</sup></sup>
</p>
<p>
For shape parameter &#945; &#160; &gt; 0, and scale parameter &#946; &#160; &gt; 0, and x &gt; 0.
</p>
<p>
The Weibull distribution is often used in the field of failure analysis;
in particular it can mimic distributions where the failure rate varies
over time. If the failure rate is:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
constant over time, then &#945; &#160; = 1, suggests that items are failing from
random events.
</li>
<li class="listitem">
decreases over time, then &#945; &#160; &lt; 1, suggesting "infant mortality".
</li>
<li class="listitem">
increases over time, then &#945; &#160; &gt; 1, suggesting "wear out" -
more likely to fail as time goes by.
</li>
</ul></div>
<p>
The following graph illustrates how the PDF varies with the shape parameter
&#945;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/weibull_pdf1.svg" align="middle"></span>
</p>
<p>
While this graph illustrates how the PDF varies with the scale parameter
&#946;:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../../graphs/weibull_pdf2.svg" align="middle"></span>
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.weibull_dist.h0"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.weibull_dist.related_distributions"></a></span><a class="link" href="weibull_dist.html#math_toolkit.dist_ref.dists.weibull_dist.related_distributions">Related
distributions</a>
</h5>
<p>
When &#945; &#160; = 3, the <a href="http://en.wikipedia.org/wiki/Weibull_distribution" target="_top">Weibull
distribution</a> appears similar to the <a href="http://en.wikipedia.org/wiki/Normal_distribution" target="_top">normal
distribution</a>. When &#945; &#160; = 1, the Weibull distribution reduces to the
<a href="http://en.wikipedia.org/wiki/Exponential_distribution" target="_top">exponential
distribution</a>. The relationship of the types of extreme value distributions,
of which the Weibull is but one, is discussed by <a href="http://www.worldscibooks.com/mathematics/p191.html" target="_top">Extreme
Value Distributions, Theory and Applications Samuel Kotz &amp; Saralees
Nadarajah</a>.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.weibull_dist.h1"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.weibull_dist.member_functions"></a></span><a class="link" href="weibull_dist.html#math_toolkit.dist_ref.dists.weibull_dist.member_functions">Member
Functions</a>
</h5>
<pre class="programlisting"><span class="identifier">weibull_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</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/Weibull_distribution" target="_top">Weibull
distribution</a> with shape <span class="emphasis"><em>shape</em></span> and scale <span class="emphasis"><em>scale</em></span>.
</p>
<p>
Requires that the <span class="emphasis"><em>shape</em></span> and <span class="emphasis"><em>scale</em></span>
parameters are both greater than zero, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>shape</em></span> parameter of this distribution.
</p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
Returns the <span class="emphasis"><em>scale</em></span> parameter of this distribution.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.weibull_dist.h2"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.weibull_dist.non_member_accessors"></a></span><a class="link" href="weibull_dist.html#math_toolkit.dist_ref.dists.weibull_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_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
<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>,
<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>,
<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>,
<a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
<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>,
<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>.
</p>
<p>
The domain of the random variable is [0, &#8734;].
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.weibull_dist.h3"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.weibull_dist.accuracy"></a></span><a class="link" href="weibull_dist.html#math_toolkit.dist_ref.dists.weibull_dist.accuracy">Accuracy</a>
</h5>
<p>
The Weibull distribution is implemented in terms of the standard library
<code class="computeroutput"><span class="identifier">log</span></code> and <code class="computeroutput"><span class="identifier">exp</span></code>
functions plus <a class="link" href="../../powers/expm1.html" title="expm1">expm1</a> and
<a class="link" href="../../powers/log1p.html" title="log1p">log1p</a> and as such should
have very low error rates.
</p>
<h5>
<a name="math_toolkit.dist_ref.dists.weibull_dist.h4"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.weibull_dist.implementation"></a></span><a class="link" href="weibull_dist.html#math_toolkit.dist_ref.dists.weibull_dist.implementation">Implementation</a>
</h5>
<p>
In the following table &#945; &#160; is the shape parameter of the distribution, &#946; &#160; is its
scale 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 = &#945;&#946;<sup>-&#945; </sup>x<sup>&#945; - 1</sup> e<sup>-(x/beta)<sup>alpha</sup></sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf
</p>
</td>
<td>
<p>
Using the relation: p = -<a class="link" href="../../powers/expm1.html" title="expm1">expm1</a>(-(x/&#946;)<sup>&#945;</sup>)
</p>
</td>
</tr>
<tr>
<td>
<p>
cdf complement
</p>
</td>
<td>
<p>
Using the relation: q = e<sup>-(x/&#946;)<sup>&#945;</sup></sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile
</p>
</td>
<td>
<p>
Using the relation: x = &#946; * (-<a class="link" href="../../powers/log1p.html" title="log1p">log1p</a>(-p))<sup>1/&#945;</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
quantile from the complement
</p>
</td>
<td>
<p>
Using the relation: x = &#946; * (-log(q))<sup>1/&#945;</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
mean
</p>
</td>
<td>
<p>
&#946; * &#915;(1 + 1/&#945;)
</p>
</td>
</tr>
<tr>
<td>
<p>
variance
</p>
</td>
<td>
<p>
&#946;<sup>2</sup>(&#915;(1 + 2/&#945;) - &#915;<sup>2</sup>(1 + 1/&#945;))
</p>
</td>
</tr>
<tr>
<td>
<p>
mode
</p>
</td>
<td>
<p>
&#946;((&#945; - 1) / &#945;)<sup>1/&#945;</sup>
</p>
</td>
</tr>
<tr>
<td>
<p>
skewness
</p>
</td>
<td>
<p>
Refer to <a href="http://mathworld.wolfram.com/WeibullDistribution.html" target="_top">Weisstein,
Eric W. "Weibull Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis
</p>
</td>
<td>
<p>
Refer to <a href="http://mathworld.wolfram.com/WeibullDistribution.html" target="_top">Weisstein,
Eric W. "Weibull Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
kurtosis excess
</p>
</td>
<td>
<p>
Refer to <a href="http://mathworld.wolfram.com/WeibullDistribution.html" target="_top">Weisstein,
Eric W. "Weibull Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</p>
</td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.weibull_dist.h5"></a>
<span class="phrase"><a name="math_toolkit.dist_ref.dists.weibull_dist.references"></a></span><a class="link" href="weibull_dist.html#math_toolkit.dist_ref.dists.weibull_dist.references">References</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://en.wikipedia.org/wiki/Weibull_distribution" target="_top">http://en.wikipedia.org/wiki/Weibull_distribution</a>
</li>
<li class="listitem">
<a href="http://mathworld.wolfram.com/WeibullDistribution.html" target="_top">Weisstein,
Eric W. "Weibull Distribution." From MathWorld--A Wolfram
Web Resource.</a>
</li>
<li class="listitem">
<a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda3668.htm" target="_top">Weibull
in NIST Exploratory Data Analysis</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 &#169; 2006-2010, 2012-2014, 2017 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;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="uniform_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="../dist_algorithms.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>