Probabilistic-Programming-and-Bayesian-Methods-for-Hackers icon indicating copy to clipboard operation
Probabilistic-Programming-and-Bayesian-Methods-for-Hackers copied to clipboard

Chapter 5: Explanation for definition of @pm.potential ?

Open amelio-vazquez-reina opened this issue 10 years ago • 8 comments

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.

amelio-vazquez-reina avatar Mar 19 '14 02:03 amelio-vazquez-reina

Yes, thanks for calling me out on this - I did sneak it in unfairly. I'll add a blurb about it ;)

CamDavidsonPilon avatar Mar 19 '14 02:03 CamDavidsonPilon

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.

amelio-vazquez-reina avatar Mar 21 '14 19:03 amelio-vazquez-reina

Wow that's awesome. Sure I'll write something up for you

CamDavidsonPilon avatar Mar 21 '14 19:03 CamDavidsonPilon

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.

CamDavidsonPilon avatar Mar 21 '14 19:03 CamDavidsonPilon

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.

amelio-vazquez-reina avatar Mar 23 '14 16:03 amelio-vazquez-reina

@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.

amelio-vazquez-reina avatar Apr 19 '14 21:04 amelio-vazquez-reina

Allen Downy, of Think Bayes, used this example in his book, of which you can read online here

That may help

CamDavidsonPilon avatar Apr 23 '14 03:04 CamDavidsonPilon

For those looking at this years later, I believe this cross-validated answer explains the core concepts with an updated coding of the model.

michael-ziedalski avatar Jan 26 '19 23:01 michael-ziedalski