Hello! For benchmarking purposes, is there a way to use MCMC such that we specify the number of MCMC iterations, rather than the number of desired accepted samples? I’ve tried setting the target_accept_prob
field of the NUTS
kernel to 0
so that all samples are accepted, but this doesn’t seem to have the right effect.
Here is what i have at the moment:
import pyro
import pyro.poutine as poutine
import pyro.distributions as dist
import torch as torch
from pyro.infer import MCMC, NUTS
def linRegr(x):
mu = pyro.sample('mu', dist.Normal(0, 3))
c = pyro.sample('c', dist.Normal(0, 5))
σ = pyro.sample('σ', dist.Uniform(1, 3))
y = pyro.sample('y', dist.Normal(mu * x + c, σ))
return y
def mhLinRegrXYS(n_samples):
xs = torch.tensor(list(range(0, 100)))
ys = torch.tensor(list(map (lambda x: (x*3) + 4, xs)))
conditioned_model = poutine.condition(linRegr, data={'y': torch.tensor(ys)})
nuts_kernel = NUTS(conditioned_model, target_accept_prob=0)
mcmc = MCMC(
nuts_kernel,
num_samples=n_samples,
warmup_steps=0,
)
mcmc.run(xs)
samples = mcmc.get_samples()
Thanks a lot.