# Generating samples from target distribution after importance sampling

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.

• make the target the unnormalized posterior (the likelihood times the prior). Commented Aug 11, 2019 at 2:20