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[0], 1.0 / data_std[0] ** 2)
prize_2 = pm.Normal("second_prize", data_mu[1], 1.0 / data_std[1] ** 2)

price_estimate = prize_1 + prize_2

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:

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

  • 1
    $\begingroup$ My implementation of Gelman's rat tumor example uses a similar methodology. See here. $\endgroup$ – Demetri Pananos Jan 26 '19 at 23:25
  • $\begingroup$ 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[0] and ab[1], are referenced throughout the rest of the model, without the immediate reason for pm.Potential() being seen. $\endgroup$ – Coolio2654 Jan 27 '19 at 1:11
  • $\begingroup$ 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. $\endgroup$ – Demetri Pananos Jan 28 '19 at 2:38

The book has been ported to PyMC3. The updated example of the Price is Right model can be found here: https://render.githubusercontent.com/view/ipynb?commit=be1faee30c4eb6bef4c049b6e11499db144c5697&enc_url=68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f43616d4461766964736f6e50696c6f6e2f50726f626162696c69737469632d50726f6772616d6d696e672d616e642d426179657369616e2d4d6574686f64732d666f722d4861636b6572732f626531666165653330633465623662656634633034396236653131343939646231343463353639372f43686170746572355f4c6f737346756e6374696f6e732f4368355f4c6f737346756e6374696f6e735f50794d43332e6970796e62&nwo=CamDavidsonPilon%2FProbabilistic-Programming-and-Bayesian-Methods-for-Hackers&path=Chapter5_LossFunctions%2FCh5_LossFunctions_PyMC3.ipynb&repository_id=7607075&repository_type=Repository#Example:-Optimizing-for-the-Showcase-on-The-Price-is-Right

  • $\begingroup$ 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. $\endgroup$ – Coolio2654 Jan 30 '19 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.