Inverse Transform Method for Continuous Random Variables

Basic method for pseudo-random number sampling

Inverse transform sampling (also known as inversion sampling, the inverse probability integral transform, the inverse transformation method, Smirnov transform, or the golden rule [1]) 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 {\displaystyle u} between 0 and 1, interpreted as a probability, and then returns the largest number x {\displaystyle x} from the domain of the distribution P ( X ) {\displaystyle P(X)} such that P ( < X < x ) u {\displaystyle P(-\infty <X<x)\leq u} . For example, imagine that P ( X ) {\displaystyle P(X)} is the standard normal distribution with mean zero and standard deviation one. The table below shows samples taken from the uniform distribution and their representation on the standard normal distribution.

Transformation from uniform sample to normal
u {\displaystyle u} F 1 ( u ) {\displaystyle F^{-1}(u)}
.5 0
.975 1.95996
.995 2.5758
.999999 4.75342
1-2−52 8.12589

Inverse transform sampling for normal distribution

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:[2] 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.[3]

Definition [edit]

The probability integral transform states that if X {\displaystyle X} is a continuous random variable with cumulative distribution function F X {\displaystyle F_{X}} , then the random variable Y = F X ( X ) {\displaystyle Y=F_{X}(X)} has a uniform distribution on [0, 1]. The inverse probability integral transform is just the inverse of this: specifically, if Y {\displaystyle Y} has a uniform distribution on [0, 1] and if X {\displaystyle X} has a cumulative distribution F X {\displaystyle F_{X}} , then the random variable F X 1 ( Y ) {\displaystyle F_{X}^{-1}(Y)} has the same distribution as X {\displaystyle X} .

Graph of the inversion technique from x {\displaystyle x} to F ( x ) {\displaystyle F(x)} . On the bottom right we see the regular function and in the top left its inversion.

Intuition [edit]

From U U n i f [ 0 , 1 ] {\displaystyle U\sim \mathrm {Unif} [0,1]} , we want to generate X {\displaystyle X} with CDF F X ( x ) . {\displaystyle F_{X}(x).} We assume F X ( x ) {\displaystyle F_{X}(x)} to be a strictly increasing function, which provides good intuition.

We want to see if we can find some strictly monotone transformation T : [ 0 , 1 ] R {\displaystyle T:[0,1]\mapsto \mathbb {R} } , such that T ( U ) = d X {\displaystyle T(U){\overset {d}{=}}X} . We will have

F X ( x ) = Pr ( X x ) = Pr ( T ( U ) x ) = Pr ( U T 1 ( x ) ) = T 1 ( x ) ,  for x R , {\displaystyle F_{X}(x)=\Pr(X\leq x)=\Pr(T(U)\leq x)=\Pr(U\leq T^{-1}(x))=T^{-1}(x),{\text{ for }}x\in \mathbb {R} ,}

where the last step used that Pr ( U y ) = y {\displaystyle \Pr(U\leq y)=y} when U {\displaystyle U} is uniform on ( 0 , 1 ) {\displaystyle (0,1)} .

So we got F X {\displaystyle F_{X}} to be the inverse function of T {\displaystyle T} , or, equivalently T ( u ) = F X 1 ( u ) , u [ 0 , 1 ] . {\displaystyle T(u)=F_{X}^{-1}(u),u\in [0,1].}

Therefore, we can generate X {\displaystyle X} from F X 1 ( U ) . {\displaystyle F_{X}^{-1}(U).}

The method [edit]

Schematic of the inverse transform sampling. The inverse function of y = F X ( x ) {\displaystyle y=F_{X}(x)} can be defined by F X 1 ( y ) = i n f { x | F X ( x ) y } {\displaystyle F_{X}^{-1}(y)=\mathrm {inf} \{x|F_{X}(x)\geq y\}} .

An animation of how inverse transform sampling generates normally distributed random values from uniformly distributed random values

The problem that the inverse transform sampling method solves is as follows:

The inverse transform sampling method works as follows:

  1. Generate a random number u {\displaystyle u} from the standard uniform distribution in the interval [ 0 , 1 ] {\displaystyle [0,1]} , e.g. from U U n i f [ 0 , 1 ] . {\displaystyle U\sim \mathrm {Unif} [0,1].}
  2. Find the inverse of the desired CDF, e.g. F X 1 ( x ) {\displaystyle F_{X}^{-1}(x)} .
  3. Compute X = F X 1 ( u ) {\displaystyle X=F_{X}^{-1}(u)} . The computed random variable X {\displaystyle X} has distribution F X ( x ) {\displaystyle F_{X}(x)} .

Expressed differently, given a continuous uniform variable U {\displaystyle U} in [ 0 , 1 ] {\displaystyle [0,1]} and an invertible cumulative distribution function F X {\displaystyle F_{X}} , the random variable X = F X 1 ( U ) {\displaystyle X=F_{X}^{-1}(U)} has distribution F X {\displaystyle F_{X}} (or, X {\displaystyle X} is distributed F X {\displaystyle F_{X}} ).

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]

Examples [edit]

  • As an example, suppose we have a random variable U U n i f ( 0 , 1 ) {\displaystyle U\sim \mathrm {Unif} (0,1)} and a cumulative distribution function
F ( x ) = 1 exp ( x ) {\displaystyle {\begin{aligned}F(x)=1-\exp(-{\sqrt {x}})\end{aligned}}}
In order to perform an inversion we want to solve for F ( F 1 ( u ) ) = u {\displaystyle F(F^{-1}(u))=u}
F ( F 1 ( u ) ) = u 1 exp ( F 1 ( u ) ) = u F 1 ( u ) = ( log ( 1 u ) ) 2 = ( log ( 1 u ) ) 2 {\displaystyle {\begin{aligned}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{aligned}}}
From here we would perform steps one, two and three.
  • As another example, we use the exponential distribution with F X ( x ) = 1 e λ x {\displaystyle F_{X}(x)=1-e^{-\lambda x}} for x ≥ 0 (and 0 otherwise). By solving y=F(x) we obtain the inverse function
x = F 1 ( y ) = 1 λ ln ( 1 y ) . {\displaystyle x=F^{-1}(y)=-{\frac {1}{\lambda }}\ln(1-y).}
It means that if we draw some y 0 {\displaystyle y_{0}} from a U U n i f ( 0 , 1 ) {\displaystyle U\sim \mathrm {Unif} (0,1)} and compute x 0 = F X 1 ( y 0 ) = 1 λ ln ( 1 y 0 ) , {\displaystyle x_{0}=F_{X}^{-1}(y_{0})=-{\frac {1}{\lambda }}\ln(1-y_{0}),} This x 0 {\displaystyle x_{0}} has exponential distribution.
The idea is illustrated in the following graph:

Random numbers yi are generated from a uniform distribution between 0 and 1, i.e. Y ~ U(0, 1). They are sketched as colored points on the y-axis. Each of the points is mapped according to x=F−1(y), which is shown with gray arrows for two example points. In this example, we have used an exponential distribution. Hence, for x ≥ 0, the probability density is ϱ X ( x ) = λ e λ x {\displaystyle \varrho _{X}(x)=\lambda e^{-\lambda \,x}} and the cumulative distribution function is F ( x ) = 1 e λ x {\displaystyle F(x)=1-e^{-\lambda \,x}} . Therefore, x = F 1 ( y ) = ln ( 1 y ) λ {\displaystyle x=F^{-1}(y)=-{\frac {\ln(1-y)}{\lambda }}} . We can see that using this method, many points end up close to 0 and only few points end up having high x-values - just as it is expected for an exponential distribution.

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 ) . {\displaystyle x=F^{-1}(y)=-{\frac {1}{\lambda }}\ln(y).}

Proof of correctness [edit]

Let F be a continuous cumulative distribution function, and let F −1 be its inverse function (using the infimum because CDFs are weakly monotonic and right-continuous):[6]

F 1 ( u ) = inf { x F ( x ) u } ( 0 < u < 1 ) . {\displaystyle F^{-1}(u)=\inf \;\{x\mid F(x)\geq u\}\qquad (0<u<1).}

Claim: If U is a uniform random variable on (0, 1) then F 1 ( U ) {\displaystyle F^{-1}(U)} has F as its CDF.

Proof:

Pr ( F 1 ( U ) x ) = Pr ( U F ( x ) ) ( applying F ,  to both sides ) = F ( x ) ( because Pr ( U y ) = y ,  when U is uniform on ( 0 , 1 ) ) {\displaystyle {\begin{aligned}&\Pr(F^{-1}(U)\leq x)\\&{}=\Pr(U\leq F(x))\quad &({\text{applying }}F,{\text{ to both sides}})\\&{}=F(x)\quad &({\text{because }}\Pr(U\leq y)=y,{\text{ when U is uniform on}}(0,1))\\\end{aligned}}}

Truncated distribution [edit]

Inverse transform sampling can be simply extended to cases of truncated distributions on the interval ( a , b ] {\displaystyle (a,b]} without the cost of rejection sampling: the same algorithm can be followed, but instead of generating a random number u {\displaystyle u} uniformly distributed between 0 and 1, generate u {\displaystyle u} uniformly distributed between F ( a ) {\displaystyle F(a)} and F ( b ) {\displaystyle F(b)} , and then again take F 1 ( u ) {\displaystyle F^{-1}(u)} .

Reduction of the number of inversions [edit]

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]

See also [edit]

  • Probability integral transform
  • Copula, defined by means of probability integral transform.
  • Quantile function, for the explicit construction of inverse CDFs.
  • Inverse distribution function for a precise mathematical definition for distributions with discrete components.

References [edit]

  1. ^ Aalto University, N. Hyvönen, Computational methods in inverse problems. Twelfth lecture https://noppa.tkk.fi/noppa/kurssi/mat-1.3626/luennot/Mat-1_3626_lecture12.pdf [ permanent dead link ]
  2. ^ Luc Devroye (1986). Non-Uniform Random Variate Generation (PDF). New York: Springer-Verlag.
  3. ^ "R: Random Number Generation".
  4. ^ Steinbrecher, György; Shaw, William T. (19 March 2008). "Quantile mechanics". European Journal of Applied Mathematics. 19 (2). doi:10.1017/S0956792508007341.
  5. ^ Arridge, Simon; Maass, Peter; Öktem, Ozan; Schönlieb, Carola-Bibiane. "Solving inverse problems using data-driven models". Acta Numerica. 28: 1–174. doi:10.1017/S0962492919000059. ISSN 0962-4929.
  6. ^ Luc Devroye (1986). "Section 2.2. Inversion by numerical solution of F(X) =U" (PDF). Non-Uniform Random Variate Generation. New York: Springer-Verlag.
  7. ^ L.A. Grzelak, J.A.S. Witteveen, M. Suarez, and C.W. Oosterlee. The stochastic collocation Monte Carlo sampler: Highly efficient sampling from "expensive" distributions. https://ssrn.com/abstract=2529691

rylandenalland1953.blogspot.com

Source: https://en.wikipedia.org/wiki/Inverse_transform_sampling

0 Response to "Inverse Transform Method for Continuous Random Variables"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel