Tanh

dl_activation_function_tanh.png
Quelle: PapersWithCode.com

The tanh function, also known as the hyperbolic tangent function, is a mathematical function that is often used in machine learning and deep learning algorithms. It maps real-valued numbers to the range between -1 and 1.

In Python, the tanh function can be implemented using the numpy library:

import numpy as np

x = np.linspace(-10, 10, 100)
y = np.tanh(x)

The formula for this function is:

This means that the tanh function calculates the difference between the exponential of x and the exponential of negative x, divided by their sum.

The derivative of the tanh function can be expressed as:

This derivative is used during the backpropagation process in neural networks.

One of the main advantages of using the tanh function in neural networks is that it produces zero-centered outputs which can help during gradient descent optimization. However, it also suffers from vanishing gradients problem when input values are too large or too small.