【问题标题】:Bayesian Logistic Regression Using Tensorflow Probability使用 TensorFlow 概率的贝叶斯逻辑回归
【发布时间】:2019-04-22 02:46:11
【问题描述】:

我在尝试对 tensorflow 概率运行贝叶斯逻辑回归示例时遇到问题,如 An introduction to probabilistic programming, now available in 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) ]]

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

【问题讨论】:

    标签: python tensorflow tensorflow-probability hierarchical-bayesian


    【解决方案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 来解决这个问题。或者也可以随意这样做。

    谢谢 迈克

    【讨论】:

    • 嗨,迈克,感谢您的帮助。进行上述更改并使用 colab 中的代码后,我仍然收到相同的错误:FailedPreconditionError(请参阅上面的回溯):从容器读取资源变量 step_size_hmc 时出错:localhost。这可能意味着该变量未初始化。未找到:容器 localhost 不存在。
    猜你喜欢
    • 2019-04-19
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 2013-06-26
    • 2019-04-04
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多