Skip to content
fn

symlog

→Tensor
symlog(x: Tensor)

Symmetric logarithm — compress magnitude, keep sign and zero.

symlog(x)=sign(x) ln⁡(∣x∣+1)\mathrm{symlog}(x) = \mathrm{sign}(x)\,\ln(|x| + 1)

Parameters

Any shape.

Returns

Tensor

Same shape.

Notes

Behaves like the identity near zero and like a logarithm far from it, so a single network can be trained on targets whose scale is not known in advance — rewards that are 0.01 in one environment and 10000 in another land in the same range without per-task normalisation. That is what it is for in DreamerV3.

The inverse is symexp, and the pair is exact: symexp of symlog returns the input. Implemented through log1p rather than log(1 + ·) so small inputs keep their precision.

Examples

>>> import lucid
>>> import lucid.nn.functional as F
>>> F.symlog(lucid.tensor([-100.0, 0.0, 100.0]))
tensor([-4.615, 0., 4.615])

See Also

  • symexp—The inverse transform.

Used by 1