Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Inverse transform sampling

From Wikipedia, the free encyclopedia
Basic method for pseudo-random number sampling

Inverse transform sampling (also known asinversion sampling, theinverse probability integral transform, theinverse transformation method, or theSmirnov transform) is a basic method forpseudo-random number sampling, i.e., for generating sample numbers atrandom from anyprobability distribution given itscumulative distribution function.

Inverse transformation sampling takesuniform samples of a numberu{\displaystyle u} between 0 and 1, interpreted as a probability, and then returns the smallest numberxR{\displaystyle x\in \mathbb {R} } such thatF(x)u{\displaystyle F(x)\geq u} for thecumulative distribution functionF{\displaystyle F} of a random variable. For example, imagine thatF{\displaystyle F} is the standardnormal distribution with mean zero andstandard 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}F1(u){\displaystyle F^{-1}(u)}
.50
.9751.95996
.9952.5758
.9999994.75342
1-2−528.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 thequantile function of the distribution — in other words, computing thecumulative distribution function (CDF) of the distribution (which maps a number in the domain to a probability between 0 and 1) and theninverting that function. This is the source of the term "inverse" or "inversion" in most of the names for this method. Note that for adiscrete 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 acontinuous distribution, however, we need to integrate theprobability density function (PDF) of the distribution, which is impossible to do analytically for most distributions (including thenormal 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 onrejection sampling.

For thenormal distribution, the lack of ananalytical expression for the corresponding quantile function means that other methods (e.g. theBox–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, theziggurat algorithm andrejection 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 packageR.[2]

Formal statement

[edit]

For anyrandom variableXR{\displaystyle X\in \mathbb {R} }, the random variableFX1(U){\displaystyle F_{X}^{-1}(U)} has the same distribution asX{\displaystyle X}, whereFX1{\displaystyle F_{X}^{-1}} is thegeneralized inverse of thecumulative distribution functionFX{\displaystyle F_{X}} ofX{\displaystyle X} andU{\displaystyle U} is uniform on[0,1]{\displaystyle [0,1]}.[3]

Forcontinuous random variables, theinverse probability integral transform is indeed the inverse of theprobability integral transform, which states that for acontinuous random variableX{\displaystyle X} withcumulative distribution functionFX{\displaystyle F_{X}}, the random variableU=FX(X){\displaystyle U=F_{X}(X)} isuniform on[0,1]{\displaystyle [0,1]}.

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

Intuition

[edit]

FromUUnif[0,1]{\displaystyle U\sim \mathrm {Unif} [0,1]}, we want to generateX{\displaystyle X} withCDFFX(x).{\displaystyle F_{X}(x).} We assumeFX(x){\displaystyle F_{X}(x)} to be a continuous, strictlyincreasing function, which provides good intuition.

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

FX(x)=Pr(Xx)=Pr(T(U)x)=Pr(UT1(x))=T1(x), for xR,{\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 thatPr(Uy)=y{\displaystyle \Pr(U\leq y)=y} whenU{\displaystyle U} is uniform on[0,1]{\displaystyle [0,1]}.

So we gotFX{\displaystyle F_{X}} to be the inverse function ofT{\displaystyle T}, or, equivalentlyT(u)=FX1(u),u[0,1].{\displaystyle T(u)=F_{X}^{-1}(u),u\in [0,1].}

Therefore, we can generateX{\displaystyle X} fromFX1(U).{\displaystyle F_{X}^{-1}(U).}

The method

[edit]
Schematic of the inverse transform sampling. The inverse function ofy=FX(x){\displaystyle y=F_{X}(x)} can be defined byFX1(y)=inf{x|FX(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 numberu{\displaystyle u} from the standard uniform distribution in the interval[0,1]{\displaystyle [0,1]}, i.e. fromUUnif[0,1].{\displaystyle U\sim \mathrm {Unif} [0,1].}
  2. Find thegeneralized inverse of the desired CDF, i.e.FX1(u){\displaystyle F_{X}^{-1}(u)}.
  3. ComputeX(u)=FX1(u){\displaystyle X'(u)=F_{X}^{-1}(u)}. The computed random variableX(U){\displaystyle X'(U)} has distributionFX{\displaystyle F_{X}} and thereby the same law asX{\displaystyle X}.

Expressed differently, given a cumulative distribution functionFX{\displaystyle F_{X}} and a uniform variableU[0,1]{\displaystyle U\in [0,1]}, the random variableX=FX1(U){\displaystyle X=F_{X}^{-1}(U)} has the distributionFX{\displaystyle F_{X}}.[3]

In the continuous case, a treatment of such inverse functions as objects satisfying differential equations can be given.[4] Some such differential equations admit explicitpower series solutions, despite their non-linearity.[5]

Examples

[edit]
F(x)=1exp(x){\displaystyle {\begin{aligned}F(x)=1-\exp(-{\sqrt {x}})\end{aligned}}}
In order to perform an inversion we want to solve forF(F1(u))=u{\displaystyle F(F^{-1}(u))=u}
F(F1(u))=u1exp(F1(u))=uF1(u)=(log(1u))2=(log(1u))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.
x=F1(y)=1λln(1y).{\displaystyle x=F^{-1}(y)=-{\frac {1}{\lambda }}\ln(1-y).}
It means that if we draw somey0{\displaystyle y_{0}}from aUUnif(0,1){\displaystyle U\sim \mathrm {Unif} (0,1)} and computex0=FX1(y0)=1λln(1y0),{\displaystyle x_{0}=F_{X}^{-1}(y_{0})=-{\frac {1}{\lambda }}\ln(1-y_{0}),} Thisx0{\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 isF(x)=1eλx{\displaystyle F(x)=1-e^{-\lambda \,x}}. Therefore,x=F1(y)=ln(1y)λ{\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=F1(y)=1λln(y).{\displaystyle x=F^{-1}(y)=-{\frac {1}{\lambda }}\ln(y).}

Proof of correctness

[edit]

LetF{\displaystyle F} be acumulative distribution function, and letF1{\displaystyle F^{-1}} be itsgeneralized inverse function (using theinfimum because CDFs are weakly monotonic andright-continuous):[6]

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

Claim: IfU{\displaystyle U} is auniform random variable on[0,1]{\displaystyle [0,1]} thenF1(U){\displaystyle F^{-1}(U)} hasF{\displaystyle F} as its CDF.

Proof:

Pr(F1(U)x)=Pr(UF(x))(F is right-continuous, so {u:F1(u)x}={u:uF(x)})=F(x)(because Pr(Uu)=u, when U is uniform on [0,1]){\displaystyle {\begin{aligned}&\Pr(F^{-1}(U)\leq x)\\&{}=\Pr(U\leq F(x))\quad &(F{\text{ is right-continuous, so }}\{u:F^{-1}(u)\leq x\}=\{u:u\leq F(x)\})\\&{}=F(x)\quad &({\text{because }}\Pr(U\leq u)=u,{\text{ when }}U{\text{ is uniform on }}[0,1])\\\end{aligned}}}

Truncated distribution

[edit]

Inverse transform sampling can be simply extended to cases oftruncated 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 numberu{\displaystyle u} uniformly distributed between 0 and 1, generateu{\displaystyle u} uniformly distributed betweenF(a){\displaystyle F(a)} andF(b){\displaystyle F(b)}, and then again takeF1(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 apolynomial 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]

Software implementations

[edit]

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.

See also

[edit]

References

[edit]
  1. ^Luc Devroye (1986).Non-Uniform Random Variate Generation(PDF). New York: Springer-Verlag. Archived fromthe original(PDF) on 2014-08-18. Retrieved2012-04-12.
  2. ^"R: Random Number Generation".
  3. ^abMcNeil, Alexander J.; Frey, Rüdiger; Embrechts, Paul (2005).Quantitative risk management. Princeton Series in Finance. Princeton University Press, Princeton, NJ. p. 186.ISBN 0-691-12255-5.
  4. ^Steinbrecher, György; Shaw, William T. (19 March 2008). "Quantile mechanics".European Journal of Applied Mathematics.19 (2):87–112.doi:10.1017/S0956792508007341.S2CID 6899308.
  5. ^Arridge, Simon; Maass, Peter; Öktem, Ozan; Schönlieb, Carola-Bibiane (2019)."Solving inverse problems using data-driven models".Acta Numerica.28:1–174.doi:10.1017/S0962492919000059.ISSN 0962-4929.S2CID 197480023.
  6. ^Luc Devroye (1986)."Section 2.2. Inversion by numerical solution ofF(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
  8. ^Derflinger, Gerhard; Hörmann, Wolfgang; Leydold, Josef (2010)."Random variate generation by numerical inversion when only the density is known"(PDF).ACM Transactions on Modeling and Computer Simulation.20 (4).doi:10.1145/945511.945517.
  9. ^"UNU.RAN - Universal Non-Uniform RANdom number generators".
  10. ^"Runuran: R Interface to the 'UNU.RAN' Random Variate Generators". 17 January 2023.
  11. ^"Random Number Generators (Scipy.stats.sampling) — SciPy v1.12.0 Manual".
  12. ^Baumgarten, Christoph; Patel, Tirth (2022). "Automatic random variate generation in Python".Proceedings of the 21st Python in Science Conference. pp. 46–51.doi:10.25080/majora-212e5952-007.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Inverse_transform_sampling&oldid=1307944637"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp