首页 > 解决方案 > 张量流概率中非负参数的负值

问题描述

我正在尝试在张量流概率中拟合一个简单的 Dirichlet-Multinomial 模型。浓度参数是gamma并且我已经在它们上放置了 Gamma(1,1) 先验分布。这是模型,其中 S 是类别数,N 是样本数:

def dirichlet_model(S, N):
    gamma = ed.Gamma(tf.ones(S)*1.0, tf.ones(S)*1.0, name='gamma')
    y = ed.DirichletMultinomial(total_count=500., concentration=gamma, sample_shape=(N), name='y')
    return y

log_joint = ed.make_log_joint_fn(dirichlet_model)

但是,当我尝试使用 HMC 从中采样时,接受率为零,并且初始抽签gamma包含负值。难道我做错了什么?不应该自动拒绝对浓度参数的否定建议吗?在我的采样代码下面:

def target_log_prob_fn(gamma):
  """Unnormalized target density as a function of states."""
  return log_joint(
    S=S, N=N,
    gamma=gamma,
    y=y_new)

num_results = 5000
num_burnin_steps = 3000

states, kernel_results = tfp.mcmc.sample_chain(
  num_results=num_results,
  num_burnin_steps=num_burnin_steps,
  current_state=[
    tf.ones([5], name='init_gamma')*5,
],
kernel=tfp.mcmc.HamiltonianMonteCarlo(
    target_log_prob_fn=target_log_prob_fn,
    step_size=0.4,
    num_leapfrog_steps=3))

gamma = states

with tf.Session() as sess:
  [
    gamma_,
    is_accepted_,
  ] = sess.run([
    gamma,
    kernel_results.is_accepted,
  ])

num_accepted = np.sum(is_accepted_)
print('Acceptance rate: {}'.format(num_accepted / num_results))

标签: python-3.xtensorflow-probability

解决方案


尝试减小步长以提高接受率。HMC 的最佳接受率约为 0.651 ( https://arxiv.org/abs/1001.4460 )。不知道为什么你会看到负值。也许浮点误差接近零?你能发布一些你的跑步日志吗?


推荐阅读