Hi @robertness
I have been going through the intro_to_generative_ML_with_Pyro.ipynb, and when I got to this code block:
from pyro.infer import NUTS, MCMC, EmpiricalMarginal
guess_prior = torch.tensor(13.)
nuts_kernel = NUTS(conditioned_scale, adapt_step_size=True)
posterior = MCMC(nuts_kernel,
num_samples=1000,
warmup_steps=300).run(guess_prior)
marginal = EmpiricalMarginal(posterior, "weight")
plt.hist([marginal().item() for _ in range(1000)],)
plt.title("P(weight | measurement = 14)")
plt.xlabel("Weight")
plt.ylabel("#")
print(posterior)
I got the following error:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-16-4bbde7897d55> in <module>
----> 1 marginal = EmpiricalMarginal(posterior, "weight")
2
3 plt.hist([marginal().item() for _ in range(1000)],)
4 plt.title("P(weight | measurement = 14)")
5 plt.xlabel("Weight")
~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/pyro/infer/abstract_infer.py in __init__(self, trace_posterior, sites, validate_args)
30 def __init__(self, trace_posterior, sites=None, validate_args=None):
31 assert isinstance(trace_posterior, TracePosterior), \
---> 32 "trace_dist must be trace posterior distribution object"
33 if sites is None:
34 sites = "_RETURN"
AssertionError: trace_dist must be trace posterior distribution object
I believe part of the problem is this line:
posterior = MCMC(nuts_kernel,
num_samples=1000,
warmup_steps=300).run(guess_prior)
because MCMC().run() does not appear to return anything, whereas the EmpiricalMarginal() is expecting an instance of TracePosterior.
Please advise.
Sincerely,
Jeremy
Hi @robertness
I have been going through the intro_to_generative_ML_with_Pyro.ipynb, and when I got to this code block:
I got the following error:
I believe part of the problem is this line:
because
MCMC().run()does not appear to return anything, whereas theEmpiricalMarginal()is expecting an instance ofTracePosterior.Please advise.
Sincerely,
Jeremy