Week 4: Advanced Sampling and Variance Reduction

STAT 536 — Statistical Computing

Soumojit Das

Fall 2026

Ratio of Uniforms

Beyond Accept-Reject: Motivation

Recall: Accept-Reject Challenges.

  • Finding good proposal \(g(x)\) can be difficult
  • Computing \(M = \sup_x \frac{f(x)}{g(x)}\) may be hard
  • Efficiency \(1/M\) can be poor

Recall how much work last week went into choosing \(g\) and computing the optimal \(M\)? Ratio of uniforms sidesteps both.

Ratio of Uniforms: A Different Approach. Instead of sampling from \(X\) directly:

  1. Sample \((U, V)\) uniformly from a 2D region
  2. Transform to get \(X = V/U\)
  3. Automatic normalization.

Key Advantage. Works directly with unnormalized densities without finding normalizing constants.

Ratio of Uniforms: The Theorem

Theorem (Kinderman-Monahan, 1977). Let \(f(x) \geq 0\) be a density (possibly unnormalized). Define region: \[\mathcal{R}_f = \left\{(u,v): 0 \leq u \leq \sqrt{f(v/u)}\right\}\]

If \((U,V) \sim \Uniform(\mathcal{R}_f)\), then \(X = V/U\) has density proportional to \(f\).

In words: scatter points uniformly on a region in the \((u,v)\) plane defined by \(f\), then read off \(X = V/U\). The transformation from uniform samples to the target happens through the geometry of the region.

Ratio of Uniforms: Derivation

Change of variables. \((u,v) \to (u, x)\) where \(x = v/u\), so \(v = ux\).

Jacobian. \(\dfrac{\partial(u,v)}{\partial(u,x)} = \begin{pmatrix} 1 & 0 \\ x & u \end{pmatrix}\), so \(|J| = u\).

Joint density of \((U,X)\). Since \((U,V)\) is uniform on \(\mathcal{R}_f\): \[p(u,x) = \frac{u}{|\mathcal{R}_f|} \cdot \mathbf{1}\left[0 \leq u \leq \sqrt{f(x)}\right]\]

Marginal of \(X\): \[p(x) = \int_0^{\sqrt{f(x)}} \frac{u}{|\mathcal{R}_f|} \, du = \frac{1}{|\mathcal{R}_f|} \cdot \frac{f(x)}{2} \propto f(x) \qquad \square\]

Finding the Bounding Rectangle

The Challenge. We need to sample uniformly from \(\mathcal{R}_f\). Solution: find a rectangle containing \(\mathcal{R}_f\).

Bounds Needed.

\[ \begin{aligned} a^+ &= \sup_{x} \sqrt{f(x)} \\ b^- &= \inf_{x}\; x\sqrt{f(x)} \\ b^+ &= \sup_{x}\; x\sqrt{f(x)} \end{aligned} \]

Rectangle. Sample \((U,V)\) uniformly from \([0, a^+] \times [b^-, b^+]\).

Ratio of Uniforms: Algorithm

Algorithm.

  1. Generate \(U \sim \Uniform(0, a^+)\)
  2. Generate \(V \sim \Uniform(b^-, b^+)\)
  3. Set \(X \leftarrow V/U\)
  4. Accept if \(U^2 \leq f(X)\); otherwise return to step 1

Example: Standard Normal. For \(f(x) = \exp(-x^2/2)\):

  • \(a^+ = \sqrt{f(0)} = 1\)
  • \(b^- = -\sqrt{2/e}\) (solve \(\frac{d}{dx}[x \exp(-x^2/4)] = 0\))
  • \(b^+ = +\sqrt{2/e}\)

Ratio of Uniforms: Examples

Example 1: Gamma Distribution. For \(\Gam(\alpha, 1)\), \(\alpha \geq 1\), with \(f(x) = x^{\alpha-1}e^{-x}\):

  • \(a^+ = \left(\frac{\alpha-1}{e}\right)^{(\alpha-1)/2}\)
  • \(b^- = 0\)
  • \(b^+ = \left(\frac{\alpha+1}{e}\right)^{(\alpha+1)/2}\)

Example 2: Student’s \(t\). For the \(t_\nu\) distribution:

  • Bounds depend on \(\nu\)
  • Efficient for heavy tails.

Adaptive Rejection Sampling

ARS: The Problem

Recall: Accept-Reject Challenges. For complex distributions, finding a good proposal \(g\) is hard.

  • Too loose: poor efficiency
  • Too tight: difficult to sample from
  • Fixed envelope: can’t improve

The ARS Innovation (Gilks & Wild, 1992). What if rejected points could improve our envelope?

  • Build envelope that gets tighter with each rejection
  • Turn “failures” into information
  • Achieve near-perfect efficiency as sampling proceeds

Log-Concavity

Definition. A density \(f\) is log-concave if \(\log f\) is concave: \[\log f(\lambda x + (1-\lambda)y) \geq \lambda \log f(x) + (1-\lambda)\log f(y)\]

Log-Concave Distributions.

  • Normal (any \(\mu, \sigma^2\))
  • Exponential, Laplace
  • Gamma (\(\alpha \geq 1\))
  • Beta (\(\alpha, \beta \geq 1\))
  • Uniform (trivially)
  • Chi-squared (\(\nu \geq 2\))

Why Log-Concavity Matters. In log space:

  • Tangents: upper bounds
  • Chords: lower bounds
  • Piecewise linear: easy to construct

In original space:

  • Piecewise exponential: still easy to sample.

Building Adaptive Envelopes

Building Adaptive Envelopes in Log Space.

  1. Start with a few evaluation points
  2. Draw tangent lines at these points (always above due to concavity)
  3. Take the minimum of all tangents: upper hull
  4. Connect adjacent points with straight lines: lower hull

The Sandwich Property. \[\text{Lower hull} \leq \log f(x) \leq \text{Upper hull}\] Exponentiating: \(\exp(\text{Lower hull}) \leq f(x) \leq \exp(\text{Upper hull})\)

The Adaptive Part. When we reject a point \(x^*\), we have already evaluated \(f(x^*)\). Add \(x^*\) as a new support point: the upper hull gets tighter at \(x^*\), the envelope improves, and future efficiency increases.

ARS: Initial Envelope

  • 4 initial points: Tangents create loose upper hull
  • Shaded region: Gap between upper and lower bounds
  • Efficiency: Proportional to gap area (smaller is better)

ARS: After Adaptation

  • 7 support points: Added 3 rejected samples
  • Tighter envelope: Shaded region much smaller
  • Higher efficiency: proposals per accepted draw fall from 1.08 to 1.04; each rejection improved the envelope for good

ARS: The Algorithm (Setup)

Initialization.

  1. Require: Initial points \(S = \{x_1, \ldots, x_k\}\), target \(\log f\)
  2. Compute \(h_i = \log f(x_i)\) for all \(x_i \in S\)
  3. Build upper hull \(u(x)\) from tangents at \(S\)
  4. Build lower hull \(\ell(x)\) from chords between adjacent points

Key Components.

  • Upper hull: Piecewise linear (tangents) in log space
  • Lower hull: Piecewise linear (chords) in log space
  • Proposal: \(\exp(u(x))/Z\) is piecewise exponential

ARS: The Algorithm (Sampling Loop)

Sampling.

  1. Sample \(X \sim \exp(u(x))/Z\) where \(Z = \int \exp(u(x))dx\)
  2. Generate \(U \sim \Uniform(0,1)\)
  3. If \(U \leq \exp(\ell(X) - u(X))\): squeeze accept (no \(f\) evaluation needed)
  4. Else compute \(h_X = \log f(X)\) (expensive step)
    • If \(U \leq \exp(h_X - u(X))\): accept
    • Else reject and adapt: \(S \leftarrow S \cup \{X\}\), update hulls

ARS: Three Types of Outcomes

  1. Squeeze Accept (best case). Test: \(U \leq \exp(\ell(X) - u(X))\). No evaluation of \(f(X)\) needed. Frequency increases as envelope tightens. Computational cost: \(O(1)\).

  2. Normal Accept. Test: \(U \leq \exp(\log f(X) - u(X)) = f(X)/\text{envelope}(X)\). Requires one evaluation of \(f(X)\). Standard accept-reject step. Computational cost: \(O(1) +\) cost of \(f\).

  3. Reject and Adapt. Sample rejected but not wasted. Add \(X\) to support points. Update hulls: \(O(\log k)\) for \(k\) points. Future sampling more efficient.

ARS: Advantages and Extensions

Advantages.

  • Self-improving: Gets better as it runs
  • Minimal setup: Just 2-3 initial points
  • Squeeze property: Saves expensive evaluations
  • Guaranteed convergence: Envelope approaches target

When to Use ARS.

  • Log-concave target
  • Expensive \(f\) evaluations
  • Need many samples
  • Unknown normalization OK

Implementation Tips.

  • Data structure: Sorted list of \((x_i, h_i, h'_i)\)
  • Sampling: Exponential pieces via inversion
  • Binary search: Find piece in \(O(\log k)\)
  • Numerical: Work in log space always

Extensions.

  • ARMS: Metropolis step for non-log-concave
  • Transformed ARS: \(T(X)\) where \(T(\cdot)\) makes log-concave
  • Multivariate: Possible but complex

Monte Carlo Integration

Monte Carlo Integration: A Recap

The Problem. Evaluate: \(I = \int_{\mathcal{X}} h(x) f(x) dx = \E_f[h(X)]\)

Basic Monte Carlo. Sample \(X_1, \ldots, X_n \iid f\), estimate \(\hat{I}_n = \frac{1}{n}\sum_{i=1}^n h(X_i)\).

  • \(\E[\hat{I}_n] = I\) (unbiased)
  • \(\Var[\hat{I}_n] = \frac{\Var_f[h(X)]}{n}\)
  • \(\hat{I}_n \xrightarrow{a.s.} I\) (SLLN)
  • \(\sqrt{n}(\hat{I}_n - I) \xrightarrow{d} \Normal(0, \Var_f[h(X)])\)

Recall the \(n^{-1/2}\) rate from week 1? It is dimension-free: the same rate in one dimension and in a million. Everything that follows is about pushing the constant in front of \(n^{-1/2}\) down.

Error Rate. Standard error: \(O(n^{-1/2})\), independent of dimension. Compare: Riemann sums \(O(n^{-1/d})\).

Importance Sampling

The Importance Sampling Identity

\[I = \int h(x)f(x)dx = \int h(x)\frac{f(x)}{g(x)}g(x)dx = \E_g\left[h(X)\frac{f(X)}{g(X)}\right]\]

Algorithm.

  1. Sample \(X_1, \ldots, X_n \iid g\)
  2. Compute weights \(w_i = \frac{f(X_i)}{g(X_i)}\)
  3. Estimate: \(\hat{I}_{IS} = \frac{1}{n}\sum_{i=1}^n h(X_i)w_i\)

Instead of sampling from the target \(f\) and averaging \(h\), sample from a proposal \(g\) you can draw from and reweight each draw by \(f/g\). Every draw is kept; none are rejected.

Importance Sampling: Unbiasedness and Variance

Unbiasedness. \[\E_g[\hat{I}_{IS}] = \E_g\left[h(X)\frac{f(X)}{g(X)}\right] = \int h(x)\frac{f(x)}{g(x)}g(x)dx = \int h(x)f(x)dx = I\]

Variance. \[\Var_g[\hat{I}_{IS}] = \frac{1}{n}\Var_g\left[h(X)\frac{f(X)}{g(X)}\right] = \frac{1}{n}\left(\int \frac{h(x)^2 f(x)^2}{g(x)} dx - I^2\right)\]

The variance depends on the match between \(g\) and \(|h|f\): where \(g\) underweights regions that matter for \(hf\), the importance weights blow up and the variance grows.

Finite-variance condition. The estimator has finite variance when \(\int \frac{h(x)^2 f(x)^2}{g(x)} dx < \infty\).

Importance Sampling: Optimal Proposal

Optimal Proposal. Minimum variance when: \[g^*(x) \propto |h(x)|f(x)\]

Zero variance if \(h \geq 0\). But \(g^*\) requires knowing \(\int |h(x)|f(x)dx\), which is the integral you are trying to compute.

Weight Degeneracy

When \(g\) has thinner tails than \(f\), a few weights dominate the sum. The effective sample size collapses; the running estimate sits at a plateau that looks converged, usually too low, until a single large weight arrives and moves it. The estimator stays consistent, but its error is heavy-tailed and no finite \(n\) is safe. High dimensions make this worse: for a fixed mismatch between \(g\) and \(f\), the largest weight’s share of the total grows exponentially with the dimension.

Self-Normalized Importance Sampling

When \(f\) is Known Only Up to Constants. If \(f(x) = \tilde{f}(x)/Z\) where \(Z\) unknown:

  1. Sample \(X_1, \ldots, X_n \iid g\)
  2. Compute unnormalized weights: \(\tilde{w}_i = \frac{\tilde{f}(X_i)}{g(X_i)}\)
  3. Normalize: \(w_i = \frac{\tilde{w}_i}{\sum_{j=1}^n \tilde{w}_j}\)
  4. Estimate: \(\hat{I}_{SNIS} = \sum_{i=1}^n w_i h(X_i)\)

Properties.

  • Biased for finite \(n\) (ratio of estimates)
  • Asymptotically unbiased
  • Often lower MSE than standard IS

This is a ratio of two Monte Carlo estimates, so the bias vanishes as \(n \to \infty\) but is nonzero for any finite sample. This is the importance-sampling version of the unnormalized-target idea from Accept-Reject last week: the normalizing constant never needs to be computed.

When Importance Sampling Fails

Left: estimating \(P(X > 3)\) for a standard normal. A \(\Normal(3,1)\) proposal concentrates draws where the integrand lives and beats plain MC by orders of magnitude. Right: estimating \(\E[X^2]\) for \(X \sim t_3\). A \(\Normal(0,1)\) proposal has lighter tails, so the weights are unbounded and the running estimate never settles. A \(t_1\) proposal has heavier tails and converges.

What You Actually Do in Practice

  1. Choose \(g\) with heavier tails than \(f\). If \(g\) drops off faster than \(f\), some weights will eventually dominate. There is no recovering from lighter tails.

  2. Look at the weights. Plot the unnormalized weights and check for a few extreme values dwarfing the rest. This is the first and cheapest diagnostic.

  3. Effective sample size. \(n_{\text{eff}} = \frac{(\sum_i w_i)^2}{\sum_i w_i^2}\). When \(n_{\text{eff}} \ll n\), a handful of particles carry all the weight and the estimate is unreliable.

  4. PSIS \(\hat{k}\) as the diagnostic. Fit a generalized Pareto to the largest weights; its shape estimate \(\hat{k}\) reads off the tail. \(\hat{k} < 0.5\): the weights have finite variance. \(0.5 \leq \hat{k} < 0.7\): infinite variance, but the smoothed estimate is still usable. \(\hat{k} \geq 0.7\): do not trust it, change \(g\). We will see this again in the Bayesian block.

Variance Reduction

Variance Reduction: Overview

Goal. Reduce \(\Var[\hat{I}]\) without increasing computational cost (much).

Main Techniques.

  1. Control Variates: Use correlated auxiliary variable
  2. Antithetic Variables: Introduce negative correlation
  3. Stratified Sampling: Divide and conquer
  4. Rao-Blackwellization: Use conditional expectations
  5. Common Random Numbers: For comparisons

Control Variates

The Idea. Use a correlated variable \(Y\) with known \(\E[Y] = \mu_Y\): \[\hat{I}_{CV} = \hat{I} - c(\bar{Y} - \mu_Y)\]

Optimal \(c\). \[c^* = \frac{\Cov(h(X), Y)}{\Var(Y)}\]

Variance reduction: \[\frac{\Var[\hat{I}_{CV}]}{\Var[\hat{I}]} = 1 - \rho^2_{h(X),Y}\]

The optimal coefficient \(c^*\) is the slope of the regression of \(h(X)\) on \(Y\). The variance reduction equals the \(R^2\) of that regression: the more \(Y\) explains \(h(X)\), the more variance you remove.

Example. Estimating \(\E[e^X]\) where \(X \sim \Normal(0,1)\): use \(Y = X\) as control, \(\E[Y] = 0\) known. High correlation.

Control Variate Adjustment

Antithetic Variables

The Idea. Generate pairs \((X, X')\) with:

  • Same marginal distribution
  • Negative correlation

Implementation. For \(U \sim \Uniform(0,1)\):

  • Use both \(U\) and \(1-U\)
  • Transform both via \(F^{-1}\)

Estimate: \(\hat{I}_{AV} = \frac{1}{2n}\sum_{i=1}^n [h(X_i) + h(X'_i)]\)

Antithetic Variables: Detailed Analysis

Variance Reduction Formula. For antithetic pairs \((X, X')\) with \(X' = F^{-1}(1-U)\) when \(X = F^{-1}(U)\): \[\Var[\hat{I}_{AV}] = \frac{1}{2n}[\Var(h(X)) + \Cov(h(X), h(X'))]\]

Reduction factor: \(\dfrac{\Var[\hat{I}_{AV}]}{\Var[\hat{I}_{MC}]} = \dfrac{1}{2}[1 + \rho_{h(X),h(X')}]\)

The factor compares \(n\) antithetic pairs with \(n\) independent draws. A pair costs two evaluations of \(h\), so it has to beat \(1/2\) to pay for itself: it does when \(h\) is monotone (\(\rho < 0\)), and it loses when \(\rho > 0\), as for a U-shaped or oscillating \(h\).

Antithetic Variables: Example

Example: \(\E[e^X]\), \(X \sim \Uniform(0,1)\).

  • \(X' = 1 - X\) (perfect negative correlation)
  • \(\Cov(e^X, e^{1-X}) = e - (e-1)^2 \approx -0.234\)
  • \(\Var(e^X) = (e^2-1)/2 - (e-1)^2 \approx 0.242\)
  • \(\rho_{h(X),h(X')} \approx -0.968\)
  • Reduction factor: \(\frac{1}{2}(1 - 0.968) = 0.016\)

\(e^X\) is nearly linear on \([0, 1]\), so this is close to the best case; the next slide gives the typical range.

Antithetic Variables: Practical Gains

When Antithetic Works Best.

  • \(h\) is monotonic: \(\rho < 0\)
  • Linear \(h\) with symmetric \(f\): perfect
    • \(\rho = -1\)
    • Reduction factor = 0
    • Zero variance.

Typical reduction factors:

  • Monotonic \(h\): 0.1–0.3
  • Non-monotonic \(h\): 0.4–0.6
  • Worst case: \(> 0.5\) (harmful)

Stratified Sampling

The Idea.

  1. Partition domain: \(\mathcal{X} = \bigcup_{j=1}^k A_j\)
  2. Sample \(n_j\) points from each \(A_j\)
  3. Weight by \(p_j = P(X \in A_j)\)

Estimate. \[\hat{I}_{SS} = \sum_{j=1}^k p_j \hat{I}_j\] where \(\hat{I}_j\) is the estimate from stratum \(j\).

With \(\sigma_j^2 = \Var[h(X) \mid X \in A_j]\) the within-stratum variance, the variance of a plain Monte Carlo draw splits into a within-strata part and a between-strata part. Stratified sampling removes the between-strata part, so the gain is larger when the stratum means \(\mu_j\) differ widely; the split \(n_j \propto p_j \sigma_j\) on the next slide is the optimal allocation.

Stratified Sampling: Detailed Analysis

Variance Reduction Formula. With \(k\) strata, proportions \(p_j = P(X \in S_j)\), and \(n_j\) samples from stratum \(j\): \[\Var[\hat{I}_{SS}] = \sum_{j=1}^k p_j^2 \frac{\sigma_j^2}{n_j}\]

Proportional Allocation. Set \(n_j = n \cdot p_j\): \[\Var[\hat{I}_{SS}] = \frac{1}{n}\sum_{j=1}^k p_j \sigma_j^2\]

Compare to basic MC: \[\Var[\hat{I}_{MC}] = \frac{\sigma^2}{n} = \frac{1}{n}\left[\sum_{j=1}^k p_j \sigma_j^2 + \sum_{j=1}^k p_j(\mu_j - \mu)^2\right]\]

Reduction = between-strata variance.

Optimal (Neyman) Allocation. Set \(n_j \propto p_j \sigma_j\): \[\Var[\hat{I}_{SS}^{opt}] = \frac{1}{n}\left(\sum_{j=1}^k p_j \sigma_j\right)^2\]

Example: \(h(x) = x^2\) on \([0,1]\) with 4 strata

  • Basic MC: \(\Var = 4/45 \approx 0.0889/n\)
  • Proportional: \(\Var = 0.00686/n\), factor 0.077
  • Optimal: \(\Var = 0.00524/n\), factor 0.059

Four Variance-Reduction Ideas, Four Roles

Method Exploits Needs Hurts when
Control Variates Correlation with a known-mean auxiliary Exact \(\E[Y]\), estimable \(\Cov\) \(Y\) is uncorrelated with \(h(X)\)
Antithetic Variables Monotonicity of \(h\) \(F^{-1}\) or a pairing rule \(h\) is non-monotone (\(\rho > 0\))
Stratified Sampling Heterogeneity across strata Computable \(p_j\), pilot \(\sigma_j\) Strata means are equal
Importance Sampling Concentration of \(hf\) Heavier tails than \(f\) \(g\) has lighter tails (weight degeneracy)

Variance Reduction Comparison

All four methods spend the same 1000 evaluations of \(h\), so the antithetic ratio shown is \(1 + \rho = 0.032\), twice the per-pair factor \(\tfrac12(1+\rho) = 0.016\) quoted earlier; the control variate \(Y = U\) (\(\rho = 0.992\)) and ten proportional strata do about as well on this near-linear integrand.

The Ugly Truth

What Textbooks Don’t Tell You. Those beautiful variance reduction formulas assume we know things we don’t.

The Setup Costs.

  • Stratified: Need pilot study to estimate \(p_j\), \(\sigma_j\)
  • Control Variates: Must know \(\E[Y]\) exactly
  • Importance Sampling: Finding good proposal is hard
  • Antithetic: Only works if \(h\) is monotonic

Reality Check. 10 strata, 1000 pilot samples, 10000 main samples:

  • 10% overhead just for setup
  • Need more than 10% variance reduction to break even
  • Often don’t get it.

When Classical Methods Fail

Stratified Sampling Dies In:

  • High dimensions (curse of dimensionality)
  • Complex distributions (can’t compute \(P(X \in S_j)\))
  • Black-box simulators (no access to internals)

Importance Sampling Dies In:

  • High dimensions (weight degeneracy)
  • Tail mismatch: proposal lighter than the target (infinite variance)
  • Bad proposal choice (most of them)

The Brutal Truth. In practice, just using more samples often beats fancy variance reduction.

PSIS

Pareto Smoothed Importance Sampling. The one method that actually works in practice.

The Key Idea. Extreme importance weights follow a Pareto distribution.

  • Fit generalized Pareto to largest 20% of weights
  • Replace extreme weights with smoothed values
  • Get automatic reliability diagnostic (\(\hat{k}\))

The \(\hat{k}\) Diagnostic.

  • \(\hat{k} < 0.5\): Excellent, trust results
  • \(0.5 \leq \hat{k} < 0.7\): OK, use with caution
  • \(\hat{k} \geq 0.7\): Bad, don’t trust, recompute

Why PSIS Dominates

Where You’ll See It.

  • Stan (loo package)
  • ArviZ (Python/R)
  • Any modern Bayesian software

The Killer App: LOO-CV from One MCMC Run. Without PSIS: Run MCMC \(n\) times (impossible). With PSIS: Run MCMC once, get LOO-CV for free.

But more on this when we formally enter the realms of Bayesian computing.

What to Carry Out of the Room

  • Ratio of uniforms replaces Accept-Reject’s proposal \(g\) and bound \(M\) with bounds on a 2D region, and handles unnormalized densities automatically.
  • ARS builds and tightens its own envelope as it runs, for any log-concave target.
  • Importance sampling is the centerpiece: keep every draw, weight by \(f/g\), and the variance of the weighted average depends entirely on how well \(g\) matches \(|h|f\).
  • The four variance-reduction techniques each exploit a different structural feature and each can backfire when the feature is absent.

The week’s punchline: once you move from generating samples to estimating integrals, the design problem shifts from “which draws do I keep?” to “which draws do I weight, and how?” Importance sampling is the bridge between the sampling methods of weeks 2–4 and the Bayesian computing machinery from week 10 on, and the \(\hat{k}\) diagnostic tells you whether the bridge is holding.

Next week: the bootstrap. A different answer to “how do I estimate variability?”, one that replaces distributional assumptions with the empirical distribution.