hard_tanh#
- class saiunit.math.hard_tanh(x, unit_to_scale=None)#
Hard \(\mathrm{tanh}\) activation function.
Computes the element-wise function:
\[\begin{split}\mathrm{hard\_tanh}(x) = \begin{cases} -1, & x < -1\\ x, & -1 \le x \le 1\\ 1, & 1 < x \end{cases}\end{split}\]- Parameters:
- Returns:
out – An array with values clipped to the range [-1, 1].
- Return type:
Array
Examples
>>> import jax.numpy as jnp >>> import saiunit.math as sumath >>> sumath.hard_tanh(jnp.array([-2., -0.5, 0., 0.5, 2.])) Array([-1. , -0.5, 0. , 0.5, 1. ], dtype=float32)