views:

41

answers:

1

Hiya, Ive written a code which successfully approximation one, two and three dimensional integrals using a 'crude' Monte-Carlo sampling technique. I would now like to improve this by using 'importance sampling', as apparently this can reduce variance. I have read a few web pages about this but none seem particularly clear. How would I implement something like this? Many Thanks. Jack

A: 

Right, I found my mistake. I wasn't using the inverse integral of the PDF to calculate the 'weight' of each point. For anyone whos's interested my conditional loop read like:

for (i = 0; i <= N; i++) {
    X = (double) rand() / (double) RAND_MAX;
   integrand = function(inverse(X)) / PDF(inverse(X));
   sum = sum + integrand;
   sum2 = sum2 + (integrand * integrand);
}
average = sum / N;
average2 = sum2 / N;

Where PDF is my probability density function, inverse is the inverse integral of the PDF. and average and average2 represent and respectively.

Jack Medley