Element-wise entropy kernel .
Returns the per-element contribution to Shannon entropy. This is the standard building block for evaluating for a discrete distribution, with the limit convention applied at the boundary.
Parameters
Input tensor. Integer and bool inputs are taken as
float32.
Values below zero give -inf.Returns
TensorElement-wise with the limit convention at
x = 0; same shape as x.
Notes
Definition:
The function is concave with maximum at
. It vanishes at both x = 0 (limit) and
x = 1. Related quantities include rel_entr (point-wise
relative entropy) and kl_div (KL kernel).
It is and takes the 0 \log 0
convention from lucid.xlogy, so the gradient at x = 0 is
0 rather than the one-sided of
that the reference framework returns. Below
zero the gradient is NaN, as in the reference.
Examples
>>> import lucid
>>> from lucid.special import entr
>>> entr(lucid.tensor([0.0, 0.5, 1.0, 2.0]))
tensor([0., 0.3466, 0., -1.386])