A question about Metropolis-Hastings sampling
Closed this issue · 2 comments
fancyerii commented
I have a question about this line of code:
#MH ratio
self.alpha[i] = self.proposal_pdf(x_new) / self.proposal_pdf(x_curr) #q(x|x')/q(x'|x)
proposal_pdf is:
def proposal_pdf(self, x):
#q(x) = N(x; mu, Sigma)
return multivariate_normal.pdf(x, self.proposal_mu, self.proposal_sigma)
q(x|x') = proposal_pdf(x_new).
According to the book:
it seems q(x|x') = N(x; x', Sigma) = multivariate_normal.pdf(x, x_new, self.proposal_sigma)
vsmolyakov commented
Thanks! You are right, I updated the code in the following commit: 1500392
It looks like the proposal_pdf was always sampling from the same self.proposal_mu mean, I updated it so that the mean is a parameter, in other words:
q(x|x') = N(x; x', Sigma) = multivariate_normal.pdf(x_curr, x_new, self.proposal_sigma)
This resulted in a slightly higher MH acceptance ratio: 0.1674 (new) compared to 0.1586 (old).
Thanks!
vsmolyakov commented
resolved