in ais.py [0:0]
def ancestral_sample(e_func, weights, batch_size=128, prop_dist=10, temp=1, hmc_step=10):
if FLAGS.dataset == "2d":
x = tf.placeholder(tf.float32, shape=(None, 2))
elif FLAGS.dataset == "gauss":
x = tf.placeholder(tf.float32, shape=(None, FLAGS.gauss_dim))
elif FLAGS.dataset == "mnist":
x = tf.placeholder(tf.float32, shape=(None, 28, 28))
else:
x = tf.placeholder(tf.float32, shape=(None, 32, 32, 3))
x_init = x
alpha_prev = tf.placeholder(tf.float32, shape=())
alpha_new = tf.placeholder(tf.float32, shape=())
approx_lr = tf.placeholder(tf.float32, shape=())
chain_weights = tf.zeros(batch_size)
# for i in range(1, prop_dist+1):
# print("processing loop {}".format(i))
# alpha_prev = (i-1) / prop_dist
# alpha_new = i / prop_dist
prob_log_old_neg = bridge_prob_neg_log(alpha_prev, x, e_func, weights, temp)
prob_log_new_neg = bridge_prob_neg_log(alpha_new, x, e_func, weights, temp)
chain_weights = -prob_log_new_neg + prob_log_old_neg
# chain_weights = tf.Print(chain_weights, [chain_weights])
# Sample new x using HMC
def unorm_prob(x):
return bridge_prob_neg_log(alpha_new, x, e_func, weights, temp)
for j in range(1):
x = hmc(x, approx_lr, hmc_step, unorm_prob)
return chain_weights, alpha_prev, alpha_new, x, x_init, approx_lr