blob: da6ea755b809cd032affc0bc8d21fe9d0371d5d8 [file] [log] [blame]
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<?xml-stylesheet type="text/xsl" href="./xdoc.xsl"?>
<document url="distribution.html">
<properties>
<title>The Commons Math User Guide - Distributions</title>
</properties>
<body>
<section name="1 Probability Distributions">
<subsection name="1.1 Overview" href="overview">
<p>
The distributions package provides a framework and implementations for some commonly used
probability distributions. Continuous univariate distributions are represented by implementations of
the <a href="../commons-statistics-distribution/apidocs/org/apache/commons/statistics/distribution/ContinuousDistribution.html">ContinuousDistribution</a>
interface. Discrete distributions implement
<a href="../commons-statistics-distribution/apidocs/org/apache/commons/statistics/distribution/DiscreteDistribution.html">DiscreteDistribution</a>
(values must be mapped to integers).
</p>
</subsection>
<subsection name="1.2 API" href="distributions">
<p>
The distribution framework provides the means to compute probability density,
probability mass and cumulative probability functions for several well-known
discrete (integer-valued) and continuous probability distributions.
The API also allows for the computation of inverse cumulative probabilities
and sampling from distributions.
</p>
<p>
For an instance <code>f</code> of a distribution <code>F</code>,
and a domain value, <code>x</code>, <code>f.cumulativeProbability(x)</code>
computes <code>P(X &lt;= x)</code> where <code>X</code> is a random variable distributed
as <code>F</code>.
For <a href="../commons-statistics-distribution/apidocs/org/apache/commons/statistics/distribution/DiscreteDistribution.html">discrete</a>
<code>F</code>, the probability mass function is given by <code>f.probability(x)</code>.
For <a href="../commons-statistics-distribution/apidocs/org/apache/commons/statistics/distribution/ContinuousDistribution.html">continuous</a>
<code>F</code>, the probability density function is given by <code>f.density(x)</code>.
Continuous distributions also implement <code>f.probability(x1, x2)</code> for computing
<code>P(x1 &lt;= X &lt;= x2)</code>.
</p>
<source>TDistribution t = new TDistribution(29);
double lowerTail = t.cumulativeProbability(-2.656); // P(T(29) &lt;= -2.656)
double upperTail = 1.0 - t.cumulativeProbability(2.75); // P(T(29) &gt;= 2.75)</source>
<p>
All distributions implement a <code>createSampler(UniformRandomProvider rng)</code>
method to support random sampling from the distribution, where <code>UniformRandomProvider</code>
is an interface defined in <a href="https://commons.apache.org/rng">Commons RNG</a>.
</p>
<p>
Inverse distribution functions can be computed using the
<code>inverseCumulativeProbability</code> methods. For continuous <code>f</code>
and <code>p</code> a probability, <code>f.inverseCumulativeProbability(p)</code> returns
<ul>
<li><code>inf{x in R | P(X &le; x) &ge; p} for 0 &lt; p &lt; 1},</code></li>
<li><code>inf{x in R | P(X &le; x) &gt; 0} for p = 0}.</code></li>
</ul>
where <code>X</code> is distributed as <code>F</code>.<br/>
For discrete <code>F</code>, the definition is the same, with <code>Z</code> (the integers)
in place of <code>R</code> (but note that, in the discrete case, the &ge; in the definition
can make a difference when <code>p</code> is an attained value of the distribution).
</p>
</subsection>
</section>
</body>
</document>