Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > 623999701586b0ea103ff2ccad7954a6 > files > 7324

boost-doc-1.44.0-1.fc14.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Uniform Distribution</title>
<link rel="stylesheet" href="../../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
<link rel="home" href="../../../../index.html" title="Math Toolkit">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="weibull.html" title="Weibull 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="weibull.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" lang="en">
<div class="titlepage"><div><div><h5 class="title">
<a name="math_toolkit.dist.dist_ref.dists.uniform_dist"></a><a class="link" href="uniform_dist.html" title="Uniform Distribution"> Uniform
          Distribution</a>
</h5></div></div></div>
<p>
            
</p>
<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>
<p>
          </p>
<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="Policies">Policy</a>   <span class="special">=</span> <a class="link" href="../../../policy/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="Policies">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 type="disc">
<li>
                1 / (upper - lower) for lower &lt; x &lt; upper
              </li>
<li>
                zero for x &lt; lower or x &gt; upper
              </li>
</ul></div>
<p>
            and in this implementation:
          </p>
<div class="itemizedlist"><ul type="disc"><li>
                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.png" align="middle"></span>
          </p>
<p>
            Likewise for the CDF:
          </p>
<p>
            <span class="inlinemediaobject"><img src="../../../../../graphs/uniform_cdf.png" align="middle"></span>
          </p>
<a name="math_toolkit.dist.dist_ref.dists.uniform_dist.member_functions"></a><h5>
<a name="id1067212"></a>
            <a class="link" href="uniform_dist.html#math_toolkit.dist.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="../../../main_overview/error_handling.html#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>
<a name="math_toolkit.dist.dist_ref.dists.uniform_dist.non_member_accessors"></a><h5>
<a name="id1067377"></a>
            <a class="link" href="uniform_dist.html#math_toolkit.dist.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.dist.cdf">Cumulative Distribution Function</a>,
            <a class="link" href="../nmp.html#math.dist.pdf">Probability Density Function</a>, <a class="link" href="../nmp.html#math.dist.quantile">Quantile</a>, <a class="link" href="../nmp.html#math.dist.hazard">Hazard
            Function</a>, <a class="link" href="../nmp.html#math.dist.chf">Cumulative Hazard Function</a>,
            <a class="link" href="../nmp.html#math.dist.mean">mean</a>, <a class="link" href="../nmp.html#math.dist.median">median</a>,
            <a class="link" href="../nmp.html#math.dist.mode">mode</a>, <a class="link" href="../nmp.html#math.dist.variance">variance</a>,
            <a class="link" href="../nmp.html#math.dist.sd">standard deviation</a>, <a class="link" href="../nmp.html#math.dist.skewness">skewness</a>,
            <a class="link" href="../nmp.html#math.dist.kurtosis">kurtosis</a>, <a class="link" href="../nmp.html#math.dist.kurtosis_excess">kurtosis_excess</a>,
            <a class="link" href="../nmp.html#math.dist.range">range</a> and <a class="link" href="../nmp.html#math.dist.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>
<a name="math_toolkit.dist.dist_ref.dists.uniform_dist.accuracy"></a><h5>
<a name="id1067482"></a>
            <a class="link" href="uniform_dist.html#math_toolkit.dist.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>
<a name="math_toolkit.dist.dist_ref.dists.uniform_dist.implementation"></a><h5>
<a name="id1067501"></a>
            <a class="link" href="uniform_dist.html#math_toolkit.dist.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>
<a name="math_toolkit.dist.dist_ref.dists.uniform_dist.references"></a><h5>
<a name="id1068337"></a>
            <a class="link" href="uniform_dist.html#math_toolkit.dist.dist_ref.dists.uniform_dist.references">References</a>
          </h5>
<div class="itemizedlist"><ul type="disc">
<li>
                <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">Wikpedia
                continuous uniform distribution</a>
              </li>
<li>
                <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>
                <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 , 2007, 2008, 2009 John Maddock, Paul A. Bristow,
      Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan R&#229;de, Gautam Sewani
      and Thijs van den Berg<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="weibull.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>