neural networks
activation functions
logistic function
tanh function
machine learning theory

Neural Activation Functions - Difference between Logistic / Tanh / etc

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

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:

σ(x)=11+ex\sigma(x) = \frac{1}{1 + e^{-x}}

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: (0,1)(0, 1)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:

tanh(x)=exexex+ex\text{tanh}(x) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}

Characteristics

Range: (1,1)(-1, 1)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:

f(x)=max(0,x)f(x) = \max(0, x)

Characteristics

Range: [0,)[0, \infty)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:

f(x)={xif x>0αxif x0f(x) = \begin{cases} x & \text{if } x > 0 \\ \alpha x & \text{if } x \leq 0 \end{cases}

where α\alpha is a small constant (e.g., 0.01).

Parametric ReLU

A variant where α\alpha is learned during training, adapting based on data:

f(x)={xif x>0αixif x0f(x) = \begin{cases} x & \text{if } x > 0 \\ \alpha_i x & \text{if } x \leq 0 \end{cases}

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 FunctionFormulaRangeKey CharacteristicsCommon Issues
Sigmoidσ(x)=11+ex\sigma(x) = \frac{1}{1 + e^{-x}}(0, 1)Smooth gradient, output as a probabilityVanishing gradients
Tanhtanh(x)=exexex+ex\text{tanh}(x) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}(-1, 1)Zero-centered, wider rangeVanishing gradients (less)
ReLUf(x)=max(0,x)f(x) = \max(0, x)[0,)[0, \infty)Sparse activation, fast convergenceDying ReLU
Leaky ReLUf(x)=x if x>0αx if x0f(x) = x \text{ if } x > 0 \alpha x \, \text{ if } x \leq 0(,)(-\infty, \infty)Solves dying ReLU, some negative slopesCan still have zero gradients
Parametric ReLUSimilar to Leaky ReLU(,)(-\infty, \infty)Learns alpha during training, adaptableComplexity 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.


Course illustration
Course illustration

All Rights Reserved.