An overview of importance sampling techniques

1. Numerical integration in 1D

Problem: compute

\[\displaystyle I=\int_a^b f(x)\,\mathrm{d}x\]

Solutions:

Rectangle (midpoint), trapezoidal and Simpson's rules with three subintervals on a concave function
Rectangle (midpoint), trapezoidal and Simpson's rules with three subintervals: piecewise constant, linear and quadratic interpolation of the function. Areas 6.3059, 5.9302 and 6.1806 for an exact value of 6.1800.

Example 1.1: integrate the square function with the rectangle rule

\[\displaystyle I=\int_0^2 x^2\,\mathrm{d}x = \frac{8}{3}\]
Left, midpoint and right rectangle sums of x squared on [0, 2] with 8 rectangles
Left end point (inf), midpoint and right end point (sup) rectangle sums with 8 rectangles.

Rectangle quadrature of \(f\) on \([a,b]\) with \(n\) subdivisions, using their left end points, midpoints and right end points (for an increasing function such as \(x^2\), the left and right sums are lower and upper bounds):

def rectangle_rule(f, a, b, n):
    size = (b - a) / n
    area_inf, area_mid, area_sup = 0, 0, 0
    for i in range(n):
        area_inf = area_inf + size * f(a + i * size)
        area_mid = area_mid + size * f(a + (i + 0.5) * size)
        area_sup = area_sup + size * f(a + (i + 1) * size)
    return area_inf, area_mid, area_sup

area_inf, area_mid, area_sup = rectangle_rule(lambda x: x * x, 0, 2, 8)
trapezoid = (area_inf + area_sup) / 2                # 2.6875
simpson = (area_inf + 4 * area_mid + area_sup) / 6   # 2.666... = 8/3

With \(h = \frac{b-a}{n}\), the left sum \(I_{\inf}\) and the right sum \(I_{\sup}\) (area_inf and area_sup) are:

\[\displaystyle I_{\inf} = h\sum_{i=0}^{n-1} f(a + i\,h), \qquad I_{\sup} = h\sum_{i=1}^{n} f(a + i\,h)\]

The integral can be approximated either by the midpoint sum (area_mid):

\[\displaystyle \hat I_{\text{mid}} = \frac{b-a}{n}\sum_{i=0}^{n-1} f\!\left(a + \left(i+\tfrac12\right)\frac{b-a}{n}\right)\]

or by the mean of the two bounds, i.e. the trapezoidal rule:

\[\displaystyle \hat I = \frac{I_{\inf} + I_{\sup}}{2}\]

For \(x^2\) on \([0, 2]\) with \(n = 8\): \(\hat I_{\text{mid}} = 2.65625\) and \(\hat I = 2.6875\), against \(8/3 \approx 2.66667\). The errors, \(-1/96\) and \(+1/48\), have opposite signs and the midpoint one is half the trapezoidal one, as predicted for smooth functions (exactly here, since \(f''\) is constant).

Can we obtain a better estimate? Yes. For a smooth \(f\), the trapezoidal error is about \(+\frac{(b-a)\,h^2}{12}f''\) and the midpoint error about \(-\frac{(b-a)\,h^2}{24}f''\). Weighting the midpoint twice cancels the \(h^2\) term:

\[\displaystyle \hat I_S = \frac{2\,\hat I_{\text{mid}} + \frac{I_{\inf}+I_{\sup}}{2}}{3} = \frac{I_{\inf} + 4\,\hat I_{\text{mid}} + I_{\sup}}{6}\]

This is the composite Simpson rule (each subinterval split at its midpoint), with an error in \(O(h^4)\), exact for polynomials up to degree 3. For \(x^2\) it gives exactly \(\frac{2.1875 + 4 \times 2.65625 + 3.1875}{6} = \frac{16}{6} = \frac{8}{3}\).

estimate (\(n = 8\)) value error
left sum \(I_{\inf}\) 2.1875 −0.479167
right sum \(I_{\sup}\) 3.1875 +0.520833
trapezoid \((I_{\inf}+I_{\sup})/2\) 2.6875 +0.020833
midpoint \(\hat I_{\text{mid}}\) 2.65625 −0.010417
Simpson \(\hat I_S\) 2.666667 0

Repeating this cancellation between estimates with \(n\) and \(2n\) subdivisions is Richardson extrapolation, which leads to the Romberg integration listed above.

2. Multidimensional integrals & Monte Carlo

Problem:

Solution:

Downsides:

Your mission, should you choose to accept it: reduce the variance of the estimator at any cost.

Example 2.1: integrate the square function with Monte Carlo

\[\displaystyle I=\int_0^2 x^2\,\mathrm{d}x\]
Monte Carlo estimate of the integral of x squared with uniform samples
Running Monte Carlo estimate with uniform samples: 2.6783 after 2000 samples (exact value 8/3 ≈ 2.66667).

3. Rejection sampling

Problem:

Solution:

(the generic version replaces \(\frac{g(x)}{c \cdot f(x)}\) by \(h(x)\) with values in \([0,1]\))

Pros: sample arbitrary distributions from uniform samples.

Cons: can be very inefficient if rejection is more frequent than acceptance.

Example 3.1: Estimate Pi with Monte Carlo and rejection sampling

200 uniform random points, green inside the disk and red outside, and the running estimate of π: four times the fraction of points inside. After an eduscol activity.

4. Stratified sampling

Problem:

Solution:

Downside:

Uniform random samples versus stratified samples
100 independent random samples (left) leave voids and clusters (largest empty disc, densest small disc); stratified sampling (right) draws one random sample per cell of a 10 × 10 grid.

Example 4.1: Estimate Pi with Monte Carlo, rejection sampling and stratified samples

A 14 × 14 grid with one random point per cell, the cells visited in random order: every partial estimate is unbiased, and the error drops to that of full stratification once the whole grid is covered.

5. Quasi Monte Carlo

Problem:

Solution:

Comparison of low discrepancy sequences (see Martin Roberts’ blog [Roberts:2018] for an animated comparison):

256 random points compared with the Halton, Sobol and R2 sequences

Comparison of optimized point sets and production samplers, generated with UTK [UTK] and OpenQMC [OpenQMC], and with a simplified implementation of SOT [Paulin:2020]:

256 points from random sampling, dart throwing, sliced optimal transport, LDBN, PMJ02 and Owen-scrambled Sobol'
256 points each. Dart throwing and SOT spread the points evenly (blue noise); LDBN adds a low discrepancy; PMJ02 [Christensen:2018] and Owen-scrambled Sobol', the samplers of production renderers, have a very low discrepancy but a less even spacing.

Downside:

Example 5.1: Estimate Pi with Monte Carlo, rejection sampling and LDS samples

200 points of the R2 sequence, with a random offset (Cranley–Patterson rotation): the estimate settles much faster than with random points.

6. Importance sampling (IS)

Problem:

Solution:

Downside:

Uniform, perfect and bad importance sampling of a Gaussian
Three sampling densities for a Gaussian integrand (rescaled for display): uniform, proportional to the integrand, and centered on the wrong place.

Example 6.1: integration of a Gaussian, uniform vs importance sampling

\[\displaystyle I=\int_{-10}^{10} 5\,e^{-x^2/2}\,\mathrm{d}x \approx 12.5331\]

with a uniform density on \([-10, 10]\), the perfect density \(\mathcal{N}(0,1)\) and a bad density \(\mathcal{N}(-4,1)\).

Estimate, variance and error of uniform and importance sampling of a Gaussian
Perfect importance sampling is exact from the first sample (zero variance). The bad density is unbiased but has a huge variance: after 2000 samples the estimate is still far below the answer (5.15), jumping each time a rare sample lands under the peak.

7. Multiple importance sampling (MIS)

Problem:

Solution:

Downside:

Example 7.1: integration in 1D

1D integration with three strategies and MIS
2000 samples per strategy, exact value 8.0501. Each Gaussian alone covers only one of the two lobes (estimates 3.46 and 3.58: unbiased, but far from converged), the uniform strategy alone is noisy (variance 58.4), and MIS combines them into a much better estimate (8.064, variance 3.34).

Example 7.2: Direct illumination sampling with Veach MIS

The scene of Veach and Guibas [Veach:1995], with the layout of Bitterli’s version [Bitterli:2016]: four glossy plates, from smooth (back) to rough (front), each tilted to reflect the lights towards the camera, lit by four spherical lights of equal power and increasing size. Four samples per pixel, each with two BSDF samples, two light samples, or one of each for MIS (balance heuristic):

Veach's scene rendered with BSDF sampling, light sampling, MIS and a reference
BSDF sampling is clean on the smooth plates, but the small lights on the rough plates turn into fireflies. Light sampling is the opposite: on the smooth plates a direction towards a large light rarely falls in the narrow reflection lobe. MIS keeps the best of both on every plate. Under each image, the relative MSE over all the plates, highlights included: MIS divides that of BSDF sampling by 2.5 and that of light sampling by 6.

8. Weighted importance sampling (WIS - SNIS)

Problem:

Solution:

“If we really accepted the idea that a sample from one distribution is a sample from any distribution (if appropriately weighted) then we should not be surprised at the next two results stated below.” - Trotter and Tukey [Trotter:1956]

Downside:

Example 8.1: integration with WIS

\[\displaystyle I=\int_1^{10} e^{-(x-1)/2}\,\mathrm{d}x \approx 1.9778\]

with uniform samples \(q\) on \([1, 10]\), reweighted towards a truncated exponential \(p(x) \propto e^{-0.7\,(x-1)}\), or towards the perfect target \(p = f/I\) (a toy: it requires knowing \(I\)).

Uniform Monte Carlo versus weighted importance sampling
With the perfect target, WIS is exact for every sample count. With the approximate target, its RMSE after 2000 samples is three times lower than uniform Monte Carlo (0.0164 versus 0.0493); with one or two samples it is slightly worse.

9. Resampled importance sampling (RIS)

Problem:

Solution:

Downside:

Example 9.1: Density of RIS samples in 1D

Exact density of RIS samples for increasing numbers of uniform candidates \(M\) on \([-4, 4]\) and a normal target density:

Exact densities of RIS samples for several numbers of candidates

The density of the selected sample can still be written with 1D integrals. With weights \(w = p/q\) (\(p\) possibly unnormalized, as above), candidate \(j\) lands at \(y\) with density \(q(y)\) and is then selected with probability \(w(y) / (w(y) + S)\), where \(S\) is the sum of the \(M - 1\) other weights. Summing over the candidates and writing \(\frac{1}{z} = \int_0^\infty e^{-tz}\,\mathrm{d}t\), the independence of the candidates turns the expectation into a power:

\[\displaystyle p_Y(y) = M\,p(y)\,\mathbb{E}\left[\frac{1}{w(y) + S}\right] = M\,p(y) \int_0^\infty e^{-t\,w(y)}\,\varphi(t)^{M-1}\,\mathrm{d}t, \qquad \varphi(t) = \mathbb{E}_q\left[e^{-t\,w(X)}\right]\]

\(\varphi\) is the Laplace transform of the weights, a single integral over \(x\). For \(M = 1\) the density is \(q\), and it tends to \(p / \int p\) as \(M\) grows, since \(S / (M - 1)\) tends to \(\int p\).

Example 9.2: direct illumination sampling with RIS

A diffuse floor and a white sphere lit by a rectangular light with a textured emission: a grid of bright spots of random colors on a uniform white base of lower power. One shadow ray per sample, 4 samples per pixel. RIS takes \(M = 16\) uniform candidates on the light and selects one with a reservoir (section 10), for two targets: the geometric term \(\hat{p} = G = \frac{\cos\theta\,\cos\theta'}{d^2}\) alone, or the emission times the geometric term \(\hat{p} = L_e\,G\), the unoccluded contribution up to the constant diffuse BRDF:

Textured light rendered with uniform area sampling, RIS with the geometric term, RIS with the emission times the geometric term, and a reference
Most of the emitted power comes from the spots, a small part of the light. Uniform samples mostly land on the white base, and the rare hits on the spots make the noise. Resampling on G alone barely helps, since the geometric term varies little across the light. With the emission in the target, the shadow rays go to the spots and the error drops by an order of magnitude. Each candidate only costs a texture lookup and a geometric term, cheap compared to the shadow ray in a real scene. The visibility is left out of the target, so the shadows remain noisy, which is what ReSTIR's reuse addresses (section 12).

10. Weighted reservoir sampling (WRS)

Problem:

Solution:

Downside:

Example 10.1: Density of WRS samples (same as RIS)

Same experiment as example 9.1, with the candidates streamed through a reservoir instead of resampled from a stored CDF. The WRS histograms follow the exact RIS density of example 9.1: the reservoir selects with exactly the same distribution.

Histograms of WRS samples against the exact RIS density for several numbers of candidates

11. Stratified resampling (bidirectional CDF sampling)

Problem:

Solution:

// Index selected by inverse CDF sampling with u in [0, 1), in a single pass over the weights from
// both ends, without storing the CDF (Ciklabakkal et al. 2022, Algorithm 1).
int bidirectionalCDF(const float* w, int M, float u)
{
    int front = 0, back = M - 1;
    float wf = w[front], wb = w[back];
    while (front < back)
    {
        if (wf <= u * (wf + wb)) wf += w[++front];
        else                     wb += w[--back];
    }
    return front;
}

Downside:

Example 11.1: Stratified resampling in 1D

Same setup as example 9.1, uniform candidates on \([-4, 4]\) and a normal target, to estimate the integral of \(f(x) = p(x)\,(1 + \frac{1}{2}\cos 3x)\) with \(N\) samples, each selected from its own subset of 8 candidates:

Resampled samples and RMSE of independent and stratified resampling with bidirectional CDF sampling

12. Spatiotemporal reservoir resampling (ReSTIR)

Problem:

Solution:

A reservoir summarizes all the candidates it has seen, so merging reservoirs costs a few evaluations of the target, whatever their number of candidates. ReSTIR [Bitterli:2020] uses this to reuse the candidates of neighboring pixels (spatial reuse) and of the previous frame (temporal reuse), examples 12.2 to 12.4.

Pros:

Downside:

12.1 The ReSTIR family

ReSTIR has been extended to most of light transport. A few landmarks, by topic:

Example 12.2: Direct illumination with spatial reuse

Each pixel first runs RIS on its own candidates and keeps its reservoir: the selected sample \(y\), its contribution weight \(W\) and its candidate count \(M\). Then each pixel resamples its own reservoir and those of a few neighbors, as if their samples were candidates of its own, with its own target \(\hat{p}\). Merging a reservoir costs target evaluations, not shadow rays, so after a pass each pixel has effectively seen the candidates of its neighbors. The neighbors’ samples come from a different distribution, and the resampling MIS weights \(m_i(y) = M_i\,\hat{p}_i(y) \big/ \sum_j M_j\,\hat{p}_j(y)\) of GRIS [Lin:2022] keep the result unbiased.

Same scene as example 9.2, with one sample per pixel: RIS with the target \(L_e\,G\) and \(M = 16\), followed by one or two passes of spatial reuse with 5 neighbors in a radius of 30 pixels:

Textured light with RIS, then one and two spatial reuse passes, and a reference
One sample, and one shadow ray, per pixel in every image. Each reuse pass lets a pixel pick among the samples of its neighbors, which halves the error with the first pass at the cost of a few target evaluations. The gain then saturates, since the neighbors share the same noise and their visibility differs from the pixel's own. This is only the spatial part of ReSTIR: in real time, the reservoirs of the previous frame are reused as well (temporal reuse), which accumulates candidates over time.

Example 12.3: Candidate strategies and resampling MIS weights

The same scene, still one sample and one shadow ray per pixel, with two strategies for the initial candidates: 16 points sampled uniformly on the light, or 8 light points and 8 cosine-weighted BSDF directions that hit the light, combined with the balance heuristic in the resampling weights (\(w = \hat{p} / (M_L\,q_L + M_B\,q_B)\), the per-candidate form of section 13.6). These reservoirs are then reused once, with 5 neighbors, and three kinds of resampling MIS weights for the \(k + 1 = 6\) reservoirs: constant weights \(m_i = M_i / \sum_j M_j\), the generalized balance heuristic \(m_i(y) = M_i\,\hat{p}_i(y) / \sum_j M_j\,\hat{p}_j(y)\), or pairwise MIS [Bitterli:2022], as generalized in GRIS [Lin:2022], which only balances each neighbor against the pixel itself:

RIS with light or light and BSDF candidates, and spatial reuse with constant, balance heuristic and pairwise MIS weights
Relative MSE of single images at one sample per pixel, and bias of their mean. On a diffuse surface the BSDF candidates are a poorer match than the light candidates for this target, so mixing them increases the error; the strategy matters for glossy surfaces. Constant weights are cheap, and even slightly less noisy here, but biased (−3%) wherever a neighbor's target vanishes and the pixel's does not, as across the horizon of the sphere. The balance heuristic is unbiased but evaluates the 6 targets at each of the 6 samples; pairwise MIS gets the same error with 2 evaluations per neighbor, O(k) instead of O(k²).

Example 12.4: Temporal reuse, visibility reuse and PDF similarity

Real-time ReSTIR runs over frames: here the scene is static and each pixel resamples, every frame, its initial RIS reservoir, its reservoir of the previous frame (temporal reuse, with a history capped at \(20\,M\)) and the reservoir of one neighbor that passes a normal and depth test (spatial reuse). Images are taken after 16 frames, and three improvements are added in turn:

RIS, temporal ReSTIR, and ReSTIR with visibility reuse, averaged visibility and PDF similarity rejection
Relative MSE of single frames on the lit surfaces, and in the shadow and penumbra of the sphere with the bias of their mean. Temporal and spatial reuse divide the error of RIS by about 3, but the shadows stay noisy: one shadow ray per pixel cannot resolve a penumbra. Visibility reuse divides the shadow error by 2.7, with a darkening bias of about −18%; averaging the reused visibilities removes another third of the noise; and rejecting dissimilar neighbors keeps samples from crossing the shadow edges, which almost removes the bias while keeping the low noise. The temporal accumulation shows as blotches rather than fine noise, the correlation of section 12.

13. Multiple weighted importance sampling (MWIS)

Problem:

Solution:

13.1 Setup and weights

The MWIS weight of strategy \(i\) is the product of an MIS weight (here the balance heuristic of section 7, the \(q_i\) playing the \(p_i\)) and the WIS weight of section 8:

\[\displaystyle \begin{aligned} w_{i,\text{mis}}(x) &= \frac{c_i\,q_i(x)}{\sum_{j=1}^{k} c_j\,q_j(x)}, \qquad w_{i,\text{wis}}(x) = \frac{p(x)}{q_i(x)}, \\ w_{i,\text{mwis}}(x) &= w_{i,\text{mis}}(x)\,w_{i,\text{wis}}(x) = \frac{c_i\,p(x)}{\bar{q}(x)} \end{aligned}\]

These weights are valid because their \(q_i\)-weighted sum rebuilds the target, the MIS weights summing to one (any MIS heuristic with \(\sum_i w_{i,\text{mis}} = 1\) works):

\[\displaystyle \begin{aligned} &\sum_{i=1}^k q_i(x)\,w_{i,\text{mwis}}(x) = p(x)\sum_{i=1}^k w_{i,\text{mis}}(x) = p(x), \\ &\text{so} \quad \sum_{i=1}^k \mathbb{E}_{q_i}\left[w_{i,\text{mwis}}(X)\,g(X)\right] = \int_\Omega g\,p\,\mathrm{d}\mu \quad \text{for any function } g \end{aligned}\]

Unlike MIS weights, MWIS weights do not sum to one, \(\sum_{i} w_{i,\text{mwis}}(x) = p(x) / \bar{q}(x) \neq 1\), and need not: only the \(q_i\)-weighted sum above matters, and self normalization makes the estimator insensitive to a global constant factor on the weights.

13.2 The MWIS identity

The MIS weights split the target between the strategies: strategy \(i\) receives the share \(w_{i,\text{mis}}\,p\), of mass \(W_i\), on which \(f/p\) has the weighted mean \(I_i\):

\[\displaystyle \begin{aligned} W_i &= \int_\Omega w_{i,\text{mis}}\,p\,\mathrm{d}\mu = \mathbb{E}_{q_i}\left[w_{i,\text{mwis}}(X)\right], \\ I_i &= \frac{\int_\Omega w_{i,\text{mis}}\,f\,\mathrm{d}\mu}{\int_\Omega w_{i,\text{mis}}\,p\,\mathrm{d}\mu} = \frac{\mathbb{E}_{q_i}\left[w_{i,\text{mwis}}(X)\frac{f(X)}{p(X)}\right]}{\mathbb{E}_{q_i}\left[w_{i,\text{mwis}}(X)\right]} \end{aligned}\]

The masses sum to one, \(\sum_i W_i = \int_\Omega p\,\mathrm{d}\mu = 1\), and \(I_i\) is the WIS integral of strategy \(i\), not an estimate of \(I\). Recombining the strategies by mass gives back the integral, since \(\sum_i W_i I_i = \sum_i \int_\Omega w_{i,\text{mis}}\,f\,\mathrm{d}\mu = I\):

\[\displaystyle \begin{aligned} I = \sum_{i=1}^k I_i\,W_i &= \sum_{i=1}^k \frac{\mathbb{E}_{q_i} \left[w_{i, \text{mwis}}(X)\frac{f(X)}{p(X)}\right]}{\mathbb{E}_{q_i}\left[w_{i, \text{mwis}}(X)\right]} \cdot \frac{\mathbb{E}_{q_i} \left[w_{i, \text{mwis}}(X)\right]}{\sum_{j=1}^k \mathbb{E}_{q_j}\left[w_{j,\text{mwis}}(X)\right]} \\ &= \frac{\sum_{i=1}^k\mathbb{E}_{q_i} \left[w_{i, \text{mwis}}(X)\frac{f(X)}{p(X)}\right]}{\sum_{j=1}^k\mathbb{E}_{q_j}\left[w_{j,\text{mwis}}(X)\right]} \end{aligned}\]

The identity is exact (the denominator equals one), written as a ratio to be estimated as one.

13.3 The MWIS estimator

Estimating each expectation with its strategy’s samples gives the ratio estimator:

\[\displaystyle \tilde{I}_{\text{mwis}} = \frac{\sum_{i=1}^k \frac{1}{n_i}\sum_{s=1}^{n_i} w_{i,\text{mwis}}(X_{i,s})\,\frac{f(X_{i,s})}{p(X_{i,s})}}{\sum_{i=1}^k \frac{1}{n_i}\sum_{s=1}^{n_i} w_{i,\text{mwis}}(X_{i,s})}\]

With the balance heuristic, \(\frac{1}{n_i}\,w_{i,\text{mwis}}(x) = \frac{p(x)}{N\,\bar{q}(x)}\) is the same for every strategy, and the estimator reduces to a weighted mean of the values \(f/p\) over all samples:

\[\displaystyle \begin{aligned} \tilde{I}_{\text{mwis}} &= \frac{\sum_{i,s} \omega(X_{i,s})\,\frac{f(X_{i,s})}{p(X_{i,s})}}{\sum_{i,s} \omega(X_{i,s})} \qquad \text{with} \qquad \omega(x) = \frac{p(x)}{\bar{q}(x)} \\ &= \frac{\frac{1}{N}\sum_{i,s} \frac{f(X_{i,s})}{\bar{q}(X_{i,s})}}{\frac{1}{N}\sum_{i,s} \frac{p(X_{i,s})}{\bar{q}(X_{i,s})}} \end{aligned}\]

Note on the paper’s notation. The paper defines \(w_{i,\text{wis}} = p/(c_i\,q_i)\) (Eq. 19), so that \(w_{i,\text{mwis}} = p/\bar{q}\) for every strategy (Eq. 21), and writes the estimator without the \(1/n_i\) factors (Eq. 17), which is the same estimator. With this convention, the expectation form of the identity (Eq. 16) needs the proportions, \(I = \sum_i c_i\,\mathbb{E}_{q_i}\left[w_{i,\text{mwis}}\,f/p\right] / \sum_j c_j\,\mathbb{E}_{q_j}\left[w_{j,\text{mwis}}\right]\); without the \(c_i\) it only holds for equal \(n_i\). The estimator and the paper’s results are unaffected.

Downside:

13.4 Examples

In 1D. A target \(p\) made of two normal lobes, two strategies \(q_1 = \mathcal{N}(-1.5, 1)\) and \(q_2 = \mathcal{N}(1.5, 1.5^2)\) with equal sample counts (\(c_1 = c_2 = 1/2\)), and an integrand close to, but not proportional to, the target: \(f(x) = p(x)\,(2 + \sin(2x + 1))\).

MWIS in 1D: problem, decomposition of the target, weighted histogram and RMSE
Top left: the problem. Top right: the MIS weights split the target between the two strategies. Bottom left: the raw histogram of the samples follows the mixture q̄; weighted by ω = p/q̄, it follows the target p. Bottom right: RMSE of balance MIS and MWIS against the predictions of section 13.5: MWIS halves the variance.

Robustness to poor sources. Self normalization also makes MWIS robust to poor source samples, the motivation of the paper. A sample falling where \(p\) is negligible has a weight \(\omega = p/\bar{q}\) close to zero and drops out of both sums, while \(B_N\) rescales the estimate by the target mass that the remaining samples captured; in MIS this mass fluctuates and goes straight into the error. Here, with 200 samples per strategy, adding a third strategy that does not touch \(p\) (\(\mathcal{N}(6, 1)\) or \(\mathcal{N}(-4, 0.5^2)\)) leaves both RMSEs unchanged (MIS 0.047, MWIS 0.033): its samples are wasted but harmless. A broad, partly useful one (\(\mathcal{N}(0, 4^2)\)) helps MWIS (0.033 → 0.029) but not MIS (0.047 → 0.046).

In 2D, with uniform sources. Source 1 (orange) is uniform on the unit square, which is also the target \(p\) (as in Fig. 7.4 of my thesis [Fraboni:2021]). Source 2 is uniform on a polygon inside the square, with the same number of samples. The weight \(\omega = p/\bar{q}\) is large outside the polygon, where only source 1 contributes, and smaller inside, where the polygon samples are shared. For an integrand \(f = g\,p\), the balance MIS estimate is \(\frac{1}{N}\sum \omega\,g\) and the MWIS estimate \(\sum \omega\,g \big/ \sum \omega\). They only differ by the division by \(B_N\), a control variate with the fixed coefficient \(I\) (13.3), so the question is for which integrands it helps. (The MIS weights \(w_i = n_i q_i / \sum_k n_k q_k\) alone, as in the thesis figure, are not what MIS uses: they only apportion a sample among the strategies and do not turn it into a sample of \(p\).)

Relative RMSE of MIS and MWIS for eight integrands with the two uniform sources in 2D
Relative RMSE of both estimators on the same samples for eight integrands. With the square as target (purple), MWIS is exact for f = p and clearly better when f is close to p or large, the two are equal on small regions, and MIS is better on the polygon. With the polygon as target (green), MWIS is the best of the three.

The target is a design choice. MWIS needs a normalized, tractable \(p\) that is positive wherever \(f \neq 0\) and covered by the sources, not the natural density of the problem. With \(p'\) uniform on the polygon, the samples outside get a weight of exactly zero and vanish from both sums, and for \(f = \mathbb{1}_{\text{polygon}}\,(1 + \frac{1}{2}\sin 6\pi x)\) the ratio \(f/p'\) only varies with the sine.

Samples with their weights and weighted histograms with the square or the polygon as target, for the orange source alone and for MWIS
Weights for a target equal to the square (left pair) or to the polygon (right pair), for the orange source alone (a rejection for the polygon) and for MWIS. With the polygon as target, the orange samples outside it get a zero weight and all the samples of source 2 are used: the histogram error over the polygon is lower than with the orange samples alone.
RMSE against the number of samples for MIS and MWIS with the square or the polygon as target
RMSE against the number of samples. Left: f = p (1 + ½ sin 6πx) on the square, where MWIS is better than MIS at every N. Right: the same integrand restricted to the polygon, where MWIS with the square as target is worse than MIS, and better than both with the polygon as target.

Matching the target to the support of the integrand is what makes MWIS better than MIS in the right panel, a choice that MIS, which has no target, does not have. The coefficient of the control variate remains fixed at \(I\); whether one estimated from the samples would do better has yet to be tested.

Discarding samples with a Russian roulette. Back in 1D, with a third, poor strategy \(q_3 = \mathcal{N}(0, 4^2)\) added. Each sample \(x\) survives with probability \(a(x) = \min(1, p(x)/\tau)\) and \(f\) is only evaluated on the survivors, so most samples falling where \(p\) is small are dropped. The survival probability does not depend on the strategy: strategy \(i\) now has the density \(a(x)\,q_i(x)\) and the mixture is \(a(x)\,\bar{q}(x)\). The estimators are the same, restricted to the survivors, with \(a\,\bar{q}\) in place of \(\bar{q}\). MIS still divides by \(N\), the number of samples drawn, killed ones included:

\[\displaystyle \tilde{I}_{\text{mis}} = \frac{1}{N}\sum_{\text{kept}} \frac{f(X)}{a(X)\,\bar{q}(X)}, \qquad \tilde{I}_{\text{mwis}} = \frac{\sum_{\text{kept}} \frac{f(X)}{a(X)\,\bar{q}(X)}}{\sum_{\text{kept}} \frac{p(X)}{a(X)\,\bar{q}(X)}}\]
MWIS with a Russian roulette: setup, exact survival probability, survival probability known up to a factor
Left: the problem, the mixture of the three strategies and the survival probability a. Middle: RMSE against the number of evaluations of f when a is known exactly. Right: the true survival probability is κ·a with κ unknown, and only a is known: MIS is biased by the factor κ, MWIS is not affected; ignoring a altogether biases MWIS too.

13.5 Convergence and bias (proofs)

WIS and MWIS are both a ratio \(\tilde{I} = A_N / B_N\) of two sample means over all samples,

\[\displaystyle \begin{aligned} A_N &= \frac{1}{N}\sum_{i,s} a(X_{i,s}), \qquad a = \frac{f}{\bar{q}}, \\ B_N &= \frac{1}{N}\sum_{i,s} b(X_{i,s}), \qquad b = \frac{p}{\bar{q}} \end{aligned}\]

(WIS is the case \(k = 1\), \(\bar{q} = q\)). Since \(\sum_i c_i\,q_i = \bar{q}\), their means are \(\mathbb{E}\left[A_N\right] = \sum_i c_i\,\mathbb{E}_{q_i}\left[a(X)\right] = \int_\Omega f\,\mathrm{d}\mu = I\) and \(\mathbb{E}\left[B_N\right] = \int_\Omega p\,\mathrm{d}\mu = 1\). These expectations are finite whenever \(f\) is integrable: \(c_i\,q_i \leq \bar{q}\) gives \(\mathbb{E}_{q_i}\left[\,\lvert a(X) \rvert\,\right] \leq \frac{1}{c_i}\int_\Omega \lvert f \rvert\,\mathrm{d}\mu\) and \(\mathbb{E}_{q_i}\left[b(X)\right] \leq \frac{1}{c_i}\). Below, \(N \to \infty\) with fixed proportions \(c_i\), and \(\tilde{I} = 0\) by convention if \(B_N = 0\) (no sample where \(p > 0\); then \(A_N = 0\) too).

Convergence. By the strong law of large numbers for each strategy, \(\frac{1}{n_i}\sum_s a(X_{i,s}) \to \mathbb{E}_{q_i}\left[a(X)\right]\) almost surely, hence \(A_N = \sum_i c_i\,\frac{1}{n_i}\sum_s a(X_{i,s}) \to I\), and likewise \(B_N \to 1\). As \((u, v) \mapsto u/v\) is continuous at \((I, 1)\),

\[\displaystyle \tilde{I} = \frac{A_N}{B_N} \xrightarrow[N\to\infty]{} I \quad \text{almost surely:}\]

the estimator is consistent under the support conditions of 13.1, for any integrable \(f\).

Error. If moreover \(a\) and \(b\) have finite second moments under every \(q_i\), the central limit theorem (per strategy, the strategies being independent) gives \(\sqrt{N}\,(A_N - I,\, B_N - 1) \to \mathcal{N}(0, \Sigma)\) with \(\Sigma = \sum_i c_i\,\mathrm{Cov}_{q_i}\left[(a, b)\right]\). With the gradient \((1, -I)\) of \(u/v\) at \((I, 1)\), the delta method gives

\[\displaystyle \begin{aligned} &\sqrt{N}\,(\tilde{I} - I) \xrightarrow[N\to\infty]{} \mathcal{N}(0, \sigma^2), \\ &\sigma^2 = \sum_{i=1}^k c_i\,\mathrm{Var}_{q_i}\left[a(X) - I\,b(X)\right] = \sum_{i=1}^k c_i\,\mathrm{Var}_{q_i}\left[\frac{f(X) - I\,p(X)}{\bar{q}(X)}\right] \end{aligned}\]

so, under the boundedness assumptions of the next paragraph (which make \(N(\tilde{I}-I)^2\) uniformly integrable), the RMSE behaves as \(\sigma/\sqrt{N}\), against \(\sigma_{\text{mis}}/\sqrt{N}\) with \(\sigma^2_{\text{mis}} = \sum_i c_i\,\mathrm{Var}_{q_i}\left[f(X)/\bar{q}(X)\right]\) for balance MIS.

The bias vanishes in \(O(1/N)\). Assume now bounded values and weights: \(\lvert f/p \rvert \leq M\) wherever \(p > 0\), and \(b = p/\bar{q} \leq K\) (both hold in the 1D example). Then \(\lvert I \rvert \leq M\), and \(\lvert \tilde{I} \rvert \leq M\) since \(\tilde{I}\) is a weighted mean of values \(f/p\) with non negative weights. Multiply the exact expansion \(\frac{1}{B} = 1 - (B - 1) + \frac{(B-1)^2}{B}\) for \(B > 0\) by \(A\), with \(A/B = \tilde{I}\):

\[\displaystyle \tilde{I} = A_N - A_N\,(B_N - 1) + \tilde{I}\,(B_N - 1)^2\]

which also holds when \(B_N = 0\) (all terms vanish). Taking expectations: \(\mathbb{E}\left[A_N\right] = I\); since \(\mathbb{E}\left[B_N - 1\right] = 0\), \(\mathbb{E}\left[A_N\,(B_N - 1)\right] = \mathrm{Cov}(A_N, B_N)\); and \(\mathbb{E}\left[\tilde{I}\,(B_N - 1)^2\right] = I\,\mathrm{Var}(B_N) + \mathbb{E}\left[(\tilde{I} - I)(B_N - 1)^2\right]\). Hence

\[\displaystyle \begin{aligned} \mathbb{E}\left[\tilde{I}\right] - I = \ &I\,\mathrm{Var}(B_N) - \mathrm{Cov}(A_N, B_N) \\ &+ \mathbb{E}\left[(\tilde{I} - I)(B_N - 1)^2\right] \end{aligned}\]

By independence of the samples, \(\mathrm{Var}(B_N) = \frac{1}{N}\sum_i c_i\,\mathrm{Var}_{q_i}\left[b\right]\) and \(\mathrm{Cov}(A_N, B_N) = \frac{1}{N}\sum_i c_i\,\mathrm{Cov}_{q_i}\left[a, b\right]\). For the last term, Cauchy-Schwarz gives \(\left\lvert \mathbb{E}\left[(\tilde{I} - I)(B_N - 1)^2\right] \right\rvert \leq \mathbb{E}\left[(\tilde{I} - I)^2\right]^{1/2}\,\mathbb{E}\left[(B_N - 1)^4\right]^{1/2}\), where \(\mathbb{E}\left[(B_N - 1)^4\right] = O(1/N^2)\) for a mean of \(N\) independent, bounded, centered terms, and \(\mathbb{E}\left[(\tilde{I} - I)^2\right] \to 0\) by dominated convergence (\(\tilde{I} \to I\) almost surely and \(\lvert \tilde{I} - I \rvert \leq 2M\)). The last term is therefore \(o(1/N)\), and

\[\displaystyle \begin{aligned} \mathbb{E}\left[\tilde{I}\right] - I &= \frac{b_1}{N} + o\left(\frac{1}{N}\right), \\ b_1 &= \sum_{i=1}^k c_i\left(I\,\mathrm{Var}_{q_i}\left[b\right] - \mathrm{Cov}_{q_i}\left[a, b\right]\right) = -\sum_{i=1}^k c_i\,\mathrm{Cov}_{q_i}\left[a - I\,b,\ b\right] \end{aligned}\]

This is the second order (delta method) expansion of \(\mathbb{E}\left[X/Y\right]\) around the means: \(\frac{\mu_X}{\mu_Y} + \frac{\mu_X\,\mathrm{Var}(Y)}{\mu_Y^3} - \frac{\mathrm{Cov}(X, Y)}{\mu_Y^2}\), with \(\mu_X = I\) and \(\mu_Y = 1\).

Measured bias and standard deviation of MWIS against the predictions
The 1D example of 13.4. Left: the standard deviation follows σ/√N and the bias b₁/N, with b₁ = 0.160. Right: the scaled bias N·(E[Ĩ] − I) settles on b₁ once higher order terms fade.

13.6 Relation to Talbot’s resampling weights

Justin Talbot’s master’s thesis [Talbot:2005b], which extends the RIS paper of section 9 [Talbot:2005a], already combines several strategies with resampling (its section 4.6, a part that is not in the EGSR paper). I was not aware of it when writing the MWIS paper [Fraboni:2022].

Talbot’s weights. In the notation of 13.1, with an unnormalized target \(\hat{p}\), strategy \(i\) draws \(n_i\) candidates (his \(m_i\), out of \(N\) in total, his \(M\)). All the candidates are pooled into a single RIS step (section 9), the resampling weight of each one being multiplied by an MIS weight, for the balance heuristic

\[\displaystyle w(x) = \frac{n_i\,q_i(x)}{\sum_{k} n_k\,q_k(x)}\,\frac{\hat{p}(x)}{q_i(x)} = w_{i,\text{mis}}(x)\,\frac{\hat{p}(x)}{q_i(x)}\]

and the RIS estimator is kept as is: select \(Y\) among the candidates with probability proportional to \(w\), and estimate \(\frac{f(Y)}{\hat{p}(Y)}\,\frac{1}{N}\sum_{i,s} w(X_{i,s})\). This weight is our \(w_{i,\text{mwis}}\) with \(\hat{p}\) in place of \(p\): the MIS times WIS structure of 13.1 is already there. The thesis also presents WIS, but only combines MIS with resampling.

What is odd in the formula. Averaged over the selection, the estimate is \(\frac{1}{N}\sum_{i,s} w(X_{i,s})\,\frac{f(X_{i,s})}{\hat{p}(X_{i,s})}\), and its expectation, strategy by strategy, is

\[\displaystyle \mathbb{E} = \sum_{i=1}^k c_i\,\mathbb{E}_{q_i}\left[w_{i,\text{mis}}(X)\,\frac{f(X)}{q_i(X)}\right] = \int_\Omega f \sum_{i=1}^k c_i\,w_{i,\text{mis}}\,\mathrm{d}\mu\]

which equals \(I\) only if \(\sum_i c_i\,w_{i,\text{mis}} = 1\). With two strategies or more this cannot hold, since the MIS weights sum to one and every \(c_i < 1\): with equal allocation the estimator converges to \(I/k\), so two strategies with half the candidates each give exactly half the integral, whatever the heuristic. The weight \(w_{i,\text{mis}}\,\hat{p}/q_i\) is a per-technique weight, made for an estimator that averages each strategy over its own \(n_i\) samples (the \(1/n_i\) of 13.3). Pooling all the candidates under a single \(1/N\) average needs a per-candidate weight instead, \(1/c_i = N/n_i\) times larger:

\[\displaystyle w(x) = \frac{1}{c_i}\,w_{i,\text{mis}}(x)\,\frac{\hat{p}(x)}{q_i(x)} = \frac{\hat{p}(x)}{\bar{q}(x)}\]

which is \(\omega\) of 13.3 up to the normalization of the target (the form of the paper’s Eq. 21), and is unbiased in RIS. With equal allocation the printed weight is only off by the constant \(1/k\), which leaves the selection unchanged and scales the normalization alone; the images of the thesis’s Fig. 5.5 do not look half as bright, which suggests a slip in the write-up rather than in the renderer.

Same weight, two estimators. With the corrected weight, RIS selects one candidate \(Y\) with probability proportional to \(\omega\) and returns, unbiased,

\[\displaystyle \hat{I}_{\text{ris}} = \frac{f(Y)}{p(Y)}\,\frac{1}{N}\sum_{i,s}\omega(X_{i,s}) = \frac{f(Y)}{p(Y)}\,B_N\]

(a constant factor on \(p\) cancels), while MWIS keeps all the candidates in a ratio. The two are exactly linked:

\[\displaystyle \tilde{I}_{\text{mwis}} = \frac{\sum_{i,s}\omega(X_{i,s})\,\frac{f(X_{i,s})}{p(X_{i,s})}}{\sum_{i,s}\omega(X_{i,s})} = \mathbb{E}\left[\frac{f(Y)}{p(Y)} \;\middle\vert\; X_{1,1}, \dots, X_{k,n_k}\right]\]

MWIS is the resampling estimate averaged over the selection, with the normalizer \(B_N\) dropped, i.e. replaced by its expectation, one. In the terms of 13.5, RIS averaged over the selection gives \(A_N\), the balance MIS estimate, and MWIS gives \(A_N / B_N\).

When the strategies do not share a domain, the thesis also runs RIS separately for each strategy, with its own target \(\hat{p}_i\), and combines the selected samples with MIS weights computed from the \(\hat{p}_i\) (its section 4.6.2). Any weights that sum to one keep this combination unbiased, but with unnormalized targets the balance heuristic depends on their arbitrary scales.

13.7 Relation to GRIS

Generalized resampled importance sampling (GRIS) [Lin:2022], the theory behind ReSTIR, is concurrent work with the same weight structure, put to a different use. Its preprint appeared in early May 2022; the MWIS paper was online from February 2022 and presented at Eurographics in April, after my thesis (December 2021).

GRIS weights. GRIS resamples one of \(M\) candidates \(X_j\), possibly correlated and coming from other domains through shift mappings \(T_j\), each with an unbiased contribution weight \(W_j\) that stands for \(1/p_{X_j}(X_j)\) when that density is intractable, e.g. after a previous resampling pass. The resampling weights and the contribution weight of the selected sample \(Y\) are (its Eqs. 19 and 22)

\[\displaystyle \begin{aligned} w_j &= m_j(Y_j)\,\hat{p}(Y_j)\,W_j \left\lvert \frac{\partial T_j}{\partial X_j} \right\rvert, \qquad Y_j = T_j(X_j), \\ W_Y &= \frac{1}{\hat{p}(Y)}\sum_{j=1}^M w_j \end{aligned}\]

and \(f(Y)\,W_Y\) is an unbiased estimate of \(I\). The resampling MIS weights \(m_j\) must be non negative and sum to one over the candidates that can produce a given point of the target’s support (its Eqs. 4 and 20). The \(1/M\) of basic RIS lives in these weights, which is why \(W_Y\) has none (its footnote 6), and this per-candidate condition is exactly what Talbot’s printed weights miss (13.6); GRIS states them per candidate, \(m_j = p_j / \sum_l p_l\) (its Eq. 5, which it attributes to Talbot’s thesis, written there per candidate as in the corrected form of 13.6). The generalized Talbot weights replace the densities by \(\hat{p}_{\leftarrow j}\), a proxy target of candidate \(j\) carried to the target domain with the shift Jacobian, \(m_j = \hat{p}_{\leftarrow j} / \sum_l \hat{p}_{\leftarrow l}\) (its Eq. 36), and pairwise MIS (Eqs. 37 and 38) lowers the cost from \(O(M^2)\) to \(O(M\,\lvert R \rvert)\) for \(\lvert R \rvert\) canonical candidates. The supplemental document derives both families from a bound on the resampling weights, gives the variants with tractable densities in place of the proxies (its Section S.1.4), and contains no self normalized estimator.

In our notation. With \(n_i\) candidates from \(q_i\), \(N\) in total, tractable densities (\(W = 1/q_i\)) and an unnormalized target \(\hat{p} = Z\,p\), the generalized Talbot weight of a candidate from strategy \(i\) is the balance heuristic split per candidate, and the resampling weight is our \(\omega\):

\[\displaystyle \begin{aligned} m(x) &= \frac{q_i(x)}{N\,\bar{q}(x)} = \frac{w_{i,\text{mis}}(x)}{n_i}, \\ w(x) &= \frac{\hat{p}(x)}{N\,\bar{q}(x)} = \frac{Z}{N}\,\omega(x) = \frac{Z}{n_i}\,w_{i,\text{mwis}}(x) \end{aligned}\]

so that \(f(Y)\,W_Y = \frac{f(Y)}{p(Y)}\,B_N\), the corrected RIS estimator of 13.6. With shifts, \(q_i\) is the density of the shifted samples in the target domain, Jacobian included, as for the shifted prefixes of the application below, and the same identity holds with GRIS’s \(p_{\leftarrow i}\) in place of \(q_i\). The weights are the same; the estimators are not:

Neither is a special case of the other: every GRIS estimator has the unbiased form \(f(Y)\,W_Y\), while MWIS divides by the weight sum that GRIS multiplies by. GRIS brings unbiasedness, unnormalized targets, intractable source densities, shift mappings with partial domains, cheap pairwise weights and convergence guarantees for correlated, chained resampling. MWIS brings the self normalization, with no selection noise, the cancellation of correlated errors (13.3) and its \(O(1/N)\) bias analysis (13.5), at the price of tractable source densities, a normalized target and the integrand evaluated at every sample.

13.8 Application: multi-view rendering with the MWIS estimator

14. To learn for next time

References