Importance sampling Matlab demo

Importance sampling is related to rejection sampling, which I looked at in the last post. Here is a short demo.

A problem of rejection sampling is that many samples could be evaluated in regions of low probability mass. This then lead to a high rate of attrition, with many samples being rejected. In importance sampling, this seems like less of an issue in terms of ending up with a large number of samples for an accurate representation of the distribution. Although the same basic problem is there in that the probability is being evaluated for many points in parameter space with very low or zero probability.

rejection sampling demo

So let’s do the same thing from the last post and use this to do parameter estimation.

Which results in this

importance sampling param est

Here is a nice little figure I found that helped with the intuition.

importance-sampling-schematic

2 thoughts on “Importance sampling Matlab demo

  1. Reply

    […] far we’ve had a look at rejection sampling and importance sampling. Here we take a quick look at slice sampling, although rather than implementing it ourselves, we […]

  2. Reply
    John - 2016/10/05

    In your first code you don’t need to do ‘proposal = 1/N;’ because you normalise the weights anyway.

Leave a Reply