arahuja / hamiltonian-monte-carlo

Implementation of Hamiltonian Monte Carlo using Google's TensorFlow
Apache License 2.0
48 stars 11 forks source link

Not able to run example file #1

Open allenanie opened 7 years ago

allenanie commented 7 years ago

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...

stefanwebb commented 7 years ago

Change min to tf.minimum

stefanwebb commented 7 years ago

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