STAT 536 — Statistical Computing
Fall 2026
Recall: Accept-Reject Challenges.
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:
Key Advantage. Works directly with unnormalized densities without finding normalizing constants.
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.
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\]
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^+]\).
Algorithm.
Example: Standard Normal. For \(f(x) = \exp(-x^2/2)\):
Example 1: Gamma Distribution. For \(\Gam(\alpha, 1)\), \(\alpha \geq 1\), with \(f(x) = x^{\alpha-1}e^{-x}\):
Example 2: Student’s \(t\). For the \(t_\nu\) distribution:
Recall: Accept-Reject Challenges. For complex distributions, finding a good proposal \(g\) is hard.
The ARS Innovation (Gilks & Wild, 1992). What if rejected points could improve our envelope?
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.
Why Log-Concavity Matters. In log space:
In original space:
Building Adaptive Envelopes in Log Space.
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.
Initialization.
Key Components.
Sampling.
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)\).
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\).
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.
Advantages.
When to Use ARS.
Implementation Tips.
Extensions.
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)\).
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})\).
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.
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.
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\).
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.
When \(f\) is Known Only Up to Constants. If \(f(x) = \tilde{f}(x)/Z\) where \(Z\) unknown:
Properties.
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.
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.
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.
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.
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.
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.
Goal. Reduce \(\Var[\hat{I}]\) without increasing computational cost (much).
Main Techniques.
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.
The Idea. Generate pairs \((X, X')\) with:
Implementation. For \(U \sim \Uniform(0,1)\):
Estimate: \(\hat{I}_{AV} = \frac{1}{2n}\sum_{i=1}^n [h(X_i) + h(X'_i)]\)
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\).
Example: \(\E[e^X]\), \(X \sim \Uniform(0,1)\).
\(e^X\) is nearly linear on \([0, 1]\), so this is close to the best case; the next slide gives the typical range.
When Antithetic Works Best.
Typical reduction factors:
The Idea.
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.
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
| 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) |
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.
What Textbooks Don’t Tell You. Those beautiful variance reduction formulas assume we know things we don’t.
The Setup Costs.
Reality Check. 10 strata, 1000 pilot samples, 10000 main samples:
Stratified Sampling Dies In:
Importance Sampling Dies In:
The Brutal Truth. In practice, just using more samples often beats fancy variance reduction.
Pareto Smoothed Importance Sampling. The one method that actually works in practice.
The Key Idea. Extreme importance weights follow a Pareto distribution.
The \(\hat{k}\) Diagnostic.
Where You’ll See It.
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.
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.