Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Monte Carlo Integration - Importance Sampling

  1. Dec 9, 2009 #1

    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:
    [tex] <f>=\int_{0}^{1}f(x)dx= \int_{0}^{1}p(x) \frac{f(x)}{p(x)}dx [/tex]
    So I thought that the implementation is the following
    [tex]<f>= \frac{1}{N} \sum_{i=1}^{N} \frac{f(x _{i} )}{p(x _{i} )} [/tex]
    and the estimated error will be given by:
    [tex] ( \frac{1}{N} \sum_{i=1}^{N} \frac{f(x _{i} )*(f(x _{i} )}{p(x _{i} )}) -<f> ^{2}[/tex]

    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. jcsd
  3. Dec 10, 2009 #2


    User Avatar
    Science Advisor

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook