A.3 The Rejection Method

Many functions cannot be integrated in order to normalize them to find their PDFs. Even given a PDF, it is often not possible to invert the associated CDF to generate samples using the inversion method. In such cases, the rejection method can be useful: it is a technique for generating samples according to a function’s distribution without needing to do either of these steps. Assume that we want to draw samples from some function ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” where we have some PDF ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” that satisfies ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” for a constant ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” , and suppose that we do know how to sample from  ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” . The rejection method is then:

ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

This procedure repeatedly chooses a pair of random variables ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” . If the point ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” lies under ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” , then the sample ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” is accepted. Otherwise, it is rejected and a new sample pair is chosen. This idea is illustrated in Figure A.2; it works in any number of dimensions. It should be evident that the efficiency of this scheme depends on how tightly ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” bounds ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” .

Figure A.2: Rejection sampling generates samples according to the distribution of a function ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” even if ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ’s PDF is unknown or its CDF cannot be inverted. If some distribution ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” and a scalar constant ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” are known such that ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” , then samples can be drawn from ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” and randomly accepted in a way that causes the accepted samples to be from ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ’s distribution. The closer the fit of ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” to ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” , the more efficient this process is.

For example, suppose we want to select a uniformly distributed point inside a unit disk. Using the rejection method, we simply select a random ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” position inside the circumscribed square and return it if it falls inside the disk. This process is shown in Figure A.3.

Figure A.3: Rejection Sampling a Disk. One approach to finding uniform points in the unit disk is to sample uniform random points in the unit square and reject all that lie outside the disk (red points). The remaining points will be uniformly distributed within the disk.

The function RejectionSampleDisk() implements this algorithm. A similar approach will work to generate uniformly distributed samples on the inside of any complex shape as long as it has an inside–outside test.

<<Sampling Function Definitions>>+= 
Point2f RejectionSampleDisk(RNG &rng) { Point2f p; do { p.x = 1 - 2 * rng.Uniform<Float>(); p.y = 1 - 2 * rng.Uniform<Float>(); } while (Sqr(p.x) + Sqr(p.y) > 1); return p; }

In general, the efficiency of rejection sampling depends on the percentage of samples that are expected to be rejected. For RejectionSampleDisk(), this is easy to compute. It is the area of the disk divided by the area of the square: ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” . If the method is applied to generate samples in hyperspheres in the general ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” -dimensional case, however, the volume of an ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” -dimensional hypersphere goes to 0 as ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” increases, and this approach becomes increasingly inefficient.

Rejection sampling is not used in any of the Monte Carlo algorithms currently implemented in pbrt. We will normally prefer to find distributions that are similar to the function that can be sampled directly, so that well-distributed sample points in ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: ed/Sampling Algorithms/The Rejection Method.html - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” can be mapped to sample points that are in turn well distributed. Nevertheless, rejection sampling is an important technique to be aware of, particularly when debugging Monte Carlo implementations. For example, if one suspects the presence of a bug in code that draws samples from some distribution using the inversion method, then one can replace it with a straightforward implementation based on the rejection method and see if the Monte Carlo estimator converges to the same value. Of course, it is necessary to take many samples in situations like these, so that variance in the estimates does not mask errors.