I'm trying to use Metropolis-Hastings to sample from a distribution that's very close to
$$\exp(-|x|/\ell)$$
and I'm finding that the method is undersampling near the origin, where there's a kink in the distribution function. I've attached an example figure. Is there a smoothness requirement to Metropolis-Hastings that isn't discussed that often? If so, is there a good workaround for this or alternative algorithm?
Edit: Here is a minimal working example, along with the output.
def exp_func(x, ell):
return np.exp(-np.abs(x)/ell)
ell = 2.
sigma = 1.
n_samples = 5000
sequence = np.zeros(n_samples)
theta_t = np.random.random()
idx = 0
while idx < n_samples:
theta_star = np.random.normal(loc=theta_t, scale=sigma)
alpha = min(exp_func(theta_star, ell)/exp_func(theta_t, ell), 1.)
u = np.random.random()
if u < alpha:
theta_t = theta_star
sequence[idx] = theta_star
idx += 1
and what it produces:
theta_t
whenu > alpha
as I do in my R code (last line)? $\endgroup$ – Xi'an Jun 10 '20 at 6:03theta_t
changes is ifu < alpha
. It's worth noting that I tested this with anexp(-x**4/sigma**4)
type distribution and I don't get this undersampling near the origin. $\endgroup$ – webb Jun 10 '20 at 17:22u < alpha
then I changetheta_t
, otherwise it stays the same, i.e. whenu > alpha
. $\endgroup$ – webb Jun 10 '20 at 21:49