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
Asked
Active
Viewed 2,978 times
0
-
I'm afraid to say that the only way to figure it out in general is to understand the math. Sometimes you can figure it out for a particular case by analogy with a similar already-worked example, but there is some risk of making a bone-head error when doing that. I've never bothered with importance sampling myself, but scanning the wikipedia article suggests its not much more complicated the the basic sampling theorem. – dmckee --- ex-moderator kitten Sep 24 '10 at 17:37
-
This code in C, for approximation one, two and three dimensional integrals using a 'crude' Monte-Carlo sampling technique is available as open source? I need to do something similar to include in an application I am developing. Thanks in advance – Mar 17 '11 at 11:14
1 Answers
0
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.

JMzance
- 1,704
- 4
- 30
- 49