Probabilities
Probability Density Functions (PDFs)
This is the graph you’ll typically see when talking about distributions, for example the classic Normal (Gaussian) distribution:
This site uses the notation to represent the probability density function of .
Cumulative Density Function (CDFs)
The cumulative density function (CDF) is a function which gets a PDF and for any x
, cumulatively sums up the probability up to that point. The y-axis always starts a and ends at .
This site uses the notation to represent the cumulative density function of .
Quantile Function
The quantile function is the inverse of the cumulative density function (CDF). Also called the percentage point function (PPF) or ICDF (inverse cumulative density function).
The quantile function is a great way of generating random numbers that follow a specific distribution. Starting with uniformly distributed random numbers in the range from to (which is trivially easy to do in most programming languages), you can transform these numbers with the quantile function into random numbers which follow your specific probability distribution.
Generating Random Numbers That Follow A Custom PDF
This section shows you how you can generate an arbitrary number of random numbers that follow a specific distribution. The distribution is defined by a probability density function (all though you could quite as easily define it by the CDF or quantile function). The code example is done in Python.
Let’s define a custom PDF. For this example I just used sin(x)
in the range from 0
to pi
, but it could be anything you want. Make sure that you scale the PDF so that the total area under the curve is 1 (i.e. divide the function by it’s integral, see the code below for how this is done):
Now let’s normalize the PDF so the total area under the curve is 1:
sin(x)
in the range of 0
to pi
.Now find the quantile function (PPF):
Now lets generate some random numbers!
Histogram showing the distribution of the 10,000 generated random numbers:
Generating Random Points On A Sphere
For many different applications, you might find yourself needing to generate random points on a sphere, with the condition that they must be uniformly distributed. You then might think you could do this by using spherical coordinates and:
. Randomly picking a value for (polar angle, measured from the positive Z-axis) between and . . Randomly picking a value for (azimuthal angle)
However, this does not give points that are uniformly distributed! You will find that points will be clustered closer together at the poles of the sphere.
Instead of being uniform, the PDF for (which we will label ) needs to be proportional to a sine curve, where1:
References
Footnotes
-
Simon, C. (2015, Feb 27). Generating uniformly distributed numbers on a sphere. Mathemathinking. Retrieved 2021-08-08, from http://corysimon.github.io/articles/uniformdistn-on-sphere/ ↩