1

So I'm trying to understand importance sampling. So far I have the algorithm implemented like this:

# Student's T target distribution for sake of example
target = stats.t(5, loc=5, scale=10)

particle_count = 100000
# Normal proposal distribution
proposal_dist = stats.norm(loc=0, scale=25)
# Take samples from proposal distribution
samples = proposal_dist.rvs(size=particle_count)
# Set weights according to ratio between target and proposal distributions
weights = target.pdf(samples) / proposal_dist.pdf(samples)
# Normalize
norm_weights = weights / np.sum(weights)

This gives the weights and calculating the expectation this way:

np.sum(norm_weights * samples)

gives around 5 as expected.

My question is how to generate "posterior" samples from the target distribution given the proposal distribution and the calculated weights.

eadains
  • 21
  • 1

1 Answers1

1

Importance sampling helps you estimate quantities for a target distribution (that you cannot generate samples from) using a proposal distribution (that you can generate samples from). Please see this great post by Xi'an on importance sampling.

To actually generate samples from the target distribution (or the posterior in a Bayesian analysis, where the posterior would now be your target distribution), we would need to use a more sophisticated algorithm like Metropolis-Hastings.

asifzuba
  • 323
  • 1
  • 6