Skip to content

Commit

Permalink
fix pep8 in tests_inference_auto_transform.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinvtran committed Jan 8, 2018
1 parent 4abda1a commit 209c32e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/inferences/test_inference_auto_transform.py
Expand Up @@ -181,7 +181,7 @@ def test_hmc_betabernoulli(self):
qz_constrained = z_unconstrained.bijector.inverse(qz_samples)
qz_mean, qz_var = sess.run(tf.nn.moments(qz_constrained, 0))

true_posterior = Beta(1. + np.sum(x_obs), 1. + np.sum(1-x_obs))
true_posterior = Beta(1. + np.sum(x_obs), 1. + np.sum(1 - x_obs))
pz_mean, pz_var = sess.run((true_posterior.mean(),
true_posterior.variance()))
self.assertAllClose(qz_mean, pz_mean, rtol=5e-2, atol=5e-2)
Expand All @@ -199,16 +199,19 @@ def test_klqp_betabernoulli(self):
initializer=tf.random_normal(()))
qz_std = tf.nn.softplus(tf.get_variable(name="qz_prestd",
initializer=tf.random_normal(())))
qz_unconstrained = ed.models.Normal(loc=qz_mean, scale=qz_std, name="z_posterior")
qz_unconstrained = ed.models.Normal(
loc=qz_mean, scale=qz_std, name="z_posterior")

inference_klqp = ed.inferences.KLqp({z: qz_unconstrained}, data={xs: x_obs})
inference_klqp = ed.inferences.KLqp(
{z: qz_unconstrained}, data={xs: x_obs})
inference_klqp.run(n_iter=500, auto_transform=True)

z_unconstrained = inference_klqp.transformations[z]
qz_constrained = z_unconstrained.bijector.inverse(qz_unconstrained.sample(1000))
qz_constrained = z_unconstrained.bijector.inverse(
qz_unconstrained.sample(1000))
qz_mean, qz_var = sess.run(tf.nn.moments(qz_constrained, 0))

true_posterior = Beta(np.sum(x_obs) + 1., np.sum(1-x_obs) + 1.)
true_posterior = Beta(np.sum(x_obs) + 1., np.sum(1 - x_obs) + 1.)
pz_mean, pz_var = sess.run((true_posterior.mean(),
true_posterior.variance()))
self.assertAllClose(qz_mean, pz_mean, rtol=5e-2, atol=5e-2)
Expand Down

0 comments on commit 209c32e

Please sign in to comment.