usencrypt.tanh#

usencrypt.tanh(x)#

Applies a hyperbolic tangent activation, defined as:

\[g(x) = \tanh(x) = \frac{e^{2x} - 1}{e^{2x} + 1}\]
Parameters

x (list or numpy.ndarray of float or usencrypt.cipher.Float) – The input list, matrix, or tensor.

Returns

The input transformed by the hyperbolic tangent activation of the same shape as x.

Return type

numpy.ndarray of float or usencrypt.cipher.Float

Warning

The precision of this function is largely dependent on the precision of the usencrypt.exp() function. See the warnings for usencrypt.exp().

Examples
>>> import numpy as np
>>> import usencrypt as ue
>>> x = np.random.randn(4, 3) - 0.5
>>> x
array([[-0.16710388,  0.41667644, -0.35427173],
       [-0.42289145, -0.13944267,  0.1442186 ],
       [ 0.19160079, -0.31765362, -0.35671227],
       [-0.07901941,  0.25071043,  0.49758583]])
>>> a = ue.ai.activation.tanh(a)
>>> a
array([[-0.16556568,  0.39412682, -0.34015847],
       [-0.39936352, -0.13854586,  0.14322698],
       [ 0.18929011, -0.30738378, -0.34231483],
       [-0.07885536,  0.24558636,  0.46021642]])