开发者

Importance sampling in monte carlo method (in C)

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 n开发者_JS百科one seem particularly clear. How would I implement something like this? Many Thanks. Jack


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜