## Further Reading

Rejection sampling was developed by von Neumann (1951) shortly after the Monte Carlo method was invented.

The alias method was introduced by Walker (1974,
1977). The algorithm that we have implemented to generate
alias tables in the `AliasTable` class is due to Vose
(1991). See Schwarz’s article (2011) for
extensive information about implementing alias tables and related
techniques.

A number of algorithms for reservoir sampling were described by Vitter
(1985), though he credits the basic algorithm we outlined
at the start of Section A.2 to Alan Waterman. The
weighted reservoir sampling algorithm in `pbrt`’s
`WeightedReservoirSampler` class is due to Chao (1982).

The square to disk mapping in Section A.5.1 was described by Shirley and Chiu (1997). The implementation here benefits by observations in Shirley’s 2011 blog by Dave Cline and the commenter “franz” that the logic could be simplified considerably from the original algorithm (Shirley 2011). Articles by Shirley and collaborators describe a number of useful recipes for warping uniform random numbers to useful distributions for rendering (Shirley 1992; Shirley et al. 2019).

The summed-area table data structure was introduced by Crow (1984). Its use for efficiently sampling arbitrary rectangluar regions of images was demonstrated by Bitterli et al. (2015).

A number of additional sampling techniques have been developed for tabularized multidimensional distributions. Steigleder and McCool (2003) linearized 2D and higher dimensional domains into 1D using a Hilbert curve and then sampled using 1D samples over the 1D domain, which still maintains desirable stratification properties of the sampling distribution thanks to the spatial coherence preserving properties of the Hilbert curve. McCool and Harwood (1997) as well as Clarberg et al. (2005) described an approach for sampling images based on quadtrees that repeatedly transforms uniform sample values until they match a target distribution.

Lawrence et al. (2005) described an adaptive representation for tabularized CDFs, where the CDF is approximated with a piecewise-linear function with fewer, irregularly spaced vertices than the given CDF. This approach can substantially reduce storage requirements and improve lookup efficiency, taking advantage of the fact that large ranges of the CDF may be efficiently approximated with a single linear function.

The time spent searching the CDF when sampling from a tabularized
distribution can be reduced with auxiliary data structures. Chen and Asau
(1974) suggested the *guide table method*, where an
additional array of offsets into the table gives a starting point for the
search. Cline et al. (2009) introduced this approach to
graphics and also presented a method based on approximating the inverse CDF
as a piecewise-linear function of , thus enabling constant-time
lookups at a cost of some accuracy.
Binder and Keller (2020) presented algorithms
for building and sampling from tabularized distributions that run
efficiently on GPUs.
Another innovative approach to sampling from such CDFs was described by
Morrical and Zellmann (2021), who showed how hardware
ray tracing capabilities could be used for this task.
Vitsas et al. (2021)
fit Gaussian mixture models to the sampling distribution of clear sky
environment maps and showed a significant reduction in memory use with a
sampling algorithm that does not require table search.

Arithmetic coding offers another interesting way to approach sampling from distributions (MacKay 2003, p. 118; Piponi 2012). If we have a discrete set of probabilities from which we would like to generate samples, one way to approach the problem is to encode the CDF as a binary tree where each node splits the interval at some point and where, given a random sample , we determine which sample value it corresponds to by traversing the tree until we reach the leaf node for its sample value. Ideally, we would like leaf nodes that represent higher probabilities to be higher up in the tree, so that it takes fewer traversal steps to find them (and thus those more frequently generated samples can be found more quickly). Looking at the problem from this perspective, it can be shown that the optimal structure of such a tree is given by Huffman coding, which is normally used for compression.

### References

- Binder, N., and A. Keller. 2020.
Massively parallel construction of radix tree forests for the efficient sampling of discrete or piecewise constant probability distributions.
*Monte Carlo and Quasi-Monte Carlo Methods (MCQMC 2018)*. arXiv: 1902.05942 [cs]. - Bitterli, B., J. Novák, and W. Jarosz. 2015.
Portal-masked environment map sampling.
*Computer Graphics Forum (Proceedings of the 2015 Eurographics Symposium on Rendering)**34*(4), 13–19. - Chao, M. T. 1982.
A general purpose unequal probability sampling plan.
*Biometrika**69*(3), 653–56. - Chen, H. C., and Y. Asau. 1974.
On generating random variates from an empirical distribution.
*AIIE Transactions**6*(2), 163–66. - Clarberg, P., W. Jarosz, T. Akenine-Möller, and H. W. Jensen. 2005.
Wavelet importance sampling: Efficiently evaluating products of complex
functions.
*ACM Transactions on Graphics (Proceedings of SIGGRAPH 2005)**24*(3), 1166–75. - Cline, D., A. Razdan, and P. Wonka. 2009.
A comparison of tabular PDF inversion methods.
*Computer Graphics Forum**28*(1), 154–60. - Crow, F. C. 1984.
Summed-area tables for texture mapping.
*Computer Graphics (Proceedings of SIGGRAPH ’84)**18*, 207–12. - Lawrence, J., S. Rusinkiewicz, and R. Ramamoorthi. 2005.
Adaptive numerical cumulative distribution functions for efficient
importance sampling.
*Rendering Techniques 2005: 16th Eurographics Workshop on Rendering*, 11–20. - MacKay, D. 2003.
*Information Theory, Inference, and Learning Algorithms*. Cambridge: Cambridge University Press. - McCool, M. D., and P. K. Harwood. 1997.
Probability trees.
*Proceedings of Graphics Interface ’97*, 37–46. - Morrical, N., and S. Zellmann. 2021.
Inverse transform sampling using ray tracing hardware.
In Marrs, A., P. Shirley, and I. Wald (eds.),
*Ray Tracing Gems II*, 625–41. Berkeley: Apress. - Piponi, D. 2012. Lossless decompression and the generation of random samples. http://blog.sigfpe.com/2012/01/lossless-decompression-and-generation.html.
- Schwarz, K. 2011. Darts, dice, and coins: Sampling from a discrete distribution. http://www.keithschwarz.com/darts-dice-coins/.
- Shirley, P. 1992.
Nonuniform random point sets via warping.
In D. Kirk (ed.),
*Graphics Gems III*, 80–83. San Diego: Academic Press. - Shirley, P. 2011. Improved code for concentric map. http://psgraphics.blogspot.com/2011/01/improved-code-for-concentric-map.html.
- Shirley, P., and K. Chiu. 1997.
A low distortion map between disk and square.
*Journal of Graphics Tools**2*(3), 45–52. - Shirley, P., S. Laine, D. Hart, M. Pharr, P. Clarberg, E. Haines, M. Raab, and D. Cline. 2019.
Sampling transformations zoo.
In E. Haines and T. Akenine-Möller (eds.),
*Ray Tracing Gems*, 223–46. Berkeley: Apress. - Steigleder, M., and M. McCool. 2003.
Generalized stratified sampling using the Hilbert curve.
*Journal of Graphics Tools**8*(3), 41–47. - Vitsas, N., K. Vardis, and G. Papaioannou. 2021.
Sampling clear sky models using truncated Gaussian mixtures.
*Proceedings of the Eurographics Symposium on Rendering*, 35–44. - Vitter, J. S. 1985.
Random sampling with a reservoir.
*ACM Transactions on Mathematical Software*,*11*(1), 37–57. - von Neumann, J. 1951.
Various techniques used in connection with random digits.
*Journal of Research of the National Bureau of Standards, Applied Mathematics Series**12*, 36–38. - Vose, M. D. 1991.
A linear algorithm for generating random numbers with a given distribution.
*IEEE Transactions on Software Engineering**17*(9), 972–75. - Walker, A. J. 1974.
New fast method for generating discrete random numbers with arbitrary
frequency distributions.
*Electronics Letters**10*(8): 127–28. - Walker, A. J. 1977.
An efficient method for generating discrete random variables with general distributions.
*ACM Transactions on Mathematical Software**3*(3), 253–56.