Probabilistic-Programming-and-Bayesian-Methods-for-Hackers
Probabilistic-Programming-and-Bayesian-Methods-for-Hackers copied to clipboard
Chapter 5: Explanation for definition of @pm.potential ?
In Chapter 5, when the code is provided for inferring the true price for the showcase, the following function is defined:
@pm.potential
def error(true_price=true_price, price_estimate=price_estimate):
return pm.normal_like(true_price, price_estimate, 1 / (3e3) ** 2)
What is the role of the above definition? Where is it used? I re-read the text but failed to find an explanation for how it helps with the true price inference.
Yes, thanks for calling me out on this - I did sneak it in unfairly. I'll add a blurb about it ;)
Thanks @CamDavidsonPilon I will be giving a talk covering your book next week at a company meeting. Any chance you could clarify the specific role of that definition sometime over the next few days?
By the way, thanks for the effort you put into this, and congrats on reaching a wide audience on something as important as principled inference.
Wow that's awesome. Sure I'll write something up for you
The potential
function is an implicit part of the model (in fact, all potential
functions are implicit parts of the model: the can define relationships between the random variables). So it is used, particularly in the following relationship:
true_price = snow_blower + Toronto_trip + error
(In fact, I added some more details to this blog post on the same subject, some of which didn't get carried over to the book.)
Thus, if my prior is given by true_price
, and I observe snow_blower + Toronto_trip
(or atleast, I have beliefs about what they might be), I need a way to connect the quantities. I assume the error between the two quantities is normal (usual assumption), hence why the normal_like
is introduced: it penalizes large differences between true_price
and snow_blower + Toronto_trip
. (Why the precision, the third argument in the call, is 1 / (3e3) ** 2
, I must admit I forget. I believe it had something to do with the sum of the variances of the other pieces of the model. )
I recall building this example, and trying to get it to work, and using a potential
was the way that worked best.
Thanks - I am trying to follow but I don't quite understand it yet. I understand what a likelihood function is (for given observed data, it is a function of the distribution parameters, giving higher values to parameters that are most likely to explain the data). I also understand what a potential is in the graphical models literature (distributions factorize as products of potentials).
I looked at the specification of the PyMC function normal_like
, and it looks like you used true_price
as your observed data, and price_estimate
as the mu
in the likelihood function. Why? I understand the true_price = price_estimate + error
expression, but don't see how you make the jump to modeling this expression with the likelihood function.
I must be missing something obvious, but don't get it.
@CamDavidsonPilon (and others who may be interested). I have posted this question on Stackoverflow: Solving the Price is Right with the hope to add more light to this part of the book.
Allen Downy, of Think Bayes, used this example in his book, of which you can read online here
That may help
For those looking at this years later, I believe this cross-validated answer explains the core concepts with an updated coding of the model.