A hyperbolic tangent (tanh) function outputs the value between -1 to +1 and is expressed as follows:
It also resembles the S-shaped curve. Unlike a sigmoid function which is centered on 0.5, the tanh function is 0 centered, as shown in the following diagram:
Similar to the sigmoid function, it is also a differentiable and monotonic function. The tanh function is implemented as follows:
def tanh(x):
numerator = 1-np.exp(-2*x)
denominator = 1+np.exp(-2*x)
return numerator/denominator