def testValueOutsideAndOnEdgeOfSupport(self, dtype): finfo = np.finfo(dtype) x = tf.convert_to_tensor( [ # Sqrt(finfo.max)**2 = finfo.max < Inf, so # round_exponential_bump_function == 0 here. -np.sqrt(finfo.max), # -2 is just outside the support, so round_exponential_bump_function # should == 0. -2., # -1 is on boundary of support, so round_exponential_bump_function # should == 0. # The gradient should also equal 0. -1., 1., 2.0, np.sqrt(finfo.max), ], dtype=dtype) y = tfp_math.round_exponential_bump_function(x) self.assertDTypeEqual(y, dtype) y_ = self.evaluate(y) # We hard-set y to 0 outside support. self.assertAllFinite(y_) self.assertAllEqual(y_, np.zeros((6, )))
def testValueOnSupportInterior(self, dtype): # round_exponential_bump_function(x) = 0 for x right at the edge of the # support, e.g. x = -0.999. This is expected, due to the exponential and # division. x = tf.convert_to_tensor([-0.9925, -0.5, 0., 0.5, 0.9925], dtype=dtype) y = tfp_math.round_exponential_bump_function(x) self.assertDTypeEqual(y, dtype) y_ = self.evaluate(y) self.assertAllFinite(y_) # round_exponential_bump_function(0) = 1. self.assertAllClose(1., y_[2]) # round_exponential_bump_function(x) > 0 for |x| < 1. self.assertAllGreater(y_, 0)