PRML book sampling (chapter 11) 開頭把動機描述得很好, 也引用來當這篇文章的前言.
在用 machine learning 很多時候會遇到需要計算某個 function $f(x)$ 的期望值, 當 $x$ follow 某個 distribution $p(x)$ 的情況, i.e. 需計算
例如 EM algorithm 會需要計算 $\mathbb{E}_{p(z|x)}[f(x,z)]$, 參考 ref 的式 (23), (28)
又或者我們要做 Bayesian 的 prediction 時, 參考 ref 的式 (2)
這些情況大部分都無法有 analytical form. 不過如果我們能從給定的 distribution $p(x)$ 取 $L$ 個 sample 的話, 式 (1) 就能如下逼近
$$\begin{align} \mathbb{E}_p[f] \approx \hat f:= \frac{1}{L}\sum_{l=1}^L f(x_l) \end{align}$$