Specify a First Sample Value/Alternative to PyMC `testval`

Hi there, @jvans and I are attempting to replicate the Challenger Shuttle example from Chapter 2 of Bayesian Methods for Hackers (http://nbviewer.jupyter.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter2_MorePyMC/Ch2_MorePyMC_PyMC3.ipynb#Example:-Challenger-Space-Shuttle-Disaster-).

This model involves using the logistic function to map the space of temperatures between 0 and 1. A side effect of using this function is that it is only between 0 and 1 in a narrow range. Outside of this range, it is 0 or 1, and if it is 0 the model cannot train. It is guaranteed to return 0.5 for an input \beta and \alpha of 0. From the Bayesian Methods for Hackers book:

  beta = pm.Normal("beta", mu=0, tau=0.001, testval=0)
  alpha = pm.Normal("alpha", mu=0, tau=0.001, testval=0)
  p = pm.Deterministic("p", 1.0/(1. + tt.exp(beta*temperature + alpha)))

Notice in the above code we had to set the values of beta and alpha to 0. The reason for this is that if beta and alpha are very large, they make p equal to 1 or 0. Unfortunately, pm.Bernoulli does not like probabilities of exactly 0 or 1, though they are mathematically well-defined probabilities. So by setting the coefficient values to 0, we set the variable p to be a reasonable starting value.

The testval argument specifies that the first sample for beta and alpha is 0. We’re wondering if there is an equivalent in Pyro or a workaround (maybe some way to conditional the sample if step == 0?)

Cheers.

1 Like

Can you paste what you’ve tried in Pyro? It’s not clear whether you’re using SVI or HMC or another type of inference, and our initialization methods depend on inference method.

This is related to a question I posted recently:

https://forum.pyro.ai/t/mcmc-a-way-to-specify-starting-points-to-sample/264