# PyMC3: up-to-date implementation of Price is Right example?

So, getting into PyMC3 a lot more and working through examples, I found I cannot implement in an up-to-date form an example from Cameron Davidson-Pilon's Bayesian Methods for Hackers, specifically the Price is Right example, in the library's current version.

The model starts on page 139, and the crux of it is to calculate how one's prior changes after being modified by a summation of two previous priors, under normality assumptions. That is as much of the model's logic as I was able to deduce, and was hoping building it and tinkering would explain the rest to me.

The code he uses is

import pymc as pm

data_mu = [3e3, 12e3]
data_std = [5e2, 3e3]
mu_prior = 35e3
std_prior =  75e2

true_price = pm.Normal("true_price", mu_prior, 1.0 / std_prior ** 2)

prize_1 = pm.Normal("first_prize", data_mu, 1.0 / data_std ** 2)
prize_2 = pm.Normal("second_prize", data_mu, 1.0 / data_std ** 2)

price_estimate = prize_1 + prize_2

@pm.potential
def error(true_price=true_price, price_estimate=price_estimate):
return pm.normal_like(true_price, price_estimate, 1 / (3e3) ** 2)

mcmc = pm.MCMC([true_price, prize_1, prize_2, price_estimate, error])
mcmc.sample(50000, 10000)

price_trace = mcmc.trace("true_price")[:]


The thing is, pm.potential is deprecated now, and sampling directly through pm.MCMC is discouraged as well, in lieu of

with pm.Model() as model:
...
...
pm.sample()


I would extremely appreciate anyone helping me understand this model, and how a similar one would be built under modern PyMC3.

• My implementation of Gelman's rat tumor example uses a similar methodology. See here. – Demetri Pananos Jan 26 '19 at 23:25
• Thank you for the link, it is not only interesting but also concise in its explanations. Why did you transform the joint prior in the way you did, first by defining a function for it and then by feeding that into pm.Potential('p(a, b)', logp_ab(ab))? The regular priors, ab and ab, are referenced throughout the rest of the model, without the immediate reason for pm.Potential() being seen. – Coolio2654 Jan 27 '19 at 1:11
• I transformed the prior at the suggestion of one of the maintainers. I think it was the preferable way to define a prior which was not composed of standard distributions. – Demetri Pananos Jan 28 '19 at 2:38

• Thanks! I must to remember in the future to check for authors open-sourcing and updating their coding books. The link perfectly answers my question, so thank you, but since you are here now, would you be willing to elaborate on Demetri Pananos's comment ^^; ? In his link, why would he define his joint prior in a new function, and then plug that it into pm.Potential()? At any rate, thanks for your help. – Coolio2654 Jan 30 '19 at 0:34