Monte-Carlo estimation and importance sampling

This notebook contains a python adaptation of the importance saimpling example in [1]. The objective is to estimate the following expectation: $$ E_{p(\mathcal X)}[f(\mathcal X)], $$ where $p(\mathcal X)$ is the uniform distribution between 0 and 10 and $f$ is defined as follows: $$ f(x) = 10 * \exp(-2 | x - 5|). $$ The true value of the expectation is around 10, but we will approximate it using Monte-Carlo estimation and importance sampling.

[1] https://dept.stat.lsa.umich.edu/~jasoneg/Stat406/lab7.pdf

Monte-Carlo estimation

We first start with a simple Monte-Carlo estimationn.

Importance sampling

We now estimate the expectation using importance sampling.

Variance comparison

To compare the two estimation methods (with and without importance sampling), we can compare the mean and variance of these estimators. In this setting, one "experiment" in a MC estimation with a fixed number of samples. We run the experiment many times, and then compute the mean and variance of resulting estimations.

We can observe that the variance is lower with IS!

We can redo the experiment with a "bad" proposal distribution. In this case, the variance is worse for IS.