Why tanh outperforms sigmoid
By: Chamanth Mvs
Tags: Machine Learning, Data Science, Deep Learning, Activation Functions

tanh function is symmetric about the origin, where the inputs would be normalized and they are more likely to produce outputs (which are inputs to next layer)and also, they are on an average close to zero. It can also be said that data is centered around zero for tanh (centered around zero is nothing but mean of the input data is around zero.

These are the main reasons why tanh is preferred and performs better than sigmoid (logistic).

Why you should normalize ?

Assume, all the inputs are positive. Weights to a particular node in the first weight layer are updated by an amount proportional to δx where δ is the (scalar) error at that node and x is the input vector. When all of the components of an input vector are positive, all updates of weights that feed into a node will have the same sign (i.e. sign of (δ)). As a result, these weights can only ‘all decrease’ or ‘all increase’ together for a given input pattern. Thus, if a weight vector must change direction it can only do so by zigzagging, which is inefficient and it is very slow. — — To prevent such cases, normalization should be done where the average becomes zero.

This approach(normalization) should be applied at all the layers in the network, which means that the average of the outputs of a node to be close to zero because these outputs are the inputs to the next layer.

Convergence is usually faster if the average of each input variable over the training set is close to zero.

The network training converges faster if its inputs are whitened — i.e., linearly transformed to have zero means and unit variances and decorrelated. As each layer observes the inputs produced by their previous layers, it would be advantageous to achieve the same whitening of the inputs of each layer.

Getting stuck during training (train time):

Not converging at train time.

Logistic sigmoid can cause a neural network to get “stuck” during training. This is because, if a strongly-negative input is provided to the logistic sigmoid, it outputs value, which is very near to zero. Because of this behaviour, updation of weights will be slow and they are less regularly updated. In simple terms, weights which are updated through backpropagation will be quite slow. In contrast to it, tanh has the output values range between (1,-1). So, strongly negative inputs to the tanh will map to negative outputs. Additionally, only zero-valued inputs are mapped to near-zero outputs. These properties make the network less likely to get “stuck” during training.

Problem of tanh and advantages of logistic sigmoid:

tanh functions — error surface can be very flat at origin. So,initializing very small weights should be avoided. Error surfaces can also be flat far from origin because of saturation of sigmoids (saturation is nothing but, the values can’t go beyond the limits, For instance, the value of logistic sigmoid can’t be above 1 or below 0).

These both are problems of tanh and sigmoid functions.

Logistic Sigmoid has beautiful probabilistic interpretation, which made it more popular. Rather than classifying 0 or 1, logistic sigmoid can give the probability value for particular data point, belonging to 0 or 1. Such interpretation lacks with tanh function.

This is the main advantage of logistic sigmoid.