Rejection Sampling
   HOME

TheInfoList



OR:

In numerical analysis and
computational statistics Computational statistics, or statistical computing, is the bond between statistics and computer science. It means statistical methods that are enabled by using computational methods. It is the area of computational science (or scientific computi ...
, rejection sampling is a basic technique used to generate observations from a
distribution Distribution may refer to: Mathematics *Distribution (mathematics), generalized functions used to formulate solutions of partial differential equations * Probability distribution, the probability of a particular value or value range of a vari ...
. It is also commonly called the acceptance-rejection method or "accept-reject algorithm" and is a type of exact simulation method. The method works for any distribution in \mathbb^m with a
density Density (volumetric mass density or specific mass) is the substance's mass per unit of volume. The symbol most often used for density is ''ρ'' (the lower case Greek letter rho), although the Latin letter ''D'' can also be used. Mathematical ...
. Rejection sampling is based on the observation that to sample a
random variable A random variable (also called random quantity, aleatory variable, or stochastic variable) is a mathematical formalization of a quantity or object which depends on random events. It is a mapping or a function from possible outcomes (e.g., the po ...
in one dimension, one can perform a uniformly random sampling of the two-dimensional Cartesian graph, and keep the samples in the region under the graph of its density function. Note that this property can be extended to ''N''-dimension functions.


Description

To visualize the motivation behind rejection sampling, imagine graphing the density function of a random variable onto a large rectangular board and throwing darts at it. Assume that the darts are uniformly distributed around the board. Now remove all of the darts that are outside the area under the curve. The remaining darts will be distributed uniformly within the area under the curve, and the x-positions of these darts will be distributed according to the random variable's density. This is because there is the most room for the darts to land where the curve is highest and thus the probability density is greatest. The visualization as just described is equivalent to a particular form of rejection sampling where the "proposal distribution" is uniform (hence its graph is a rectangle). The general form of rejection sampling assumes that the board is not necessarily rectangular but is shaped according to the density of some proposal distribution that we know how to sample from (for example, using inversion sampling), and which is at least as high at every point as the distribution we want to sample from, so that the former completely encloses the latter. (Otherwise, there would be parts of the curved area we want to sample from that could never be reached.) Rejection sampling works as follows: #Sample a point on the x-axis from the proposal distribution. #Draw a vertical line at this x-position, up to the maximum y-value of the probability density function of the proposal distribution. #Sample uniformly along this line from 0 to the maximum of the probability density function. If the sampled value is greater than the value of the desired distribution at this vertical line, reject the x-value and return to step 1; else the x-value is a sample from the desired distribution. This algorithm can be used to sample from the area under any curve, regardless of whether the function integrates to 1. In fact, scaling a function by a constant has no effect on the sampled x-positions. Thus, the algorithm can be used to sample from a distribution whose
normalizing constant The concept of a normalizing constant arises in probability theory and a variety of other areas of mathematics. The normalizing constant is used to reduce any probability function to a probability density function with total probability of one. ...
is unknown, which is common in
computational statistics Computational statistics, or statistical computing, is the bond between statistics and computer science. It means statistical methods that are enabled by using computational methods. It is the area of computational science (or scientific computi ...
.


Theory

The rejection sampling method generates sampling values from a target distribution X with arbitrary
probability density function In probability theory, a probability density function (PDF), or density of a continuous random variable, is a function whose value at any given sample (or point) in the sample space (the set of possible values taken by the random variable) can ...
f(x) by using a proposal distribution Y with probability density g(x). The idea is that one can generate a sample value from X by instead sampling from Y and accepting the sample from Y with probability f(x)/(M g(x)), repeating the draws from Y until a value is accepted. M here is a constant, finite bound on the likelihood ratio f(x)/g(x), satisfying 1 < M < \infty over the support of X; in other words, M must satisfy f(x) \leq M g(x) for all values of x. Note that this requires that the support of Y must include the support of X—in other words, g(x) > 0 whenever f(x) > 0. The validation of this method is the envelope principle: when simulating the pair (x,v=u\cdot Mg(x)), one produces a uniform simulation over the subgraph of Mg(x). Accepting only pairs such that u then produces pairs (x,v) uniformly distributed over the subgraph of f(x) and thus, marginally, a simulation from f(x). This means that, with enough replicates, the algorithm generates a sample from the desired distribution f(x). There are a number of extensions to this algorithm, such as the
Metropolis algorithm A metropolis () is a large city or conurbation which is a significant economic, political, and cultural center for a country or region, and an important hub for regional or international connections, commerce, and communications. A big c ...
. This method relates to the general field of
Monte Carlo Monte Carlo (; ; french: Monte-Carlo , or colloquially ''Monte-Carl'' ; lij, Munte Carlu ; ) is officially an administrative area of the Principality of Monaco, specifically the ward of Monte Carlo/Spélugues, where the Monte Carlo Casino is ...
techniques, including
Markov chain Monte Carlo In statistics, Markov chain Monte Carlo (MCMC) methods comprise a class of algorithms for sampling from a probability distribution. By constructing a Markov chain that has the desired distribution as its equilibrium distribution, one can obtain ...
algorithms that also use a proxy distribution to achieve simulation from the target distribution f(x). It forms the basis for algorithms such as the
Metropolis algorithm A metropolis () is a large city or conurbation which is a significant economic, political, and cultural center for a country or region, and an important hub for regional or international connections, commerce, and communications. A big c ...
. The unconditional acceptance probability is the proportion of proposed samples which are accepted, which is \begin \mathbb\left(U\le\frac\right) &= \operatorname\mathbf_\\ pt&= E\left _Yright.html"_;"title="mathbf_.html"_;"title="operatorname[\mathbf_">_Yright">mathbf_.html"_;"title="operatorname[\mathbf_">_Yright&_(\text_)_\\ _Yright.html"_;"title="mathbf_.html"_;"title="operatorname[\mathbf_">_Yright">mathbf_.html"_;"title="operatorname[\mathbf_">_Yright&_(\text_)_\\[6pt">mathbf_">_Yright.html"_;"title="mathbf_.html"_;"title="operatorname[\mathbf_">_Yright">mathbf_.html"_;"title="operatorname[\mathbf_">_Yright&_(\text_)_\\[6pt &=_\operatorname\left[\mathbb\left(U\le_\frac_\biggr.html" ;"title="pt.html" ;"title="mathbf_">_Yright.html" ;"title="mathbf_.html" ;"title="operatorname[\mathbf_"> Yright">mathbf_.html" ;"title="operatorname[\mathbf_"> Yright& (\text ) \\[6pt">mathbf_">_Yright.html" ;"title="mathbf_.html" ;"title="operatorname[\mathbf_"> Yright">mathbf_.html" ;"title="operatorname[\mathbf_"> Yright& (\text ) \\[6pt &= \operatorname\left[\mathbb\left(U\le \frac \biggr"> Y\right) \right\ pt&= E\left[\frac\right] & (\text \Pr(U \leq u) = u, \text U \text (0,1)) \\[6pt] &=\int\limits_ \frac g(y) \, dy\\ pt&= \frac\int\limits_ f(y) \, dy \\ pt&= \frac & (\text Y \text X) \end where U\sim \mathrm(0,1), and the value of y each time is generated under the density function g(\cdot) of the proposal distribution Y. The number of samples required from Y to obtain an accepted value thus follows a
geometric distribution In probability theory and statistics, the geometric distribution is either one of two discrete probability distributions: * The probability distribution of the number ''X'' of Bernoulli trials needed to get one success, supported on the set \; * ...
with probability 1/M, which has mean M. Intuitively, M is the expected number of the iterations that are needed, as a measure of the computational complexity of the algorithm. Rewrite the above equation, M=\frac Note that 1 \le M<\infty, due to the above formula, where \mathbb\left(U\le\frac\right) is a probability which can only take values in the interval ,1/math>. When M is chosen closer to one, the unconditional acceptance probability is higher the less that ratio varies, since M is the upper bound for the likelihood ratio f(x)/g(x). In practice, a value of M closer to 1 is preferred as it implies fewer rejected samples, on average, and thus fewer iterations of the algorithm. In this sense, one prefers to have M as small as possible (while still satisfying f(x) \leq M g(x), which suggests that g(x) should generally resemble f(x) in some way. Note, however, that M cannot be equal to 1: such would imply that f(x)=g(x), i.e. that the target and proposal distributions are actually the same distribution. Rejection sampling is most often used in cases where the form of f(x) makes sampling difficult. A single iteration of the rejection algorithm requires sampling from the proposal distribution, drawing from a uniform distribution, and evaluating the f(x)/(M g(x)) expression. Rejection sampling is thus more efficient than some other method whenever M times the cost of these operations—which is the expected cost of obtaining a sample with rejection sampling—is lower than the cost of obtaining a sample using the other method.


Algorithm

The algorithm, which was used by
John von Neumann John von Neumann (; hu, Neumann János Lajos, ; December 28, 1903 – February 8, 1957) was a Hungarian-American mathematician, physicist, computer scientist, engineer and polymath. He was regarded as having perhaps the widest cove ...
and dates back to Buffon and his needle, obtains a sample from distribution X with density f using samples from distribution Y with density g as follows: * Obtain a sample y from distribution Y and a sample u from \mathrm(0,1) (the uniform distribution over the unit interval). * Check whether or not u. ** If this holds, accept y as a sample drawn from f; ** if not, reject the value of y and return to the sampling step. The algorithm will take an average of M iterations to obtain a sample.


Advantages over sampling using naive methods

Rejection sampling can be far more efficient compared with the naive methods in some situations. For example, given a problem as sampling X\sim F(\cdot) conditionally on X given the set A, i.e., X, X\in A, sometimes X can be easily simulated, using the naive methods (e.g. by
inverse transform sampling Inverse transform sampling (also known as inversion sampling, the inverse probability integral transform, the inverse transformation method, Smirnov transform, or the golden ruleAalto University, N. Hyvönen, Computational methods in inverse probl ...
): * Sample X\sim F(\cdot) independently, and leave those satisfying \ * Output: \ The problem is this sampling can be difficult and inefficient, if \mathbb(X\in A)\approx 0. The expected number of iterations would be \frac, which could be close to infinity. Moreover, even when you apply the Rejection sampling method, it is always hard to optimize the bound M for the likelihood ratio. More often than not, M is large and the rejection rate is high, the algorithm can be very inefficient. The
Natural Exponential Family In probability and statistics, a natural exponential family (NEF) is a class of probability distributions that is a special case of an exponential family (EF). Definition Univariate case The natural exponential families (NEF) are a subset of ...
(if it exists), also known as exponential tilting, provides a class of proposal distributions that can lower the computation complexity, the value of M and speed up the computations (see examples: working with Natural Exponential Families).


Examples: working with natural exponential families

Given a random variable X\sim F(\cdot), F(x)=\mathbb(X\le x) is the target distribution. Assume for the simplicity, the density function can be explicitly written as f(x). Choose the proposal as \begin F_\theta (x)&=\mathbb\left exp(\theta X-\psi (\theta))\mathbb(X\le x)\right\ &=\int^x_e^f(y)dy\\ g_\theta(x)&=F'_\theta(x)=e^f(x) \endwhere \psi(\theta) = \log\left(\mathbb\exp(\theta X)\right) and \Theta = \. Clearly, \_, is from a
natural exponential family In probability and statistics, a natural exponential family (NEF) is a class of probability distributions that is a special case of an exponential family (EF). Definition Univariate case The natural exponential families (NEF) are a subset of ...
. Moreover, the likelihood ratio is Z(x)=\frac=\frac=e^Note that \psi (\theta)<\infty implies that it is indeed a log moment-generation function, that is, \psi(\theta)=\log\mathbb, _=\log M_X(t), _. And it is easy to derive the log moment-generation function of the proposal and therefore the proposal's moments.\begin \psi_\theta(\eta)&=\log\left(\mathbb_\theta\exp(\eta X)\right)=\psi(\theta+\eta)-\psi(\theta)<\infty\\ \mathbb_\theta(X)&= \left.\frac\_\\ \mathrm_\theta(X)&= \left.\frac\_ \end As a simple example, suppose under F(\cdot), X \sim \mathrm(\mu, \sigma^2), with \psi(\theta)=\theta \mu+\frac. The goal is to sample X, X\in \left ,\infty\right/math>, b>\mu. The analysis goes as follows. * Choose the form of the proposal distribution F_\theta(\cdot), with log moment-generating function as \psi_\theta(\eta)=\psi (\theta+\eta)-\psi(\eta)=\eta(\mu+\theta\sigma^2)+\frac, which further implies it is a normal distribution \mathrm(\mu+\theta\sigma^2, \sigma^2). * Decide the well chosen \theta^* for the proposal distribution. In this setup, the intuitive way to choose \theta^* is to set \mathbb_(X)=\mu+\theta\sigma^2=b, that is \theta^*=\frac * Explicitly write out the target, the proposal and the likelihood ratio\begin f_(x)&=\frac\\ g_(x)&=f(x)\exp(\theta^* x-\psi(\theta^*))\\ Z(x)&=\frac=\frac \end * Derive the bound M for the likelihood ratio z(x), which is a decreasing function for x \in , \infty/math>, thereforeM=Z(b)=\frac = \frac = \frac * Rejection sampling criterion: for U\sim \mathrm(0,1), if U\le \frac=e^\mathbb(x\ge b)holds, accept the value of X; if not, continue sampling new X\sim_\mathrm(\mu+\theta^*\sigma^2,\sigma^2) and new U\sim \mathrm(0,1) until acceptance. For the above example, as the measurement of the efficiency, the expected number of the iterations the NEF-Based Rejection sampling method is of order b, that is M(b)=O(b), while under the naive method, the expected number of the iterations is \frac=O(b\cdot e^), which is far more inefficient. In general, exponential tilting, a parametric class of proposal distribution, solves the optimization problems conveniently, with its useful properties that directly characterize the distribution of the proposal. For this type of problem, to simulate X conditionally on X\in A, among the class of simple distributions, the trick is to use NEFs, which helps to gain some control over the complexity and considerably speed up the computation. Indeed, there are deep mathematical reasons for using NEFs.


Drawbacks

Rejection sampling can lead to a lot of unwanted samples being taken if the function being sampled is highly concentrated in a certain region, for example a function that has a spike at some location. For many distributions, this problem can be solved using an adaptive extension (see
adaptive rejection sampling In numerical analysis and computational statistics, rejection sampling is a basic technique used to generate observations from a distribution. It is also commonly called the acceptance-rejection method or "accept-reject algorithm" and is a type of ...
), or with an appropriate change of variables with the method of the
ratio of uniforms The ratio of uniforms is a method initially proposed by Kinderman and Monahan in 1977 for pseudo-random number sampling, that is, for drawing random samples from a statistical distribution. Like rejection sampling and inverse transform sampling, it ...
. In addition, as the dimensions of the problem get larger, the ratio of the embedded volume to the "corners" of the embedding volume tends towards zero, thus a lot of rejections can take place before a useful sample is generated, thus making the algorithm inefficient and impractical. See
curse of dimensionality The curse of dimensionality refers to various phenomena that arise when analyzing and organizing data in high-dimensional spaces that do not occur in low-dimensional settings such as the three-dimensional physical space of everyday experience. The ...
. In high dimensions, it is necessary to use a different approach, typically a Markov chain Monte Carlo method such as
Metropolis sampling A metropolis () is a large city or conurbation which is a significant economic, political, and cultural center for a country or region, and an important hub for regional or international connections, commerce, and communications. A big c ...
or
Gibbs sampling In statistics, Gibbs sampling or a Gibbs sampler is a Markov chain Monte Carlo (MCMC) algorithm for obtaining a sequence of observations which are approximated from a specified multivariate probability distribution, when direct sampling is dif ...
. (However, Gibbs sampling, which breaks down a multi-dimensional sampling problem into a series of low-dimensional samples, may use rejection sampling as one of its steps.)


Adaptive rejection sampling

For many distributions, finding a proposal distribution that includes the given distribution without a lot of wasted space is difficult. An extension of rejection sampling that can be used to overcome this difficulty and efficiently sample from a wide variety of distributions (provided that they have log-concave density functions, which is in fact the case for most of the common distributions—even those whose ''density'' functions are not concave themselves) is known as adaptive rejection sampling (ARS). There are three basic ideas to this technique as ultimately introduced by Gilks in 1992: # If it helps, define your envelope distribution in log space (e.g. log-probability or log-density) instead. That is, work with h\left(x\right) = \log g\left(x\right) instead of g\left(x\right) directly. #* Often, distributions that have algebraically messy density functions have reasonably simpler log density functions (i.e. when f\left( x \right) is messy, \log f\left(x\right) may be easier to work with or, at least, closer to piecewise linear). # Instead of a single uniform envelope density function, use a piecewise linear density function as your envelope instead. #* Each time you have to reject a sample, you can use the value of f \left(x \right) that you evaluated, to improve the piecewise approximation h \left(x \right) . This therefore reduces the chance that your next attempt will be rejected. Asymptotically, the probability of needing to reject your sample should converge to zero, and in practice, often very rapidly. #* As proposed, any time we choose a point that is rejected, we tighten the envelope with another line segment that is tangent to the curve at the point with the same x-coordinate as the chosen point. #* A piecewise linear model of the proposal log distribution results in a set of piecewise
exponential distribution In probability theory and statistics, the exponential distribution is the probability distribution of the time between events in a Poisson point process, i.e., a process in which events occur continuously and independently at a constant average ...
s (i.e. segments of one or more exponential distributions, attached end to end). Exponential distributions are well behaved and well understood. The logarithm of an exponential distribution is a straight line, and hence this method essentially involves enclosing the logarithm of the density in a series of line segments. This is the source of the log-concave restriction: if a distribution is log-concave, then its logarithm is concave (shaped like an upside-down U), meaning that a line segment tangent to the curve will always pass over the curve. #* If not working in log space, a piecewise linear density function can also be sampled via triangle distributions # We can take even further advantage of the (log) concavity requirement, to potentially avoid the cost of evaluating f \left( x \right) when your sample ''is'' accepted. #* Just like we can construct a piecewise linear upper bound (the "envelope" function) using the values of h \left(x \right) that we had to evaluate in the current chain of rejections, we can also construct a piecewise linear lower bound (the "squeezing" function) using these values as well. #* Before evaluating (the potentially expensive) f \left( x \right) to see if your sample will be accepted, we may ''already know'' if it will be accepted by comparing against the (ideally cheaper) g_l \left( x \right) (or h_l \left( x \right) in this case) squeezing function that have available. #* This squeezing step is optional, even when suggested by Gilks. At best it saves you from only one extra evaluation of your (messy and/or expensive) target density. However, presumably for particularly expensive density functions (and assuming the rapid convergence of the rejection rate toward zero) this can make a sizable difference in ultimate runtime. The method essentially involves successively determining an envelope of straight-line segments that approximates the logarithm better and better while still remaining above the curve, starting with a fixed number of segments (possibly just a single tangent line). Sampling from a truncated exponential random variable is straightforward. Just take the log of a uniform random variable (with appropriate interval and corresponding truncation). Unfortunately, ARS can only be applied from sampling from log-concave target densities. For this reason, several extensions of ARS have been proposed in literature for tackling non-log-concave target distributions. Furthermore, different combinations of ARS and the Metropolis-Hastings method have been designed in order to obtain a universal sampler that builds a self-tuning proposal densities (i.e., a proposal automatically constructed and adapted to the target). This class of methods are often called as Adaptive Rejection Metropolis Sampling (ARMS) algorithms. The resulting adaptive techniques can be always applied but the generated samples are correlated in this case (although the correlation vanishes quickly to zero as the number of iterations grows).


See also

*
Inverse transform sampling Inverse transform sampling (also known as inversion sampling, the inverse probability integral transform, the inverse transformation method, Smirnov transform, or the golden ruleAalto University, N. Hyvönen, Computational methods in inverse probl ...
*
Ratio of uniforms The ratio of uniforms is a method initially proposed by Kinderman and Monahan in 1977 for pseudo-random number sampling, that is, for drawing random samples from a statistical distribution. Like rejection sampling and inverse transform sampling, it ...
*
Pseudo-random number sampling Non-uniform random variate generation or pseudo-random number sampling is the numerical practice of generating pseudo-random numbers (PRN) that follow a given probability distribution. Methods are typically based on the availability of a unifo ...
*
Ziggurat algorithm The ziggurat algorithm is an algorithm for pseudo-random number sampling. Belonging to the class of rejection sampling algorithms, it relies on an underlying source of uniformly-distributed random numbers, typically from a pseudo-random number gen ...


References


Further reading

*{{cite book , last=Robert , first=C. P. , last2=Casella , first2=G. , title=Monte Carlo Statistical Methods , edition=Second , location=New York , publisher=Springer-Verlag , year=2004 Monte Carlo methods Non-uniform random numbers