def test_value(self):
with self.test_session(use_gpu=True):
def _test_value(logits, given):
logits = np.array(logits, np.float32)
given = np.array(given, np.float32)
bernoulli = Bernoulli(logits)
log_p = bernoulli.log_prob(given)
target_log_p = stats.bernoulli.logpmf(
given, 1. / (1. + np.exp(-logits)))
self.assertAllClose(log_p.eval(), target_log_p)
p = bernoulli.prob(given)
target_p = stats.bernoulli.pmf(
given, 1. / (1. + np.exp(-logits)))
self.assertAllClose(p.eval(), target_p)
_test_value(0., [0, 1])
_test_value([-50., -10., -50.], [1, 1, 0])
_test_value([0., 4.], [[0, 1], [0, 1]])
_test_value([[2., 3., 1.], [5., 7., 4.]],
np.ones([3, 1, 2, 3], dtype=np.int32))
评论列表
文章目录