Importance sampling (source code)

= Importance sampling
{wiki}

To estimate $\mathbb E_f[g(X)]$, sample $Y_1,\ldots,Y_m$ independently from a reference density $h$ whose support covers that of $gf$, and use
$$
\frac1m\sum_{i=1}^m g(Y_i)\frac{f(Y_i)}{h(Y_i)}.
$$
The summands have expectation $\int g(x)f(x)\,dx$, and the <strong law of large numbers> gives almost-sure convergence under integrability.