class
TanhTransform
extends
TransformTanhTransform()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)Methods (1)
fn
log_abs_det_jacobian
→Tensorlog_abs_det_jacobian(x: Tensor, y: Tensor)Numerically-stable .