fn
entr
→Tensorentr(x: Tensor)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
xTensorInput tensor; any floating-point dtype. Values outside
produce
NaN.Returns
TensorElement-wise with the limit convention at
x = 0; same shape and dtype 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).
Examples
>>> import lucid
>>> from lucid.special import entr
>>> entr(lucid.tensor([0.0, 0.5, 1.0, 2.0]))
Tensor([0.0000, 0.3466, 0.0000, -1.3863])