CamDavidsonPilon / Probabilistic-Programming-and-Bayesian-Methods-for-Hackers

aka "Bayesian Methods for Hackers": An introduction to Bayesian methods + probabilistic programming with a computation/understanding-first, mathematics-second point of view. All in pure Python ;)
http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
MIT License
26.67k stars 7.87k forks source link

Instantiating MCMC in PyMC examples #104

Open fonnesbeck opened 11 years ago

fonnesbeck commented 11 years ago

Having a peek through Chapter 3, I notice that you instantiate your MCMC objects in a two-step process:

model = Model([var1, var2, var3])
sampler = MCMC(Model)

There is really no need to explicitly create a Model object at all -- MCMC will do this for you if you pass it the variables:

sampler = MCMC([var1, var2, var3])

In fact, typically I just pass a call to vars (or locals) which MCMC will sift through to look for PyMC objects in the local namespace:

sampler = MCMC(vars())

This is particularly useful if you encapsulate your model in a function that returns vars or locals.

In any case, its just one fewer step in the PyMC modeling process to have to think about.

CamDavidsonPilon commented 11 years ago

Hey @fonnesbeck! I think my original intention was to use the draw_from_prior method for something (but, it's in the MCMC class anyways), and have since changed my mind. It's an artifact now. I'll remove it when I touch this chapter (and other chapters) again.