Calculator Inputs
Choose a scalar, matrix, or generated range. Optional scaling adjusts every value before activation.
Formula Used
Tanh activation: tanh(x) = (ex - e-x) ÷ (ex + e-x)
Stable equivalent: tanh(x) = 2 ÷ (1 + e-2x) - 1
Derivative: tanh′(x) = 1 - tanh²(x)
Tanh maps every finite input between negative one and one. Its derivative peaks at zero and shrinks near saturation.
How to Use
- Select a single, matrix, or generated range mode.
- Enter values and optional scale or offset settings.
- Choose precision, thresholds, and graph limits.
- Press Calculate Tanh to view outputs and gradients.
- Copy, print, or export the completed results.
Example Data
These values demonstrate negative, central, and positive activation behaviour. Large magnitudes show how Tanh approaches saturation.
| x | Approximate tanh(x) | Approximate derivative | Interpretation |
|---|---|---|---|
| -5 | -0.999909 | 0.000182 | Negative saturation |
| -2 | -0.964028 | 0.070651 | Strong negative activation |
| -1 | -0.761594 | 0.419974 | Negative active region |
| 0 | 0.000000 | 1.000000 | Maximum gradient |
| 1 | 0.761594 | 0.419974 | Positive active region |
| 2 | 0.964028 | 0.070651 | Strong positive activation |
| 5 | 0.999909 | 0.000182 | Positive saturation |
Machine Learning Interpretation
Tanh is zero-centred, unlike the standard Sigmoid activation. This often gives balanced positive and negative hidden outputs.
Large inputs create saturation and very small derivatives. Deep networks may then experience slower gradient-based learning.
ReLU avoids positive-side saturation but discards negative outputs. Tanh remains useful for recurrent states and bounded signals.
Frequently Asked Questions
What does the Tanh function return?
It returns a smooth value between negative one and one. Zero input produces exactly zero output.
Why is Tanh called zero-centred?
Its outputs can be negative, zero, or positive. This differs from standard Sigmoid outputs.
What is the Tanh derivative?
The derivative equals one minus the squared Tanh output. It reaches one when x equals zero.
When does Tanh saturate?
Saturation occurs when outputs approach negative one or positive one. The threshold is adjustable here.
Can this calculator process matrices?
Yes, it calculates every matrix value element by element. Rows may use line breaks or semicolons.
How does Tanh compare with Sigmoid?
Both functions saturate and remain smooth. Tanh produces zero-centred outputs from negative one to one.
How does Tanh compare with ReLU?
ReLU is unbounded for positive inputs. Tanh is bounded and preserves negative activation values.
Why do gradients become small?
The Tanh curve flattens at large input magnitudes. Flat regions have derivatives approaching zero.
Can extreme values cause overflow?
The calculator uses stable built-in Tanh computation. Exponential details display safe infinity notation when needed.