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
inputTensorInput 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 input.
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).
The value is and takes the
0 \log 0 convention from lucid.xlogy. The gradient is
as the reference framework has it: the one-sided
at x = 0 and NaN below zero.
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])