`MissingInputError` when sampling data

Hi all, I am new to Bayesian statistics, and I am trying to run the following code from the Bayesian Modeling and Computation in Python book (which was using PyMC3):

with pm.Model() as model_0:
    θ1 = pm.Normal("θ1", 0, 1, initval=0.1)
    θ2 = pm.Uniform("θ2", -θ1, θ1)
    idata_0 = pm.sample(return_inferencedata=True)

However I got the following error message

MissingInputError: Input 0 (θ1) of the graph (indices start from 0), used to compute Neg(θ1), was not provided and not given a value. Use the PyTensor flag exception_verbosity='high', for more information on this error.

I wonder why do I get this error, and how should I fix it in PyMC5? Thank you!

None of those examples seem to work, and I’m not sure what the intention original was. @aloctavodia @RavinKumar @junpenglao ?

That’s true, and that’s something making me frustrated :frowning: I am trying to learn more about PyMC or Tensorflow Probability, but everything source (this book, and the Bayesian Methods for Hackers book I found are outdated, even many official examples are not working (at least for the last time I checked. Apology if they have been updated) :cry: Wonder if you or anyone esle have suggestions about how should I learn more about PyMC and PPL?

@cluhmannThe intention of that example was to generate divergences using a very simple model. Not sure why it does not run with PyMC 5.x, it did with PyMC 3.x

@Yijun_X Sorry for the frustration, my recommendation when reading books with code is to stick to the version used in the books, and only switch to a new version once you understand the material. Otherwise, the code can easily become an obstacle instead of an enabler.

We, the authors of Bayesian Modeling and Computation in Python, are thinking about a second edition with PyMC 5, but it will take a year or more to be published.

The third edition of Bayesian analysis with Python will be ready in one or two months. https://www.amazon.com/Bayesian-Analysis-Python-Practical-probabilistic/dp/1805127160 It uses PyMC 5

If you find an example in the documentation that is not running with the last version of PyMC, please fill an issue ticket so we can resolve it.

3 Likes

Thanks for the advice! I will start with PyMC3 when reading that book, and learn more about pymc5 later. And I am looking forward to the new book!

Also, just in case you know Spanish this may help https://gmp.net.ar/modelado_bayesiano/

1 Like

No I don’t know Spanish, but google can translate it pretty well. Will take a look at this. Thank you!

That looks like a bug

Should be fixed by Avoid inplace mutation in `replace_rvs_by_values` by ricardoV94 · Pull Request #7055 · pymc-devs/pymc · GitHub

1 Like

Thank you @ricardoV94 ! Maybe another rookie question: I wonder how long would this fix take to be included in the next release? Wonder where can I find doc about the development process? Thank you!

You can check Releases · pymc-devs/pymc · GitHub

Github allows you to follow releases of projects, so that you get an email whenever there is a release: About notifications - GitHub Docs

1 Like

@Yijun_X Here you will find the code for the first 4 chapters updated to PyMC 5.x BookCode_Edition1/notebooks_updated at main · BayesianModelingandComputationInPython/BookCode_Edition1 · GitHub
We will try to add more chapters soon. Also, notice that TF/TFP code is commented out and it will get updated eventually.

3 Likes