prob


prob, a MATLAB code which handles various discrete and continuous probability density functions (PDF).

For a discrete variable X, PDF(X) is the probability that the value X will occur; for a continuous variable, PDF(X) is the probability density of X, that is, the probability of a value between X and X+dX is PDF(X) * dX.

The corresponding cumulative density functions or "CDF"'s are also handled. For a discrete or continuous variable, CDF(X) is the probability that the variable takes on a value less than or equal to X.

In some cases, the inverse of the CDF can easily be computed. If


        X = CDF_INV ( P ) 
      
then we are asserting that the value X has a cumulative probability density function of P, in other words, the probability that the variable is less than or equal to X is P. If the CDF cannot be analytically inverted, there are simple ways to try to estimate the inverse. Depending on the PDF, these methods may be rapid and accurate, or not.

For most distributions, the mean or "average value" or "expected value" is also available. For a discrete variable, MEAN is simply the sum of the products X * PDF(X); for a continuous variable, MEAN is the integral of X * PDF(X) over the range. For the distributions covered here, the means are known beforehand, and no summation or integration is required.

For most distributions, the variance is available. For a discrete variable, the variance is the sum of the products ( X - MEAN )^2 * PDF(X); for a continuous variable, the variance is the integral of ( X - MEAN )^2 * PDF(X) over the range. The square root of the variance is known as the standard deviation. For the distributions covered here, the variances are often known beforehand, and no summation or integration is required.

For many of the distributions, it is possible to repeatedly request "samples", that is, a pseudorandom sequence of realizations of the PDF. These samples are always associated with an integer seed, which controls the calculation. Using the same seed as input will guarantee the same sample value on output. Ultimately, a random number generator must be invoked internally. In most cases, the current code will call a routine called r8_uniform_ab() or i4_uniform_ab(), each of which in turn calls a routine called r8_uniform_01(). You may prefer a different random number generator for this purpose.

Licensing:

The computer code and data files described and made available on this web page are distributed under the MIT license

Languages:

prob is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

Related Data and Programs:

discrete_pdf_sample_2d, a MATLAB code which demonstrates how to construct a probability density function (pdf) from a table of sample data, and then to use that pdf to create new samples.

histogram_pdf_2d_sample, a MATLAB code which demonstrates how uniform sampling of a 2d region with respect to some known probability density function (pdf) can be approximated by decomposing the region into rectangles, approximating the pdf by a piecewise constant function, constructing a histogram for the cdf, and then sampling.

log_normal, a MATLAB code which returns quantities associated with the log normal probability distribution function (pdf).

log_normal_truncated_ab, a MATLAB code which returns quantities associated with the log normal probability distribution function (pdf) truncated to the interval [a,b].

normal, a MATLAB code which samples the normal distribution.

pdflib, a MATLAB code which evaluates probability density functions (pdf's) and produces random samples from them, including beta, binomial, chi, exponential, gamma, inverse chi, inverse gamma, multinomial, normal, scaled inverse chi, and uniform.

prob_test

test_values, a MATLAB code which contains sample values for a number of distributions.

truncated_normal, a MATLAB code which works with the truncated normal distribution over [a,b], or [a,+oo) or (-oo,b], returning the probability density function (pdf), the cumulative density function (cdf), the inverse cdf, the mean, the variance, and sample values.

uniform, a MATLAB code which samples the uniform distribution.

Source Code:


Last revised on 11 November 2022.