Element-wise hyperbolic tangent bijection .
Maps element-wise. Commonly used in
reinforcement learning to push a Normal policy through tanh so
actions live in a bounded box (SAC and friends). Monotone
increasing, bijective, event_dim = 0.
Notes
Forward: .
Inverse: (the inverse hyperbolic tangent).
Log Jacobian determinant (numerically stable form):
This formulation avoids overflow / underflow when is large, which the naive form would suffer (since ).
Examples
>>> import lucid
>>> from lucid.distributions.transforms import TanhTransform
>>> T = TanhTransform()
>>> T(lucid.tensor(0.0)) # tanh(0) = 0
Tensor(0.0)Used by 1
Instance methods
1Numerically-stable .
Computed as
— the stable form used by the reference framework that avoids
the catastrophic log(1 - 1) cancellation when |x| is
large.
Parameters
Returns
TensorSame shape as x.