I watched some youtube videos about the Metropolis-Hastings algorithm. They used a Gaussian as a proposal function to estimate an unknown Gaussian, or used a Gamma function as the proposal function to estimate an unknown Gamma.
I tested this with some simple MATLAB code and it didn't work.
n = 20000; x = zeros(n,1); x(1) = 0.5; for i = 1:n-1 % x_c = normrnd(x(i), 0.05); % proposal function (0.5, 0.05) x_c = gamma(x(i)); % will it works with a different distribution? if rand() < min(1, normpdf(x_c) / normpdf(x(i))) x(i+1)= x_c; else x(i+1) = x(i); end end hist(x, 100) % to get the standard Gaussian (0,1)
So I wonder when using Metropolis-Hastings algorithm to estimate an unknown distribution, should the proposal function have the same distribution?