code: def leapfrog(z_old, r_old, step_size, log_joint, n_steps):
      z_new = z_old.copy()
      r_new = r_old.copy()
  
      grad_log_joint = tf.gradients(
          log_joint(z_new), list(six.itervalues(z_new))
      )
      for _ in range(n_steps):
          for i, key in enumerate(six.iterkeys(z_new)):
              z, r = z_new[key], r_new[key]
              r_new[key] = r + 0.5 * step_size * tf.convert_to_tensor(
                  grad_log_joint[i]
              )
              z_new[key] = z + step_size * r_new[key]
  
          grad_log_joint = tf.gradients(
              log_joint(z_new), list(six.itervalues(z_new))
          )
          for i, key in enumerate(six.iterkeys(z_new)):
              r_new[key] += (
                  0.5
                  * step_size
                  * tf.convert_to_tensor(grad_log_joint[i])
              )
  
      return z_new, r_new
  
file_path: edward/edward/inferences/hmc.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import six
  import tensorflow
  from collections import OrderedDict
  from edward.inferences.monte_carlo import MonteCarlo
  from edward.models import RandomVariable
  from edward.util import copy
label_desc: Use image node_id 1 for calling a global function with example usage: leapfrog(z_old, r_old, step_size, log_joint, n_steps) and returns: z_new,  r_new