Inverse transform sampling (also known as inversion sampling, the inverse probability integral transform, the inverse transformation method, or the Smirnov transform) is a basic method for pseudo-random number sampling, i.e., for generating sample numbers at random from any probability distribution given its cumulative distribution function.
Inverse transformation sampling takes uniform samples of a number
u
x\inR
F(x)\geu
F
F
u | F-1(u) | |
---|---|---|
.5 | 0 | |
.975 | 1.95996 | |
.995 | 2.5758 | |
.999999 | 4.75342 | |
1-2−52 | 8.12589 |
We are randomly choosing a proportion of the area under the curve and returning the number in the domain such that exactly this proportion of the area occurs to the left of that number. Intuitively, we are unlikely to choose a number in the far end of tails because there is very little area in them which would require choosing a number very close to zero or one.
Computationally, this method involves computing the quantile function of the distribution — in other words, computing the cumulative distribution function (CDF) of the distribution (which maps a number in the domain to a probability between 0 and 1) and then inverting that function. This is the source of the term "inverse" or "inversion" in most of the names for this method. Note that for a discrete distribution, computing the CDF is not in general too difficult: we simply add up the individual probabilities for the various points of the distribution. For a continuous distribution, however, we need to integrate the probability density function (PDF) of the distribution, which is impossible to do analytically for most distributions (including the normal distribution). As a result, this method may be computationally inefficient for many distributions and other methods are preferred; however, it is a useful method for building more generally applicable samplers such as those based on rejection sampling.
For the normal distribution, the lack of an analytical expression for the corresponding quantile function means that other methods (e.g. the Box–Muller transform) may be preferred computationally. It is often the case that, even for simple distributions, the inverse transform sampling method can be improved on:[1] see, for example, the ziggurat algorithm and rejection sampling. On the other hand, it is possible to approximate the quantile function of the normal distribution extremely accurately using moderate-degree polynomials, and in fact the method of doing this is fast enough that inversion sampling is now the default method for sampling from a normal distribution in the statistical package R.[2]
X\inR
-1 | |
F | |
X |
(U)
X
-1 | |
F | |
X |
FX
X
U
[0,1]
X
FX
U=FX(X)
[0,1]
From
U\simUnif[0,1]
X
FX(x).
FX(x)
We want to see if we can find some strictly monotone transformation
T:[0,1]\mapstoR
T(U)\overset{d}{=}X
FX(x)=\Pr(X\leqx)=\Pr(T(U)\leqx)=\Pr(U\leqT-1(x))=T-1(x),forx\inR,
where the last step used that
\Pr(U\leqy)=y
U
[0,1]
So we got
FX
T
-1 | |
T(u)=F | |
X |
(u),u\in[0,1].
Therefore, we can generate
X
-1 | |
F | |
X |
(U).
The problem that the inverse transform sampling method solves is as follows:
X
FX
X
The inverse transform sampling method works as follows:
u
[0,1]
U\simUnif[0,1].
-1 | |
F | |
X |
(u)
-1 | |
X'(u)=F | |
X |
(u)
X'(U)
FX
X
Expressed differently, given a cumulative distribution function
FX
U\in[0,1]
X=
-1 | |
F | |
X |
(U)
FX
In the continuous case, a treatment of such inverse functions as objects satisfying differential equations can be given.[4] Some such differential equations admit explicit power series solutions, despite their non-linearity.[5]
U\simUnif(0,1)
\begin{align} F(x)=1-\exp(-\sqrt{x}) \end{align}
In order to perform an inversion we want to solve for
F(F-1(u))=u
\begin{align} F(F-1(u))&=u\\ 1-\exp\left(-\sqrt{F-1(u)}\right)&=u\\ F-1(u)&=(-log(1-u))2\\ &=(log(1-u))2 \end{align}
From here we would perform steps one, two and three.
-λx | |
F | |
X(x)=1-e |
x=F-1(y)=-
1 | |
λ |
ln(1-y).
It means that if we draw some
y0
U\simUnif(0,1)
x0=
-1 | |
F | |
X |
(y0)=-
1 | |
λ |
ln(1-y0),
x0
The idea is illustrated in the following graph:
Note that the distribution does not change if we start with 1-y instead of y. For computational purposes, it therefore suffices to generate random numbers y in [0, 1] and then simply calculate
x=F-1(y)=-
1 | |
λ |
ln(y).
Let
F
F-1
F-1(u)=inf \{x\midF(x)\gequ\} (0<u<1).
Claim: If
U
[0,1]
F-1(U)
F
Proof:
\begin{align} &\Pr(F-1(U)\leqx)\\ &{}=\Pr(U\leqF(x)) &(Fisright-continuous,so\{u:F-1(u)\lex\}=\{u:u\leF(x)\})\\ &{}=F(x) &(because\Pr(U\lequ)=u,whenUisuniformon[0,1])\\ \end{align}
Inverse transform sampling can be simply extended to cases of truncated distributions on the interval
(a,b]
u
u
F(a)
F(b)
F-1(u)
In order to obtain a large number of samples, one needs to perform the same number of inversions of the distribution. One possible way to reduce the number of inversions while obtaining a large number of samples is the application of the so-called Stochastic Collocation Monte Carlo sampler (SCMC sampler) within a polynomial chaos expansion framework. This allows us to generate any number of Monte Carlo samples with only a few inversions of the original distribution with independent samples of a variable for which the inversions are analytically available, for example the standard normal variable.[7]
There are software implementations available for applying the inverse sampling method by using numerical approximations of the inverse in the case that it is not available in closed form. For example, an approximation of the inverse can be computed if the user provides some information about the distributions such as the PDF [8] or the CDF.