• No results found

Importance sampling

In document Practical photon mapping in hardware (Page 111-115)

5.6 Conclusions

6.1.1 Importance sampling

The goal of importance sampling is to choose the N samples such that it is more likely that a sample Xi will contribute significantly to ˆQ=FN. Importance sampling requires

prior knowledge. Suppose we were informed, somehow, thatg(x) in the range [0.5,1] will contribute more to the final result than [0,0.5] will. We would like to put more samples in that part of the domain. This prior knowledge is expressed in terms of a probability density function (p.d.f.) p(x). A potential p(x) for our example function is shown in Figure 6.3a. Making use of this knowledge to construct a new Monte Carlo estimator requires us to do two things. The first is to pick the set of samples, Xi, not uniformly

but according top(x). They should still be random, but no longer uniformly distributed. For the p(x) in Figure 6.3a we would expect many more sample locations above 0.5 than

0 0.25 0.5 0.75 1 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 (a)p(x) 0 0.25 0.5 0.75 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 (b)c(x) 0 0.25 0.5 0.75 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 (c)c−1(x)

Figure 6.3: Importance sampling chooses the samples Xi =c−1(ζi) where ζi is a uniform

random variable. For this example probability distribution functionp(x), only a quarter of the samples are expected to be below 0.5, as is reflected in the cumulative distribution function c(x). The construction of c−1(x) enables fast selection of samples according to

p(x).

below it.

Choosing a sample Xi according to p(x) is easy if p(x) is known. The first step is to

find the cumulative distribution function (c.d.f.), c(x), that corresponds to p(x). This is shown in Figure 6.3b. This function is then inverted to form c−1(x), Figure 6.3c. The idea is to sample c−1(x) with uniformly random numbersζi to find the samples Xi that

will be used. In our example, only one quarter of the random numbers are mapped to the range [0,0.5]. The other three quarters are instead mapped to the second half of the range of g(x). If ζi is a uniform random variable in [0,1], then let the set of samples

Xi = c−1(ζi). This changes the function presented to the Monte Carlo algorithm from

g(x) to g(c−1(x)).

Simply using the different samples will result in a biased answer unless the weights are also adjusted. By inspection of Figure 6.4a we see that R1

0 g(c

−1(x))dx = 3.625, a

significant error from the correct value of 2.75. By setting Wi = p(X1

i) we can correct

for this error. The more likely we were to choose a specific sample, the less we should take its result into account. On the other hand, a sample that was chosen despite a low probability but has a high value g(Xi) should count highly in the estimate.

0 0.25 0.5 0.75 1 0 1 2 3 4 5 6 7 8 9 10 (a)f(c−1(x)) 0 0.25 0.5 0.75 1 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 (b)p(x) 0 0.25 0.625 1 0 0.6667 2 5.3333 (c) f(cp(1x()x))

Figure 6.4: The sampling strategy described in this section generates samples according to p(x). Using these samples directly in the Monte Carlo estimator without adjusting the weights would however lead to a biased result. Setting Wi = p(1X

i is equivalent to

using blind Monte Carlo integration on the new function g(cp−1(x()x)).

blind Monte Carlo integration of the function g(cp−1(x()x)), as presented in Figure 6.4c. By inspection it can be verified that R01 g(cp−1(x()x))dx = 2.75 as expected. When this new function is sampled using 25 uniform random numbers we get the results shown in Fig- ure 6.5a. The estimated result is closer to the true value Q. Indeed, Figure 6.5b shows that importance sampling with the little information given to us in p(x) requires fewer than half the samples that blind Monte Carlo does for the same expected error.

The expected error of Monte Carlo integration using importance sampling can not be expressed without knowing the specific function and probability distribution function. However, the expected error is derived directly from the definitions:

O s Z g2(X) p2(x)p(x)dx−Θ 2 ! (6.4)

Intuitively we know that the more that p(x) resembles g(x) the lower the error will be. Indeed, inspection of Equation 6.4 shows that the error would be zero if and only if

p(x) = kg(x) for some constant k. In practice, even a rough correlations between p(x) and g(x) is good enough to provide a reduction in variance (Veach, 1997).

0 0.25 0.5 0.75 1 0 1 2 3 4 5 6 7 8 9 10 (a)FN = 2.32 0 5 10 15 20 25 30 35 40 45 50 0 0.5 1 1.5 2 2.5 3 Blind Importance Sampled

(b) Average Standard Deviation

Figure 6.5: Using importance sampling, the same number of samples will result in a smaller error from the true value. In Figure (a), 25 samples computed a estimate of 2.32, closer to 2.75 than the blind Monte Carlo estimator achieved with the same number of samples. Repeating the experiment from Figure 6.2, importance sampling is shown to be significantly better than blind Monte Carlo. Fewer than half the number of samples are required for equivalent results.

0 0.25 0.5 0.75 1 0 1 Q=2.75 8 10 (a)g(x) 0 0.25 0.625 1 0 2/3 2 Q=2.75 16/3 10 (b) g(cp(1x()x))

Figure 6.6: Importance sampling works because it attempts to integrate a function that is closer to being a constant. The average standard deviation of g(x) from 2.75 over the range [0,1] is 3.03, while it is merely 2.29 for g(cp−1(x()x)).

blind Monte Carlo works best when the integrand is as close to a constant function as is possible. One way to measure the uniformity of a function is to compute the average standard deviation to the average value throughout the domain. For our example the average value is Θ. The average standard deviation ofg(x) from 2.75 is 3.03, while that of the modified function g(cp−1(x()x)) is 2.29. The function as modified by importance sampling is therefore a more constant value, allowing the blind (standard) Monte Carlo method to perform better.

In document Practical photon mapping in hardware (Page 111-115)