张量流概率中非负参数的负值
Negative values for a non-negative parameter in tensorflow probablity
我正在尝试在张量流概率中拟合一个简单的 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))
尝试减小步长以提高接受率。 HMC 的最佳接受率约为 0.651 (https://arxiv.org/abs/1001.4460)。不确定为什么会看到负值。也许浮点误差接近于零?你能 post 你 运行 的一些日志吗?
我正在尝试在张量流概率中拟合一个简单的 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))
尝试减小步长以提高接受率。 HMC 的最佳接受率约为 0.651 (https://arxiv.org/abs/1001.4460)。不确定为什么会看到负值。也许浮点误差接近于零?你能 post 你 运行 的一些日志吗?