# 7. Sampling and Observers¶

## 7.1. Observer Equation¶

The total intensity measured by an observing pixel is given be the integral of the incident emission over the collecting solid angle \(\Omega\) and surface area \(A\).

Here, \(L_{i}(p, \omega_i)\) is the incident emission at a given point \(p\) and incident angle \(\omega_i\) on the observing surface. \(\cos (\theta_i)\) is a geometry factor describing the increase in effective observing area as the incident rays become increasingly parallel to the surface.

## 7.2. Monte-Carlo Integration¶

The integral in the observer equation is exact but difficult to evaluate analytically for most physically relevant scenes. Monte-Carlo integration is a technique for approximating the value of an integral by simulating a random process with random numbers.

The simplest form of Monte-Carlo integration is the average value method, which starts by considering the integral

The average value of the function \(f(x)\) over the domain can be expressed in terms of the integral over the same domain.

Therefore, through manipulation we can express our integral in terms of the average of \(f(x)\). We can measure \(<f(x)>\) by sampling \(f(x)\) at \(N\) points \(x_1\), \(x_2\), ..., \(x_N\) chosen randomly between \(a\) and \(b\).

\(p(x_i) = 1/(a-b)\) is the uniform distribution we are sampling from. For a rectangular pixel in a camera the sampling distributions would be uniformly distributed 2D points in the square area \(A\) and 3D vectors in the hemisphere \(\Omega\).

In general, the standard error on the approximation scales as \(1/\sqrt{N}\) with \(N\) samples.

## 7.3. Importance Sampling¶

The average value formula works well for smoothly varying functions but becomes inefficient when the integral contains steep gradients or a divergence, for example, a bright point light source. The standard error on the integral estimator can become large in such circumstances.

We can get around these problems by drawing the sample points \(x_i\) from a non-uniform probability density function (i.e. higher density for regions with stronger emission). \(p(x_i)\) now becomes

where \(w(x)\) is the weight function and has been normalised so that its integral is 1. The estimator for the integral is now

This is the fundamental formula of importance sampling and a generalisation of the average value method (try \(w(x) = 1\)). It allows estimation of the integral \(I\) by performing a weighted sum, which can be weighted to have higher density in regions of interest. The price we pay is that the random samples are being drawn from a more complicated distribution.

Importance sampling exploits the fact that the Monte-Carlo estimator converges fastest when samples are taken from a distribution p(x) that is similar to the function f(x) in the integrand (i.e. concentrate the calculations where the integrand is high).