hamiltonian-monte-carlo icon indicating copy to clipboard operation
hamiltonian-monte-carlo copied to clipboard

Not able to run example file

Open allenanie opened this issue 7 years ago • 2 comments

Hi,

It seems that you might have written this over a year ago, so sorry to bother you...I'm running with TF 0.12.1, which is released a year ago (hopefully the same version that you used). And i got this error when running the example program:

Traceback (most recent call last):
  File "gaussian_sampler_example.py", line 74, in <module>
    num_steps=10)
  File "/../hamiltonian_monte_carlo.py", line 98, in hmc
    p_accept = min(1.0, tf.exp(orig - current))
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 547, in __nonzero__
    raise TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. "
TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. Use `if t is not None:` instead of `if t:` to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.

Basically this line is problematic:

p_accept = min(1.0, tf.exp(orig - current))

I'm wondering if you are able to run the sample program and if there's a easy fix to this...

allenanie avatar Apr 12 '17 02:04 allenanie

Change min to tf.minimum

stefanwebb avatar Apr 28 '17 12:04 stefanwebb

You can also change the final condition with a tf.cond

stefanwebb avatar Apr 28 '17 12:04 stefanwebb