def log_prob(self, value): """probability mass function evaluated at value Args: value (Tensor): value to be evaluated. Returns: Tensor: probability of value. """ if paddle.is_integer(value): value = paddle.cast(value, self.probs.dtype) logits, value = paddle.broadcast_tensors( [paddle.log(self.probs), value]) logits[(value == 0) & (paddle.isinf(logits))] = 0 return (paddle.lgamma(value.sum(-1) + 1) - paddle.lgamma(value + 1).sum(-1) + (value * logits).sum(-1))
def test_for_exception(self): with self.assertRaises(TypeError): paddle.is_integer(np.array([1, 2]))
def test_for_floating_point(self): x = paddle.randn([2, 3]) self.assertFalse(paddle.is_integer(x))
def test_for_complex(self): x = paddle.randn([2, 3]) + 1j * paddle.randn([2, 3]) self.assertFalse(paddle.is_integer(x))
def test_for_integer(self): x = paddle.arange(10) self.assertTrue(paddle.is_integer(x))