0

我在尝试运行有关 tensorflow 概率的贝叶斯逻辑回归示例时遇到问题,如图所示An Introduction to probabilistic Programming,现在可在 TensorFlow Probability中找到。

如果我只是在网站上运行代码,我会收到以下错误:

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'

然后,当我指定 num_adaptation_steps=5 时,出现以下错误:

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) ]]

我不知道我做错了什么,任何帮助将不胜感激。谢谢!!

4

1 回答 1

1

当前 Colab 中第 2 章的挑战者代码应该可以工作:

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)

我刚刚注意到该章中较早的 HMC 示例缺少 num_adaptation_steps,所以我会尽快进行 PR 来解决这个问题。或者也可以随意这样做。

谢谢迈克

于 2019-04-22T17:31:19.160 回答