# Importance Sampling

I want to solve the integral

$$I =\int_{0}^{3} \frac{\exp(-s)}{1+\frac {1}{s}} \text{d}s$$

using importance sampling.

I'm unsure as to how implement it.

I have sampled random variables from an exponential distribution.

$$x = -\log(1-U)\ \text{with}\ U \sim \mathcal{U}(0,1)$$

Am I right in thinking that

$$\hat{I} = \frac{1}{N}\sum f(x)/g(x)$$

is a proper importance sampling approximation, where $$f(s)=\frac{\exp(-s)}{1+\frac {1}{s}}$$

and $g$ is the pdf of the standard exponential distribution.

$$\frac{1}{N}\sum_i f(x_i)/g(x_i) \to E_g[f(x)/g(x)] = \int_0^{\infty}f(x)/g(x) g(x)dx = \int_0^{\infty}f(x) dx \neq \int_0^3 f(x) dx.$$
Instead try computing $\frac{1}{N}\sum_i f(x_i)/g(x_i)1(0 < x_i < 3)$.