A distribution with an inverse cumulative distribution function (CDF) can be sampled from using just samples from . The inverse CDF (sometimes called the quantile function) is the value of such that . Consider a that a transformation , exists which takes a value sampled from the standard uniform distribution and returns a value distributed according to the target distribution. Then the inverse CDF can be written as:
Since the CDF of the uniform distribution over the interval is:
$$$$
Then as required. The algorithm below summarises the inverse sampling procedure.
Sample
Evaluate
Return
Most statistical packages will expose the quantile function for common distributions making it practical to use inverse sampling. The figure below shows a histogram of 1,000 simulated values from a distribution using the inverse CDF method, the analytical density is plotted in red.
The figure below shows samples from using the inverse CDF method plotted with the analytical PDF.