Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since C++11, the Standard Library contains a bunch of distributions that can be used for random number generation. Unfortunately, there is no functionality for computing probability densities, cumulative distributions or quantile functions in the Standard Library. </p> <p>As for a rationale why this was not included in the Standard Library, see the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1398.html"><strong>working paper N1398</strong></a> (emphasis mine)</p> <blockquote> <p>Some libraries provide the probability density function of a given distribution as part of that distribution's interface. While this may be useful occasionally, this proposal does not provide for such a feature. One reason is separation of concerns: The distribution class templates might benefit from precomputing large tables of values depending on the distribution parameters, while the computation of the probability density function does not. <strong>Also, the function representation is often straightforward, so the user can easily code it himself.</strong></p> </blockquote> <p>I don't quite agree with this reasoning: while it is true that the density functions are easy enough to code, the same does not hold for the cumulative distribution or quantile functions.</p> <p>As a workaround, you could go to the <a href="http://www.boost.org/doc/libs/1_54_0/libs/math/doc/html/index.html"><strong>Boost Math Toolkit</strong></a>. It uses the same names as the Standard Library for the distributions, but allows you to compute <code>pdf()</code> and many more properties for these distributions. Boost libraries often find their way into the Standard, and if not, they are at least platform independent and widely available. Your example would be something like:</p> <pre><code>#include &lt;iostream&gt; #include &lt;boost/math/distributions/exponential.hpp&gt; using namespace boost::math; int main() { auto const lambda = 1.0; auto d = exponential_distribution&lt;&gt;{lambda}; std::cout &lt;&lt; pdf(d, 0) &lt;&lt; "\n"; // exp(0) = 1 std::cout &lt;&lt; pdf(d, 1) &lt;&lt; "\n"; // exp(-1) = 0.367879 } </code></pre> <p><a href="http://coliru.stacked-crooked.com/a/eb7fbfa3a9abad57"><strong>Live Example</strong></a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload