Suppose I have two tensors, p1
and p2
in tensorflow of the same shape which contain probilities, some of which might be zero or one. Is their and elegant way of calculating the log-likelihood pointwise: p1*log(p2) + (1-p1)*log(1-p2)
?
Implementing it naively using the tensorflow functions
p1*tf.log(p2) + (1-p1)*tf.log(1-p2)
risks calling 0*tf.log(0)
which will give a nan
.