stanh#

ivy.stanh(x, /, *, alpha=1.7159, beta=0.67, out=None)[source]#

Compute the scaled hyperbolic tangent (tanh) activation.

The scaled tanh activation function is defined as: out = alpha * tanh(beta * x)

Parameters:
  • x (Union[Array, NativeArray]) – input array.

  • alpha (float, default: 1.7159) – The scaling parameter for the output. Determines the amplitude of the tanh function. Default: 1.7159

  • beta (float, default: 0.67) – The scaling parameter for the input. Determines the slope of the tanh function. Default: 0.67

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – The input array after applying the scaled tanh activation.

Examples

With ivy.Array input:

>>> x = ivy.array([22.])
>>> y = ivy.scaled_tanh(x)
>>> y
ivy.array([1.71589994]))
>>> x = ivy.array([4.0, 7.0])
>>> y = ivy.scaled_tanh(x, alpha=1.2, beta=5)
>>> y
ivy.array([1.20000005, 1.20000005])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([1.2, -1.2]), b=ivy.array([4.4, -2.2]))
>>> y = ivy.scaled_tanh(x)
>>> y
{
    a: ivy.array([1.14324772, -1.14324772]),
    b: ivy.array([1.70648694, -1.54488957])
}
>>> x = ivy.Container(a=ivy.array([1.2]), b=ivy.array([4.4]))
>>> y = ivy.scaled_tanh(x, alpha=0.2, beta=0.5)
>>> y
{
a: ivy.array([0.10740992]),
b: ivy.array([0.19514863])
}