Skip to content

Commit

Permalink
Python 3 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Hoffman committed Mar 25, 2017
1 parent 4f4a2a5 commit 6e92378
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions edward/inferences/conjugacy/conjugacy.py
Expand Up @@ -98,7 +98,7 @@ def complete_conditional(rv, blanket, log_joint=None):

# Simplify those nodes, and extract any new linear terms into multipliers_i.
s_stat_exprs = defaultdict(list)
for i in xrange(len(s_stats)):
for i in range(len(s_stats)):
expr = symbolic_suff_stat(s_stats[i], rv.value(), stop_nodes)
expr = full_simplify(expr)
multipliers_i, s_stats_i = extract_s_stat_multipliers(expr)
Expand Down Expand Up @@ -152,7 +152,7 @@ def complete_conditional(rv, blanket, log_joint=None):
nat_params = tf.gradients(log_joint_copy, s_stat_placeholders)

# Removes any dependencies on those old placeholders.
for i in xrange(len(nat_params)):
for i in range(len(nat_params)):
nat_params[i] = edward.util.copy(nat_params[i], swap_back,
scope=scope + 'swapback')
nat_params = [nat_params[i] for i in order]
Expand Down
8 changes: 4 additions & 4 deletions edward/inferences/conjugacy/simplify.py
Expand Up @@ -202,7 +202,7 @@ def mul_add_simplify(expr):
'''Turns Mul(Add(.), .) into Add(Mul(.), Mul(.),...)'''
if expr[0] != '#Mul':
return None
for i in xrange(1, len(expr)):
for i in range(1, len(expr)):
if expr[i][0] == '#Add':
other_args = expr[1:i] + expr[i + 1:]
return ('#Add',) + tuple((('#Mul',) + other_args + (j,)
Expand Down Expand Up @@ -277,9 +277,9 @@ def square_add_simplify(expr):
if not (expr[0] == '#CPow2.0000e+00' and expr[1][0] == '#Add'):
return None
terms = []
for i in xrange(1, len(expr[1])):
for i in range(1, len(expr[1])):
terms.append(('#CPow2.0000e+00', expr[1][i]))
for j in xrange(i + 1, len(expr[1])):
for j in range(i + 1, len(expr[1])):
terms.append(('#Mul', ('2.0',), expr[1][i], expr[1][j]))
return ('#Add',) + tuple(terms)

Expand All @@ -300,7 +300,7 @@ def add_const_simplify(expr):
return None
did_something = False
new_args = []
for i in xrange(1, len(expr)):
for i in range(1, len(expr)):
if expr_contains(expr[i], '#x'):
new_args.append(expr[i])
else:
Expand Down
4 changes: 2 additions & 2 deletions edward/models/param_mixture.py
Expand Up @@ -19,8 +19,8 @@ def __init__(self,
allow_nan_stats=True,
name="ParamMixture"):
parameters = locals()
with tf.name_scope(name, values=[mixing_weights] +
component_params.values()) as name:
values = [mixing_weights] + [i for i in component_params.values()]
with tf.name_scope(name, values=values) as name:
self._mixing_weights = mixing_weights
self._component_params = component_params
self._cat = Categorical(p=self._mixing_weights,
Expand Down
2 changes: 1 addition & 1 deletion examples/mixture_gaussian_gibbs.py
Expand Up @@ -62,7 +62,7 @@
cond_dict = {pi: pi_est, mu: mu_est, sigmasq: sigmasq_est, z: z_est, x: x_val}
t0 = time()
T = 500
for t in xrange(T):
for t in range(T):
z_est = sess.run(z_cond, cond_dict)
cond_dict[z] = z_est
pi_est, mu_est = sess.run([pi_cond, mu_cond], cond_dict)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-inferences/test_conjugacy.py
Expand Up @@ -197,7 +197,7 @@ def test_mog(self):

true_pi = pi_alpha + np.unique(z_val, return_counts=True)[1]
self.assertAllClose(pi_cond_alpha, true_pi)
for k in xrange(K):
for k in range(K):
sigmasq_true = (1. / 4**2 + 1. / sigmasq * (z_val == k).sum())**-1
mu_true = sigmasq_true * (1. / sigmasq * x_val[z_val == k].sum())
self.assertAllClose(np.sqrt(sigmasq_true), mu_cond_sigma[k])
Expand Down

0 comments on commit 6e92378

Please sign in to comment.