# Monte Carlo Integration - Importance Sampling

1. Dec 9, 2009

### trelek2

Hi!

I'm trying to write an algorithm that performes Importance Sampling Monte Carlo integration.

I found some info about it, but I have trouble understanding how it actually can be implemented.

Let f(x) be the function we want to integrate and p(x) the non-uniform probability distribution function which is normalized and is in the same shape as f(x). p(x) returns values in the range of the interval we want to integrate. The monte carlo importance sampling formula is the following:
$$<f>=\int_{0}^{1}f(x)dx= \int_{0}^{1}p(x) \frac{f(x)}{p(x)}dx$$
So I thought that the implementation is the following
$$<f>= \frac{1}{N} \sum_{i=1}^{N} \frac{f(x _{i} )}{p(x _{i} )}$$
and the estimated error will be given by:
$$( \frac{1}{N} \sum_{i=1}^{N} \frac{f(x _{i} )*(f(x _{i} )}{p(x _{i} )}) -<f> ^{2}$$

The problem is that this works only for integrals in the range 0 to 1.
What should I do if I want to integrate over the range from a to b?

And how are these formulas modified when dealing with a multidimentional integral. If my understanding of importance sampling is already wrong please correct me!

2. Dec 10, 2009

### mathman

The simplest method is simply to scale (assuming a and b finite) a<x<b.
Let y = (x-a)/(b-a)

Your understanding is correct as far as it goes. For multidimensional integrals, it is easier to do the integration one dimension at a time.