【发布时间】:2020-05-05 09:16:55
【问题描述】:
我正在使用 TensorFlow Probability 的 MCMC 包实现复杂的采样算法。假设我对一个组件使用 Gibbs 抽样,对另一个组件使用 Hamiltonian Monte Carlo,最后是 Random Walk Metropolis。例如,假设我们有一个联合概率,
p(X|a, b)p(b|c, d)p(c)p(d)p(a).
我的自定义采样迭代大致是:
def one_iteration():
# Sampling `a`:
# part of joint density: p(X|a, b)p(a)
# ...using some custom Gibbs sampler
# Sampling `b`:
# part of joint density: p(X|a, b)p(b|c, d)
def log_prob(b):
return p(X|a, b).log_prob() + p(b|c, d).log_prob(b)
hmc = tfp.mcmc.HamiltonianMonteCarlo(
log_prob, step_size=0.1, num_leapfrog_steps=3)
samples, is_accepted = tfp.mcmc.sample_chain(
num_results=1,
num_burnin_steps=0,
current_state=b,
kernel=hmc)
# Sampling `c`:
# part of joint density: p(b|c, d)p(c)
def log_prob(c):
return p(b|c, d).log_prob() + p(c).log_prob(c)
rwm = tfp.mcmc.RandomWalkMetropolis(log_prob)
samples, is_accepted = tfp.mcmc.sample_chain(
num_results=1,
num_burnin_steps=0,
current_state=c,
kernel=rwm)
然后运行:
for i in range(T):
one_iteration()
这是混合采样的正确方法吗?即每个组件采样算法的每次迭代都调用sample_chain?
【问题讨论】:
标签: python tensorflow mcmc tensorflow-probability