0

I am having issues trying to run the Bayesian logistic regression example on tensorflow probability, as shown An introduction to probabilistic programming, now available in TensorFlow Probability.

If I just run the code on the site I get the following error:

Traceback (most recent call last):
  File "<input>", line 75, in <module>
TypeError: make_simple_step_size_update_policy() missing 1 required positional argument: 'num_adaptation_steps'

Then when I specify the num_adaptation_steps=5 I get the following error:

FailedPreconditionError (see above for traceback): Error while reading resource variable step_size_hmc from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/step_size_hmc)
     [[node mcmc_sample_chain/transformed_kernel_bootstrap_results/Identity_2/ReadVariableOp (defined at /home/abeer/PycharmProjects/TensorFlowProbability/venv/lib/python3.6/site-packages/tensorflow_probability/python/mcmc/hmc.py:127) ]]

I don't know what I am doing wrong and any help would be greatly appreciated. Thanks!!

giser_yugang
  • 6,058
  • 4
  • 21
  • 44
Abeer Ali
  • 11
  • 3

1 Answers1

1

The Challenger code in the current Colab for chapter 2 should work:

https://colab.sandbox.google.com/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter2_MorePyMC/Ch2_MorePyMC_TFP.ipynb#scrollTo=oHU-MbPxs8iL

hmc=tfp.mcmc.TransformedTransitionKernel(
inner_kernel=tfp.mcmc.HamiltonianMonteCarlo(
    target_log_prob_fn=unnormalized_posterior_log_prob,
    num_leapfrog_steps=40,
    step_size=step_size,
    step_size_update_fn=tfp.mcmc.make_simple_step_size_update_policy(
        num_adaptation_steps=int(burnin * 0.8)),
    state_gradients_are_stopped=True),
bijector=unconstraining_bijectors)

I just noticed that the earlier HMC examples in that Chapter are lacking the num_adaptation_steps, so I'll do a PR soon to fix that. Or feel free to do so as well.

Thanks mike

Mike Shwe
  • 11
  • 1
  • Hi Mike, Thanks for your help. after making the above change, and using code from the colab, I am still getting the same error: FailedPreconditionError (see above for traceback): Error while reading resource variable step_size_hmc from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. – Abeer Ali Apr 23 '19 at 22:26