Content deleted Content added
m link to inverse function |
|||
(44 intermediate revisions by 22 users not shown) | |||
Line 1:
{{Short description|Basic method for pseudo-random number sampling}}
'''Inverse transform sampling''' (also known as '''inversion sampling''', the '''inverse probability integral transform''', the '''inverse transformation method''', or the '''[[Nikolai Smirnov (mathematician)|Smirnov]] transform'''
Inverse transformation sampling takes [[Continuous uniform distribution|uniform samples]] of a number <math>u</math> between 0 and 1, interpreted as a probability, and then returns the
{| class="wikitable floatright"
Line 16 ⟶ 17:
| .999999 || 4.75342
|-
| 1-2
|}
[[File:Inverse transform sampling.png|thumbnail|360px|right|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 [[inverse function|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 [[Closed-form expression|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:<ref>{{cite book |author=Luc Devroye |url=http://www.eirene.de/Devroye.pdf |title=Non-Uniform Random Variate Generation |publisher=Springer-Verlag |place=New York |year=1986 |access-date=2012-04-12 |archive-date=2014-08-18 |archive-url=https://web.archive.org/web/20140818200854/http://www.eirene.de/Devroye.pdf |url-status=dead }}</ref> 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 (programming language)|R]].<ref>{{Cite web|url=https://stat.ethz.ch/R-manual/R-devel/library/base/html/Random.html|title = R: Random Number Generation}}</ref>
==Formal statement==
For any [[random variable]] <math>X\in\mathbb R</math>, the random variable <math>F_X^{-1}(U)</math> has the same distribution as <math>X</math>, where <math>F_X^{-1}</math> is the [[Cumulative distribution function#Inverse_distribution_function_(quantile_function)|generalized inverse]] of the [[cumulative distribution function]] <math>F_X</math> of <math>X</math> and <math>U</math> is uniform on <math>[0,1]</math>.<ref name="mcneil2005">{{cite book | last1 = McNeil | first1 = Alexander J. | last2 = Frey | first2 = Rüdiger | last3 = Embrechts | first3 = Paul | title = Quantitative risk management | date=2005 | series=Princeton Series in Finance | publisher=Princeton University Press, Princeton, NJ | page=186 | isbn=0-691-12255-5}}</ref>
For [[Random_variable#Continuous_random_variable|continuous random variables]], the [[inverse probability]] integral transform is indeed the inverse of the [[probability integral transform]], which states that for a [[continuous random variable]] <math>X</math> with [[cumulative distribution function]] <math>F_X</math>, the random variable <math>U=F_X(X)</math> is [[uniform distribution (continuous)|uniform]] on <math>[0,1]</math>.
[[File:InverseFunc.png|thumb|Graph of the inversion technique from <math>x</math> to <math>F(x)</math>. On the bottom right we see the regular function and in the top left its inversion.]]▼
▲[[File:InverseFunc.png|thumb|360px|Graph of the inversion technique from <math>x</math> to <math>F(x)</math>. On the bottom right we see the regular function and in the top left its inversion.]]
== Intuition ==
From <math>U \sim \mathrm{Unif}[0,1]</math>, we want to generate <math>X</math> with [[Cumulative distribution function|CDF]] <math>F_X(x).</math> We assume <math>F_X(x)</math> to be a continuous, strictly [[Monotonic function|increasing function]], which provides good intuition.
We want to see if we can find some strictly monotone transformation <math>T:[0,1]\mapsto \mathbb{R}</math>, such that <math>T(U)\overset{d}{=}X</math>. We will have
Line 40 ⟶ 43:
<math>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},</math>
where the last step used that <math>\Pr(U \leq y) = y</math> when <math>U</math> is uniform on <math>
So we got <math>F_X</math> to be the inverse function of <math>T </math>, or, equivalently <math>T(u)=F_X^{-1}(u), u\in [0,1]. </math>
Line 47 ⟶ 50:
==The method==
[[File:Generalized inversion method.svg|thumb|
[[File:Inverse Transform Sampling Example.gif|thumb|360px|right|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:
Line 54 ⟶ 58:
The inverse transform sampling method works as follows:
#[[pseudorandom number generator|Generate a random number]] <math>u</math> from the standard uniform distribution in the interval <math>[0,1]</math>,
#Find the [[cumulative distribution function#Inverse_distribution_function_(quantile_function)|generalized inverse]] of the desired CDF,
# Compute <math>X'(u)=F_X^{-1}(u)</math>. The computed random variable <math>X'(U)</math> has distribution <math>F_X
Expressed differently, given a
== Examples ==
Line 90 ⟶ 94:
==Proof of correctness==
Let
:<math>F^{-1}(u) = \inf\;\{x \mid F(x)\geq u\} \qquad (0<u<1).</math>
''Claim:'' If
''Proof:''
Line 101 ⟶ 105:
\begin{align}
& \Pr(F^{-1}(U) \leq x) \\
& {} = \Pr(U \leq F(x)) \quad &(F\text{
& {} = F(x) \quad &(\text{because }\Pr(U \leq
\end{align}
</math>
Line 113 ⟶ 117:
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.<ref>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</ref>
== Software implementations ==
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 <ref>
{{cite journal | last1 = Derflinger | first1 = Gerhard | last2 = Hörmann | first2 = Wolfgang | last3 = Leydold | first3 = Josef | title = Random variate generation by numerical inversion when only the density is known | journal = ACM Transactions on Modeling and Computer Simulation | date = 2010 | volume = 20 | issue = 4 | doi = 10.1145/945511.945517| url = https://epub.wu.ac.at/664/1/document.pdf }}</ref> or the CDF.
* C library UNU.RAN <ref>{{cite web | url=https://statmath.wu.ac.at/unuran/index.html | title=UNU.RAN - Universal Non-Uniform RANdom number generators }}</ref>
* R library Runuran <ref>{{cite web | url=https://cran.r-project.org/package=Runuran | title=Runuran: R Interface to the 'UNU.RAN' Random Variate Generators | date=17 January 2023 }}</ref>
* Python subpackage sampling in [[SciPy|scipy.stats]]<ref>{{cite web | url=https://docs.scipy.org/doc/scipy/reference/stats.sampling.html | title=Random Number Generators (Scipy.stats.sampling) — SciPy v1.12.0 Manual }}</ref><ref>
{{cite book | last1 = Baumgarten | first1 = Christoph | last2 = Patel | first2 = Tirth | chapter = Automatic random variate generation in Python | title = Proceedings of the 21st Python in Science Conference | date = 2022 | pages = 46–51 | doi = 10.25080/majora-212e5952-007}}</ref>
== See also ==
Line 118 ⟶ 131:
* [[Copula (statistics)|Copula]], defined by means of probability integral transform.
* [[Quantile function]], for the explicit construction of inverse CDFs.
* [[Cumulative distribution function#
* [[Rejection sampling]] is another common technique to generate random variates that does not rely on inversion of the CDF.
==References==
|