Rejection sampling is a technique used to generate random samples from a target probability distribution ( f(x) ) by sampling from a simpler proposal distribution ( g(x) ) and rejecting samples that do not meet specific criteria. It is particularly useful when direct sampling from ( f(x) ) is difficult, but ( g(x) ) is easy to sample from and closely approximates ( f(x) ).
How Rejection Sampling Works
-
Proposal Distribution: Choose a proposal distribution ( g(x) ) such that:
- ( g(x) ) is easy to sample from.
- There exists a constant ( M ) where ( M \cdot g(x) \geq f(x) ) for all ( x ).
-
Sampling Steps:
- Generate a candidate ( X \sim g(x) ).
- Generate ( U \sim \text{Uniform}(0, 1) ).
- Accept ( X ) if ( U \leq \frac{f(X)}{M \cdot g(X)} ); otherwise, reject and repeat.
Proof of Correctness
To prove that accepted samples follow ( f(x) ), we show that the conditional probability ( P(X \leq y \mid \text{accepted}) ) equals the cumulative distribution function (CDF) of ( f(x) ).
-
Joint Probability:
The probability of accepting a sample ( X \leq y ) is:
[
P(X \leq y, \text{accepted}) = \int_{-\infty}^y \frac{f(x)}{M \cdot g(x)} \cdot g(x) , dx = \frac{1}{M} \int_{-\infty}^y f(x) , dx.
]
-
Total Acceptance Probability:
The unconditional probability of acceptance is:
[
P(\text{accepted}) = \frac{1}{M} \int_{-\infty}^\infty f(x) , dx = \frac{1}{M} \quad (\text{since } f(x) \text{ is a valid PDF}).
]
-
Conditional Probability:
Using Bayes' rule:
[
P(X \leq y \mid \text{accepted}) = \frac{P(X \leq y, \text{accepted})}{P(\text{accepted})} = \frac{\frac{1}{M} \int_{-\infty}^y f(x) , dx}{\frac{1}{M}} = \int_{-\infty}^y f(x) , dx.
]
This is exactly the CDF of ( f(x) ), proving that accepted samples follow the target distribution[5][8].
Key Properties
- Efficiency: The acceptance probability is ( \frac{1}{M} ), so smaller ( M ) (closer ( g(x) ) is to ( f(x) )) improves efficiency[2][6].
- Requirements:
- ( g(x) ) must dominate ( f(x) ) (i.e., ( M \cdot g(x) \geq f(x) )).
- The support of ( g(x) ) must include the support of ( f(x) )[1][2].
Example
Suppose ( f(x) ) is a complex PDF, and ( g(x) ) is a uniform distribution over ([0, 1]). If ( f(x) \leq 2 ) for all ( x \in [0, 1] ), set ( M = 2 ). Sampling proceeds as follows:
- Draw ( X \sim \text{Uniform}(0, 1) ).
- Draw ( U \sim \text{Uniform}(0, 1) ).
- Accept ( X ) if ( U \leq \frac{f(X)}{2 \cdot 1} ); otherwise, reject[7].
Applications
- Statistical Computing: Generate samples from intractable distributions[2][5].
- Reinforcement Learning: Filter model outputs using reward models (e.g., RLHF in language models)[4].
By following these steps, rejection sampling ensures that accepted samples are distributed according to ( f(x) ), even when direct sampling is impractical.