# Understanding Sobol sampling

This article describes the Sobol sampling method for non-sequential ray tracing. A comparison with random ray-generation is presented, and the benefits and limitations of each methods are discussed.

Authored By Mark Nicholson

Article Attachments

## Introduction

A source object generates rays with spatial and angular distribution. For example, a Source Point generates rays with the same starting coordinates, but with direction cosines chosen uniformly within a given solid angle. There are two methods of rays generation in OpticStudio, each sampling the source objects differently. Those methods are refered to as Random, and Sobol.

## Random and Sobol sampling schemes

The spatial and angular distribution of a source can be viewed as a probability density function of the ray starting position, and direction cosine. This function is usually sampled with a pseudorandom number generator, whose purpose is to create a series of numbers, uncorrelated with each other, that are used to generate the source rays.

Computer-based random-number generators are pseudorandom in that they are limited (ultimately by the number of bits of the operating system, but generally by algorithm assumptions) to have a period over which the random number sequence repeats, they are not "truly" random. In this article, I refer to Zemax' long-period random number generator as "truly" random to distinguish it from the Sobol algorithm.

Sobol sampling takes a different approach. Rather than generating random numbers, it generates a uniform distribution in probability space. It is a distribution which appears qualitatively random, but cleverly "fills in" previously unsampled regions of the probability function.

The zip file attached, which can be downloaded from the last page of this article, shows a simple optical system. Two rectangular sources illuminate a detector. These source objects are designed to produce a uniform, rectangular distribution of rays. The bottom one uses Zemax' random number generator, whilst the top one uses a Sobol sampling scheme. If we trace 10,000 rays per source, the difference between the sampling schemes is hardly visible: Tracing 100,000 rays shows the differences more clearly: The Sobol sampling scheme produces a more uniform, though still qualitatively random distribution than the random distribution, which shows a more "clumpy" distribution, i.e. with hot spots and darker regions. Zooming in on a region in the random-sampled source distribution shows: The red pixel above indicates where three rays landed in the same pixel, and there are also regions where no rays landed. Hence this region is noisier than the Sobol-illuminated region.

## Signal to Noise Ratio

Here is the result of tracing 1,000,000, 10,000,000, 100,000,000, and 1,000,000,000 rays per source: When there are few (10,000) and a great amount of rays (1 billion) the results of the random ray-trace and Sobol ray-trace are similar. Hence Sobol sampling is most useful in a "sweet-spot" region. The signal to noise ratio (SNR) of the random ray-trace is SQRT(N) where N is the average number of rays hitting a pixel. For the Sobol sampling scheme, the SNR goes linearly as N (see reference 1). This can be seen by taking a cross-section through the distribution with 1 billion rays per source: Note however that Sobol sampling is not a "magic bullet". In this case, we know that the source irradiance is intended to be uniform. Our prior knowledge of the intended distribution allows us to claim that Sobol sampling is "better" in this case. However, in any Monte-Carlo simulation, there is ultimately no more accurate method than making many samples with a truly random number generator. For this reason, OpticStudio allows you to select either a Sobol sampling scheme, or to use OpticStudio's long-period random number generator, in the source tab of the object properties: ## References

Press, Flannery, Teukolsky, and Vetterling, Numerical Recipes, Cambridge Press.

KA-01413