Sampling from a probability density function

From HandWiki


Frequently, a random sample is required that exhibits a known probability density function. Random number generators, on the other hand, usually supply samples with a uniform distribution, typically between 0 and 1. What is needed is a recipe for converting the flat probability density function (pdf) to the desired (``target) pdf. Call the target pdf f(x); distribution function is defined by

File:Hepa img985.gif

By definition,

File:Hepa img986.gif

F(x) is uniformly distributed over the interval [0,1], for all f(x); hence a uniformly distributed random number r can be interpreted as a random value of F(x). If a generator supplies r, the variable x is obtained by solving

File:Hepa img987.gif

for x. If f(x) is not analytically integrable, or only known in discretized form (e.g. as a histogram), simple methods of numerical integration and, possibly, interpolation will usually suffice.