Bayesflow: ensure Gaussian assertion of sigma positivity is executed; add test.

Change: 122084052
This commit is contained in:
A. Unique TensorFlower 2016-05-11 12:01:11 -08:00 committed by TensorFlower Gardener
parent 851012c010
commit 3451a5903f
2 changed files with 12 additions and 2 deletions

View File

@ -127,5 +127,15 @@ class GaussianTest(tf.test.TestCase):
self.assertAllClose(sample_values[:, 0, 1].mean(), mu_v[1], atol=1e-2)
self.assertAllClose(sample_values[:, 0, 1].std(), sigma_v[1], atol=1e-1)
def testNegativeSigmaFails(self):
with tf.Session():
gaussian = tf.contrib.distributions.Gaussian(
mu=[1.],
sigma=[-5.],
name='G')
with self.assertRaisesOpError(
r'should contain only positive values'):
gaussian.mean.eval()
if __name__ == '__main__':
tf.test.main()

View File

@ -103,8 +103,8 @@ class Gaussian(object):
mu = ops.convert_to_tensor(mu)
sigma = ops.convert_to_tensor(sigma)
with ops.control_dependencies([_assert_all_positive(sigma)]):
self._mu = mu
self._sigma = sigma
self._mu = array_ops.identity(mu, name="mu")
self._sigma = array_ops.identity(sigma, name="sigma")
contrib_tensor_util.assert_same_float_dtype((mu, sigma))