def build_update(self):
    'Simulate Hamiltonian dynamics with friction using a discretized\n    integrator. Its discretization error goes to zero as the learning\n    rate decreases.\n\n    Implements the update equations from (15) of Chen et al. (2014).\n    '
    old_sample = {z: tf.gather(qz.params, tf.maximum((self.t - 1), 0)) for (z, qz) in six.iteritems(self.latent_vars)}
    old_v_sample = {z: v for (z, v) in six.iteritems(self.v)}
    friction = tf.constant(self.friction, dtype=tf.float32)
    learning_rate = tf.constant((self.step_size * 0.01), dtype=tf.float32)
    grad_log_joint = tf.gradients(self._log_joint(old_sample), list(six.itervalues(old_sample)))
    sample = {}
    v_sample = {}
    for (z, grad_log_p) in zip(six.iterkeys(old_sample), grad_log_joint):
        qz = self.latent_vars[z]
        event_shape = qz.event_shape
        normal = Normal(loc=tf.zeros(event_shape), scale=(tf.sqrt((learning_rate * friction)) * tf.ones(event_shape)))
        sample[z] = (old_sample[z] + old_v_sample[z])
        v_sample[z] = ((((1.0 - (0.5 * friction)) * old_v_sample[z]) + (learning_rate * tf.convert_to_tensor(grad_log_p))) + normal.sample())
    assign_ops = []
    for (z, qz) in six.iteritems(self.latent_vars):
        variable = qz.get_variables()[0]
        assign_ops.append(tf.scatter_update(variable, self.t, sample[z]))
        assign_ops.append(tf.assign(self.v[z], v_sample[z]).op)
    assign_ops.append(self.n_accept.assign_add(1))
    return tf.group(*assign_ops)
Simulate Hamiltonian dynamics with friction using a discretized
integrator. Its discretization error goes to zero as the learning
rate decreases.

Implements the update equations from (15) of Chen et al. (2014).
def build_update(self):
    'Simulate Hamiltonian dynamics with friction using a discretized\n    integrator. Its discretization error goes to zero as the learning\n    rate decreases.\n\n    Implements the update equations from (15) of Chen et al. (2014).\n    '
    old_sample = {z: tf.gather(qz.params, tf.maximum((self.t - 1), 0)) for (z, qz) in six.iteritems(self.latent_vars)}
    old_v_sample = {z: v for (z, v) in six.iteritems(self.v)}
    friction = tf.constant(self.friction, dtype=tf.float32)
    learning_rate = tf.constant((self.step_size * 0.01), dtype=tf.float32)
    grad_log_joint = tf.gradients(self._log_joint(old_sample), list(six.itervalues(old_sample)))
    sample = {}
    v_sample = {}
    for (z, grad_log_p) in zip(six.iterkeys(old_sample), grad_log_joint):
        qz = self.latent_vars[z]
        event_shape = qz.event_shape
        normal = Normal(loc=tf.zeros(event_shape), scale=(tf.sqrt((learning_rate * friction)) * tf.ones(event_shape)))
        sample[z] = (old_sample[z] + old_v_sample[z])
        v_sample[z] = ((((1.0 - (0.5 * friction)) * old_v_sample[z]) + (learning_rate * tf.convert_to_tensor(grad_log_p))) + normal.sample())
    assign_ops = []
    for (z, qz) in six.iteritems(self.latent_vars):
        variable = qz.get_variables()[0]
        assign_ops.append(tf.scatter_update(variable, self.t, sample[z]))
        assign_ops.append(tf.assign(self.v[z], v_sample[z]).op)
    assign_ops.append(self.n_accept.assign_add(1))
    return tf.group(*assign_ops)