Neural Activation Functions - Difference between Logistic / Tanh / etc
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
In the realm of artificial neural networks, activation functions play a crucial role in introducing non-linearity into the model, enabling it to learn complex patterns. Various activation functions exist, each with unique characteristics affecting model performance, convergence speed, and computational efficiency. This article delves into common neural activation functions, including Logistic (Sigmoid), Hyperbolic Tangent (Tanh), ReLU, and some of their variants.
Logistic (Sigmoid) Activation Function
Overview
The Logistic function, often referred to as the Sigmoid function, is defined as:
It maps any real-valued number into the range of 0 to 1, making it particularly useful for binary classification problems where the output is interpreted as a probability.
Characteristics
• Range: • Non-linear: Capable of capturing non-linear relationships. • Vanishing Gradient Problem: For large positive or negative inputs, derivatives approach zero, leading to minimal weight updates during backpropagation. • Centering: Not zero-centered which can affect optimization.
Example Use Case
Sigmoid is often used in the output layer of binary classifiers. For instance, in network structures like logistic regression, to predict whether an email is spam or not.
Hyperbolic Tangent (Tanh) Activation Function
Overview
The Tanh function is an extension of the Sigmoid function that maps input to the range (-1, 1). It is defined by:
Characteristics
• Range: • Non-linear: Similar to Sigmoid but with a broader range. • Vanishing Gradient: Still susceptible to the vanishing gradient problem but less severe than Sigmoid. • Centering: Zero-centered, which helps in the gradient descent process.
Example Use Case
Due to its output range and properties, Tanh is often favored in hidden layers of neural networks, providing faster convergence than Sigmoid.
Rectified Linear Unit (ReLU) Activation Function
Overview
The ReLU activation function provides a simple non-linear transformation, defined as:
Characteristics
• Range: • Non-linear: Allows the model to account for complex scenarios. • Sparse Activation: Efficiently activates a unit only for positive input values. • Avoids Vanishing Gradient: Except for non-positive inputs, helps networks to converge faster. • Dying ReLU Problem: During training, neurons can get stuck at zero.
Example Use Case
ReLU has become the default activation function for many hidden layers due to its simplicity and efficiency, used extensively in CNNs and deep feedforward networks.
Leaky ReLU and Variants
Leaky ReLU
To address the dying ReLU problem, variants like Leaky ReLU introduce a small slope for negative values, defined as:
where is a small constant (e.g., 0.01).
Parametric ReLU
A variant where is learned during training, adapting based on data:
Example Use Case
Both variants alleviate issues of standard ReLU and are suitable for deep convolutional networks where gradient mobility is crucial.
Comparing Activation Functions
The table below summarizes the key points of these activation functions:
| Activation Function | Formula | Range | Key Characteristics | Common Issues |
| Sigmoid | (0, 1) | Smooth gradient, output as a probability | Vanishing gradients | |
| Tanh | (-1, 1) | Zero-centered, wider range | Vanishing gradients (less) | |
| ReLU | Sparse activation, fast convergence | Dying ReLU | ||
| Leaky ReLU | Solves dying ReLU, some negative slopes | Can still have zero gradients | ||
| Parametric ReLU | Similar to Leaky ReLU | Learns alpha during training, adaptable | Complexity in training |
Conclusion
The choice of activation function can greatly influence model performance and training efficiency. While Sigmoid and Tanh functions were widely used in earlier neural networks, ReLU and its variants have largely displaced them in deep learning due to their computational benefits and higher convergence speed. Understanding the nuances of each activation function is crucial for practitioners to tailor neural networks effectively to problem-specific needs.
Related reading
- Neural nets as universal approximators
- Neural Network / Machine Learning memory storage
- Neural Network Architecture Design
- Neural Network Back-Propagation Algorithm Gets Stuck on XOR Training PAttern
- Neural Network Back-Propagation Algorithm Gets Stuck on XOR Training PAttern
- Neural network backprop not fully training
- Neural Network based ranking of documents
- Neural network bias for each neuron
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.