tensorflow-probability - TransformedTransitionKernel 无法在 sample_chain 中应用逆双射器
问题描述
我正在尝试为一些时间序列数据运行一个相当简单的 MCMC 示例。我相信我包含了所有必需的参数,但我仍然遇到错误。
库版本:
tensorflow==1.14.0
tensorflow-proability==0.7.0
我尝试回滚到 tfp 0.6.0 并出现matmul
错误。我尝试每晚推进到 tf 并得到与以下相同的错误。
编码
import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions
tf.enable_eager_execution()
rate_prior = tfd.Exponential(1./mean_users)
users_before = [...] # bogus positive ints
users_after = [...] # bogus positive ints
def unnormalized_log_prob(rate_before, rate_after):
users_before_prior = tfd.Poisson(rate_before)
users_after_prior = tfd.Poisson(rate_after)
return (rate_prior.log_prob(rate_before)
+ rate_prior.log_prob(rate_after)
+ tf.reduce_sum(users_before_prior.log_prob(users_before))
+ tf.reduce_sum(users_after_prior.log_prob(users_after))
)
bijectors = [tfp.bijectors.Exp, tfp.bijectors.Exp]
hmc = tfp.mcmc.TransformedTransitionKernel(
tfp.mcmc.HamiltonianMonteCarlo(
target_log_prob_fn=unnormalized_log_prob,
step_size=10.,
num_leapfrog_steps=3,
),
bijectors
)
states = tfp.mcmc.sample_chain(
num_results=10000,
current_state=[tf.ones(2) * mean_users],
kernel=hmc,
trace_fn=None
)
这将返回一个错误。
.../tensorflow_probability/python/mcmc/transformed_kernel.py in <listcomp>(.0)
71 def fn(state_parts):
72 return [b.inverse(sp)
---> 73 for b, sp in zip(bijector, state_parts)]
74 return fn
75
TypeError: inverse() missing 1 required positional argument: 'y'`
解决方案
尝试
bijectors = [tfp.bijectors.Exp(), tfp.bijectors.Exp()]
]
推荐阅读
- python - model.fit_generator 中的 class_weight 参数如何与数据生成器一起使用?
- spring - 启动时的 Spring JDBC 连接没有问题,但是当插入或更新发生问题时
- jquery - 为什么我无法安装和使用 Bootstrap Multiselect?
- apache-spark - Pyspark 收集/分组嵌套数据
- reactjs - 未选中框时更新状态
- python - Pandas DataFrame:如何删除列并对选定列执行计算
- c++ - 无法弄清楚为什么没有在 SDL 中绘制线
- javascript - 如何使用地图功能(ReactJS)限制购物车中的项目
- solr - solr:edismax tie 参数未按描述工作
- java - Spring-5 ResponseEntity(不存在创建者,如默认构造)