Mehmet Emre Tiryaki
Back to Notes

Sampling Methods

Inverse Transformation Sampling

Sample from DD with density f(x)f(x) and CDF F(x)F(x), given U∼Unif(0,1)U \sim \mathrm{Unif}(0,1). Find TT such that T(U)=X∼DT(U) = X \sim D.

P(X≤x)=P(T(U)≤x)=P(U≤T−1(x))=T−1(x)\mathbb{P}(X \le x) = \mathbb{P}(T(U) \le x) = \mathbb{P}(U \le T^{-1}(x)) = T^{-1}(x)

So F(x)=T−1(x)F(x) = T^{-1}(x), i.e. T=F−1T = F^{-1}. Sample from UU and plug into F−1F^{-1}: the result is a sample from DD. If FF is not invertible, use the generalized inverse F←(u)=inf⁡{x:F(x)≥u}F^{\leftarrow}(u) = \inf\{x : F(x) \ge u\} (see random variables).

Rejection Sampling

Sample from PP with density f(x)/Zf(x)/Z. Choose a proposal GG with density g(x)g(x) such that

  1. the support of GG contains the support of PP,
  2. GG is possible to sample,

and choose MM such that f(x)≤Mg(x)f(x) \le M g(x) for all xx.

Algorithm Sample ss from GG, and accept ss with probability f(s)Mg(s)\frac{f(s)}{M g(s)}.

P(s∣Accept)=P(Accept∣s) P(s)P(Accept)=f(s)Mg(s) g(s)∫g(s)f(s)Mg(s) ds=f(s)/M1M∫f(s) ds=f(s)Z=density of PP(s | \text{Accept}) = \frac{P(\text{Accept} | s)\, P(s)}{P(\text{Accept})} = \frac{\frac{f(s)}{M g(s)}\, g(s)}{\int g(s) \frac{f(s)}{M g(s)}\, ds} = \frac{f(s)/M}{\frac{1}{M}\int f(s)\, ds} = \frac{f(s)}{Z} = \text{density of } P