STAT 536 — Statistical Computing
Fall 2026
The Challenge. What if:
Examples.
Solution. Accept-Reject: a general method using an easier “instrumental” distribution.
Theorem (Accept-Reject; von Neumann, 1951). Let \(f\) be the target density and \(g\) be an instrumental density with \[f(x) \leq M g(x) \quad \text{for all } x \text{ in the support of } f.\] Then the following algorithm generates \(X \sim f\).
Algorithm.
Acceptance probability \(= 1/M\).
Essentially, if we can bound the target \(f\) by a constant multiple of an easier density \(g\), proposing from \(g\) and randomly thinning the proposals produces exact draws from \(f\).
Recall Marsaglia’s polar method from last week? Propose uniformly on the square, keep only the disc. That was accept-reject for the uniform distribution on the disc, with \(g\) uniform on \([-1,1]^2\) and acceptance region \(\{V_1^2 + V_2^2 \leq 1\}\), giving \(M = 4/\pi\).
The Claim. The Accept-Reject algorithm produces samples from the target distribution \(f\).
If \(X\) is the output of the algorithm, we need to show \[P[X \in A] = \int_A f(x)dx \quad \text{for any set } A.\] Equivalently, show the CDF: \(P[X \leq x] = \int_{-\infty}^x f(t)dt\).
\(X\) is a \(Y \sim g\) that was accepted. So we need \[P[X \leq x] = P[Y \leq x \mid Y \text{ was accepted}].\]
The Acceptance Criterion. We accept \(Y\) when \(U \leq \dfrac{f(Y)}{Mg(Y)}\). This is a random event that depends on both \(Y\) and \(U\).
For a fixed \(y\)
\[ \begin{aligned} P[\text{accept} \mid Y = y] &= P\left[U \leq \frac{f(y)}{Mg(y)}\right]\\ &= \frac{f(y)}{Mg(y)} \end{aligned} \]
Since \(U \sim \Uniform(0,1)\).
Important.
Using rules of conditional probability: \[P[X \leq x] = P[Y \leq x \mid \text{accept}] = \frac{P[Y \leq x \text{ and accept}]}{P[\text{accept}]}\]
The numerator.
\[ \begin{aligned} P[Y \leq x \text{ and accept}] &= \int_{-\infty}^x P[\text{accept} \mid Y=y] \cdot g(y)dy\\ &= \int_{-\infty}^x \frac{f(y)}{Mg(y)} \cdot g(y)dy\\ &= \frac{1}{M}\int_{-\infty}^x f(y)dy \end{aligned} \]
The denominator. Same computation over the whole line:
\[ P[\text{accept}] = \int_{-\infty}^{\infty} \frac{f(y)}{Mg(y)} \cdot g(y)dy = \frac{1}{M}\int_{-\infty}^{\infty} f(y)dy = \frac{1}{M} \]
Combining the two,
\[ \begin{aligned} P[X \leq x] &= \frac{P[Y \leq x \text{ and accept}]}{P[\text{accept}]}\\ &= \frac{\frac{1}{M}\int_{-\infty}^x f(y)dy}{\frac{1}{M}}\\ &= \int_{-\infty}^x f(y)dy = F(x) \end{aligned} \]
Correctness of Accept-Reject
Therefore, \(X\) has CDF \(F\) \(\implies\) \(X \sim f\). \(\square\)
Consider the joint distribution of \((Y, U)\) conditional on acceptance. The accepted points satisfy \(0 \leq U \leq \dfrac{f(Y)}{Mg(Y)}\), so \[f_{Y,U \mid \text{accept}}(y,u) = \frac{g(y) \cdot 1 \cdot \mathbf{1}\left[0 \leq u \leq \frac{f(y)}{Mg(y)}\right]}{P[\text{accept}]}.\]
Marginal density of \(Y\) given acceptance:
\[ f_{Y \mid \text{accept}}(y) = \int_0^{f(y)/(Mg(y))} \frac{g(y)}{1/M} \, du = \frac{g(y) \cdot \frac{f(y)}{Mg(y)}}{1/M} = f(y) \]
Accepted \(Y\) values are distributed exactly according to \(f\).
The Fundamental Principle. To sample from \(f\), we need to see values \(y\) with frequency proportional to \(f(y)\).
What A-R Does
Example. If \(g(y_0) = 2f(y_0)\):
The Role of \(M\). Ensures \(\dfrac{f(y)}{Mg(y)} \leq 1\) so we have valid probabilities.
Accept-Reject uniformly samples points under the curve \(Mg(x)\) and keeps those under \(f(x)\).
Theorem (Fundamental Theorem of Simulation). To generate \(X \sim f\), it suffices to:
Essentially, this says that scattering points uniformly under a density curve and reading off their \(x\)-coordinates produces draws from the density.
Accept-Reject implements this by:
The proof asks nothing of \(g\) beyond \(f \leq Mg\), so what is left is a design problem: pick a \(g\) you can sample from, then make \(M\) as small as it will go.
Requirements.
Critical. If \(g\) has thinner tails than \(f\): \[\lim_{x \to \infty} \frac{f(x)}{g(x)} = \infty.\] Then \(M = \infty\).
If the instrumental density drops off faster than the target in the tails, the ratio \(f/g\) grows without bound, no finite \(M\) exists, and the algorithm cannot run.
Optimization. Want small \(M\) for efficiency:
Common Choices.
General Approach.
Target: \(f(x) = \dfrac{1}{\sqrt{2\pi}} e^{-x^2/2}\). Instrumental: \(g(x) = \dfrac{1}{2} e^{-|x|}\).
Problem. Generate \(X \sim \Gam(\alpha, \beta)\) where \(\alpha \notin \mathbb{N}\) and \(\alpha > 1\).
Instrumental: an integer-shape Gamma. Let \(a = \lfloor\alpha\rfloor \geq 1\) and \(d = \alpha - a \in (0,1)\), and use \(g \sim \Gam(a, b)\), which is a sum of \(a\) exponentials.
Minimizing \(M\) over \(b\) gives \(b^* = \dfrac{a\beta}{\alpha}\), and then
\[M = \frac{\Gamma(a)}{\Gamma(\alpha)} \cdot \frac{\alpha^\alpha}{a^a} \cdot e^{-(\alpha - a)}.\]
Efficiency. \(M\) is free of the rate \(\beta\): only the shape matters. For \(\alpha = 2.5\), \(M \approx 1.13\) and the sampler accepts 89% of proposals.
Problem. Generate \(X \sim f(x) \propto e^{-x^2/2} \mathbf{1}[x > a]\) (truncated normal).
Method 1: Naive
Efficiency: \(P[Z > a] = 1 - \Phi(a)\). Very inefficient for large \(a\).
Method 2: Shifted Exponential
Use \(g(x) = \lambda e^{-\lambda(x-a)}\mathbf{1}[x > a]\).
Optimal \(\lambda = \dfrac{a + \sqrt{a^2 + 4}}{2}\).
As \(a \to \infty\): \(M \to 1\), taking \(M\) as the bound for the normalized target. At \(a = 4\), \(M = 1.026\) and the sampler accepts 97% of proposals; the naive method accepts 0.003%.
The normalizing constant never enters the algorithm
Accept-Reject works even when \(f(x) = c \cdot f_1(x)\) with unknown \(c\).
Modified Algorithm. If \(f(x) = c f_1(x)\) and \(f_1(x) \leq M' g(x)\):
Multiply numerator and denominator by \(c\): \[\frac{f_1(y)}{M' g(y)} = \frac{c\,f_1(y)}{c M' g(y)} = \frac{f(y)}{M g(y)}, \qquad M = cM'.\]
This is the original algorithm with bound \(M = cM'\) for \(f\), so the proof already covers it and \(c\) never appears in the code.
Bayesian Application. Posterior: \(\pi(\theta \mid x) \propto f(x \mid \theta)\pi(\theta) = f_1(\theta)\).
Don’t need \(\int f(x \mid \theta)\pi(\theta)d\theta\).
Note. The acceptance rate is \(\dfrac{1}{cM'}\): still constant, but not computable, since \(c\) is the constant you avoided. The observed acceptance rate estimates it, and so estimates \(c\).
This is the property the Bayesian half of the course runs on: the Metropolis-Hastings acceptance ratio in week 10 touches the posterior only through \(f_1\), for exactly the reason above.
The theory says: if \(f \leq Mg\), accepted proposals follow \(f\) exactly. In practice you execute a recipe. Each step draws on a specific result from this lecture.
Motivation. Evaluating \(f(x)\) may be computationally expensive.
Theorem (Envelope Accept-Reject). If \(g_l(x) \leq f(x) \leq g_u(x) \leq Mg(x)\), then:
Essentially, cheap bounds \(g_l\) and \(g_u\) bracket \(f\) and decide most proposals without evaluating \(f\). Only proposals falling between the bounds require the expensive evaluation.
Expected Attempts.
On average, you draw \(M\) proposals from \(g\) for every accepted sample from \(f\).
Computational Cost. Per iteration: generate from \(g\), evaluate \(f(Y)/g(Y)\), generate a uniform.
Comparison.
| Method | Cost |
|---|---|
| Inverse | \(O(1)\) |
| Box-Muller | \(O(1)\) |
| Accept-Reject | \(O(M)\) |
Trade-off. Flexibility against efficiency.
Strengths.
Limitations.
| Result | Statement | Role |
|---|---|---|
| Correctness | Accepted draws \(\sim f\) | The method produces exact samples |
| Acceptance probability | \(P[\text{accept}] = 1/M\) | The cost: \(M\) proposals per accepted draw |
| Unnormalized targets | Only \(f_1/g\) enters | The normalizing constant never appears |
Because only the ratio \(f_1/g\) is ever evaluated, the target needs no normalizing constant, which is what makes the method reach posteriors at all.
Next week takes the two obvious complaints in turn. Adaptive rejection sampling builds the envelope for you when \(\log f\) is concave, ratio of uniforms sidesteps the envelope by moving to a bounded region in the plane, and importance sampling drops rejection altogether: keep every draw, weight it by \(f/g\), and spend the rest of the week making the variance of that estimator small.