From 8a031e6626b0b75abd29162977153e92d6f273ef Mon Sep 17 00:00:00 2001 From: Emile Mathieu Date: Fri, 11 Aug 2017 16:17:48 +0100 Subject: [PATCH] typo, scope_iter and scope fixes --- edward/inferences/hmcda.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/edward/inferences/hmcda.py b/edward/inferences/hmcda.py index 219ed3e62..5c3c3aa0d 100644 --- a/edward/inferences/hmcda.py +++ b/edward/inferences/hmcda.py @@ -60,7 +60,8 @@ def initialize(self, n_adapt, delta=0.65, Lambda=0.15, *args, **kwargs): Lambda : float, optional Target leapfrog length """ - self.scope_iter = 0 # a convenient counter for log joint calculations + # store global scope for log joint calculations + self._scope = tf.get_default_graph().unique_name("inference") + '/' # Find initial epsilon step_size = self.find_good_eps() @@ -137,7 +138,7 @@ def build_update(self): should_adapt = self.t <= self.n_adapt assign_ops = tf.cond(should_adapt, lambda: self._adapt_step_size(alpha), - lambda: self._do_not__adapt_step_size(alpha)) + lambda: self._do_not_adapt_step_size(alpha)) # Update Empirical random variables. for z, qz in six.iteritems(self.latent_vars): @@ -148,7 +149,7 @@ def build_update(self): assign_ops.append(self.n_accept.assign_add(tf.where(accept, 1, 0))) return tf.group(*assign_ops) - def _do_not__adapt_step_size(self, alpha): + def _do_not_adapt_step_size(self, alpha): # Do not adapt step size but assign last running averaged epsilon to epsilon assign_ops = [] assign_ops.append(tf.assign(self.H_B, self.H_B).op) @@ -188,7 +189,7 @@ def find_good_eps(self): old_r[z] = normal.sample() # Initialize espilon at 1.0 - epsilon = tf.Variable(1.0, trainable=False) + epsilon = tf.constant(1.0) # Calculate log joint probability old_z = {z: tf.gather(qz.params, 0) @@ -257,8 +258,7 @@ def _log_joint(self, z_sample): z_sample : dict Latent variable keys to samples. """ - self.scope_iter += 1 - scope = 'inference_' + str(id(self)) + '/' + str(self.scope_iter) + scope = self._scope + tf.get_default_graph().unique_name("sample") # Form dictionary in order to replace conditioning on prior or # observed variable with conditioning on a specific value. dict_swap = z_sample.copy()