Activation functions in Neural Networks
Last Updated :
19 Nov, 2024
While building a neural network, one key decision is selecting the Activation Function for both the hidden layer and the output layer. Activation functions decide whether a neuron should be activated.
In this article, we will explore the role of activation functions in neural networks, their types, and their impact on the learning process.
Pre-requisite: Neural Networks, Backpropagation
What is an Activation Function?
An activation function is a mathematical function applied to the output of a neuron. It introduces non-linearity into the model, allowing the network to learn and represent complex patterns in the data. Without this non-linearity feature, a neural network would behave like a linear regression model, no matter how many layers it has.
The activation function decides whether a neuron should be activated by calculating the weighted sum of inputs and adding a bias term. This helps the model make complex decisions and predictions by introducing non-linearities to the output of each neuron.
Why is Non-Linearity Important in Neural Networks?
Neural networks consist of neurons that operate using weights, biases, and activation functions.
In the learning process, these weights and biases are updated based on the error produced at the outputâa process known as backpropagation. Activation functions enable backpropagation by providing gradients that are essential for updating the weights and biases.
Without non-linearity, even deep networks would be limited to solving only simple, linearly separable problems. Activation functions empower neural networks to model highly complex data distributions and solve advanced deep learning tasks. Adding non-linear activation functions introduce flexibility and enable the network to learn more complex and abstract patterns from data.
Mathematical Proof of Need of Non-Linearity in Neural Networks
To illustrate the need for non-linearity in neural networks with a specific example, let’s consider a network with two input nodes [Tex](i_1 \text{and } i_2â)[/Tex], a single hidden layer containing one neuron [Tex](h_1)[/Tex], and an output neuron (out). We will use [Tex]w_1, w_2[/Tex] as weights connecting the inputs to the hidden neuron, and [Tex]w_5[/Tex]â as the weight connecting the hidden neuron to the output. We’ll also include biases ([Tex]b_1[/Tex]â for the hidden neuron and [Tex]b_2[/Tex] for the output neuron) to complete the model.
Network Structure
- Input Layer: Two inputs [Tex]i_1[/Tex] and [Tex]i_2â[/Tex].
- Hidden Layer: One neuron [Tex]h_1[/Tex]â.
- Output Layer: One output neuron.

Mathematical Model Without Non-linearity
Hidden Layer Calculation:
The input to the hidden neuron h1h_1h1â is calculated as a weighted sum of the inputs plus a bias:
[Tex]z_{h_1} = w_1 i_1 + w_2 i_2 + b_1
[/Tex]
Output Layer Calculation:
The output neuron is then a weighted sum of the hidden neuron’s output plus a bias:
[Tex] \text{output} = w_5 h_1 + b_2
[/Tex]
If [Tex]h_1[/Tex]â were directly the output of [Tex]z_{h_1}[/Tex] (no activation function applied, i.e., [Tex]h_1 = z_{h_1}ââ[/Tex]), then substituting [Tex]h_1[/Tex] in the output equation yields:
[Tex]\text{output}= w_5 (w_1 i_1 + w_2 i_2 + b_1) + b_2
[/Tex]
[Tex]\text{output} = w_5 w_1 i_1 + w_5 w_2 i_2 + w_5 b_1 + b_2
[/Tex]
This shows that the output neuron is still a linear combination of the inputs [Tex]i_1[/Tex]â and [Tex]i_2â[/Tex].
Thus, the entire network, despite having multiple layers and weights, effectively performs a linear transformation, equivalent to a single-layer perceptron.
Introducing Non-Linearity in Neural Network
To introduce non-linearity, let’s use a non-linear activation function [Tex]\sigma[/Tex] for the hidden neuron. A common choice is the ReLU function, defined as [Tex]\sigma(x) = \max(0, x)[/Tex].
Updated Hidden Layer Calculation:
[Tex]h_1 = \sigma(z_{h_1}) = \sigma(w_1 i_1 + w_2 i_2 + b_1)
[/Tex]
Output Layer Calculation with Non-linearity:
[Tex]\text{output} = w_5 \sigma(w_1 i_1 + w_2 i_2 + b_1) + b_2
[/Tex]
Effect of Non-linearity
The inclusion of the ReLU activation function \sigma allows h_1â to introduce a non-linear decision boundary in the input space. This non-linearity enables the network to learn more complex patterns that are not possible with a purely linear model, such as:
- Modeling functions that are not linearly separable.
- Increasing the capacity of the network to form multiple decision boundaries based on the combination of weights and biases.
Types of Activation Functions in Deep Learning
1. Linear Activation Function
Linear Activation Function resembles straight line define by y=x. No matter how many layers the neural network contains, if they all use linear activation functions, the output is a linear combination of the input.
- The range of the output spans from [Tex](-\infty \text{ to } + \infty)[/Tex].
- Linear activation function is used at just one place i.e. output layer.
- Using linear activation across all layers makes the network’s ability to learn complex patterns limited.
Linear activation functions are useful for specific tasks but must be combined with non-linear functions to enhance the neural networkâs learning and predictive capabilities.

Linear Activation Function or Identity Function returns the input as the output
2. Non-Linear Activation Functions
1. Sigmoid Function
Sigmoid Activation Function is characterized by ‘S’ shape. It is mathematically defined as[Tex] A = \frac{1}{1 + e^{-x}}[/Tex]â. This formula ensures a smooth and continuous output that is essential for gradient-based optimization methods.
- It allows neural networks to handle and model complex patterns that linear equations cannot.
- The output ranges between 0 and 1, hence useful for binary classification.
- The function exhibits a steep gradient when x values are between -2 and 2. This sensitivity means that small changes in input x can cause significant changes in output y, which is critical during the training process.

Sigmoid or Logistic Activation Function Graph
2. Tanh Activation Function
Tanh function or hyperbolic tangent function, is a shifted version of the sigmoid, allowing it to stretch across the y-axis. It is defined as:
[Tex] f(x) = \tanh(x) = \frac{2}{1 + e^{-2x}} – 1. [/Tex]
Alternatively, it can be expressed using the sigmoid function:
[Tex] \tanh(x) = 2 \times \text{sigmoid}(2x) – 1
[/Tex]
- Value Range: Outputs values from -1 to +1.
- Non-linear: Enables modeling of complex data patterns.
- Use in Hidden Layers: Commonly used in hidden layers due to its zero-centered output, facilitating easier learning for subsequent layers.

Tanh Activation Function
3. ReLU (Rectified Linear Unit) Function
ReLU activation is defined by [Tex]A(x) = \max(0,x)[/Tex], this means that if the input x is positive, ReLU returns x, if the input is negative, it returns 0.
- Value Range: [Tex][0, \infty)[/Tex], meaning the function only outputs non-negative values.
- Nature: It is a non-linear activation function, allowing neural networks to learn complex patterns and making backpropagation more efficient.
- Advantage over other Activation: ReLU is less computationally expensive than tanh and sigmoid because it involves simpler mathematical operations. At a time only a few neurons are activated making the network sparse making it efficient and easy for computation.

ReLU Activation Function
3. Exponential Linear Units
1. Softmax Function
Softmax function is designed to handle multi-class classification problems. It transforms raw output scores from a neural network into probabilities. It works by squashing the output values of each class into the range of 0 to 1, while ensuring that the sum of all probabilities equals 1.
- Softmax is a non-linear activation function.
- The Softmax function ensures that each class is assigned a probability, helping to identify which class the input belongs to.

Softmax Activation Function
2. SoftPlus Function
Softplus function is defined mathematically as: [Tex]A(x) = \log(1 + e^x)[/Tex]. This equation ensures that the output is always positive and differentiable at all points, which is an advantage over the traditional ReLU function.
- Nature: The Softplus function is non-linear.
- Range: The function outputs values in the range [Tex](0, \infty)[/Tex], similar to ReLU, but without the hard zero threshold that ReLU has.
- Smoothness: Softplus is a smooth, continuous function, meaning it avoids the sharp discontinuities of ReLU, which can sometimes lead to problems during optimization.

Softplus Activation Function
The choice of activation function has a direct impact on the performance of a neural network in several ways:
- Convergence Speed: Functions like ReLU allow faster training by avoiding the vanishing gradient problem, while Sigmoid and Tanh can slow down convergence in deep networks.
- Gradient Flow: Activation functions like ReLU ensure better gradient flow, helping deeper layers learn effectively. In contrast, Sigmoid can lead to small gradients, hindering learning in deep layers.
- Model Complexity: Activation functions like Softmax allow the model to handle complex multi-class problems, whereas simpler functions like ReLU or Leaky ReLU are used for basic layers.
Conclusion
Activation functions are the backbone of neural networks, enabling them to capture non-linear relationships in data. From classic functions like Sigmoid and Tanh to modern variants like ReLU and Swish, each has its place in different types of neural networks. The key is to understand their behavior and choose the right one based on your modelâs needs.
Frequently Asked Questions : Activation Functions
What is the activation function?
An activation function determines the output of a neuron in a neural network by adding non-linearity, enabling the network to learn complex patterns from the data.
What is ReLU and softmax?
- ReLU outputs the input directly if it’s positive, or zero otherwise, and is used in hidden layers to speed up training.
- Softmax is used in the output layer for multi-class classification, converting raw outputs into probabilities for each class.
What is the ReLU activation function?
ReLU is activation function that helps avoid vanishing gradients and computationally efficient in deep learning.
What is the difference between ReLU and TANH?
ReLU outputs positive values directly and zero for negatives, while Tanh maps inputs between -1 and 1. Tanh is zero-centered but suffers from vanishing gradients, unlike ReLU which does not for positive values.
Similar Reads
Activation functions in Neural Networks
While building a neural network, one key decision is selecting the Activation Function for both the hidden layer and the output layer. Activation functions decide whether a neuron should be activated. In this article, we will explore the role of activation functions in neural networks, their types,
8 min read
Activation functions in Neural Networks | Set2
The article Activation-functions-neural-networks will help to understand the use of activation function along with the explanation of some of its variants like linear, sigmoid, tanh, Relu and softmax. There are some other variants of the activation function like Elu, Selu, Leaky Relu, Softsign and S
3 min read
Auto-associative Neural Networks
Auto associative Neural networks are the types of neural networks whose input and output vectors are identical. These are special kinds of neural networks that are used to simulate and explore the associative process. Association in this architecture comes from the instruction of a set of simple pro
3 min read
Types Of Activation Function in ANN
The biological neural network has been modeled in the form of Artificial Neural Networks with artificial neurons simulating the function of a biological neuron. The artificial neuron is depicted in the below picture: Each neuron consists of three major components:Â A set of 'i' synapses having weigh
4 min read
Exploring Adaptive Filtering in Neural Networks
Adaptive filtering is a critical concept in neural networks, particularly in the context of signal processing, control systems, and error cancellation. This article delves into the adaptive filtering problem, its mathematical formulation, and the various techniques used to address it, with a focus o
7 min read
Backpropagation in Neural Network
Backpropagation (short for "Backward Propagation of Errors") is a method used to train artificial neural networks. Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network. In this article, we will explore what
9 min read
Introduction to Convolution Neural Network
A Convolutional Neural Network (CNN) is a type of Deep Learning neural network architecture commonly used in Computer Vision. Computer vision is a field of Artificial Intelligence that enables a computer to understand and interpret the image or visual data. When it comes to Machine Learning, Artific
10 min read
Activation Functions
To put it in simple terms, an artificial neuron calculates the 'weighted sum' of its inputs and adds a bias, as shown in the figure below by the net input. Mathematically, [Tex]\text{Net Input} =\sum \text{(Weight} \times \text{Input)+Bias}[/Tex] Now the value of net input can be any anything from -
3 min read
Effect of Bias in Neural Network
Neural Network is conceptually based on actual neuron of brain. Neurons are the basic units of a large neural network. A single neuron passes single forward based on input provided. In Neural network, some inputs are provided to an artificial neuron, and with each input a weight is associated. Weigh
3 min read
Dropout in Neural Networks
The concept of Neural Networks is inspired by the neurons in the human brain and scientists wanted a machine to replicate the same process. This craved a path to one of the most important topics in Artificial Intelligence. A Neural Network (NN) is based on a collection of connected units or nodes ca
3 min read
Artificial Neural Networks and its Applications
As you read this article, which organ in your body is thinking about it? It's the brain of course! But do you know how the brain works? Well, it has neurons or nerve cells that are the primary units of both the brain and the nervous system. These neurons receive sensory input from the outside world
9 min read
Applications of Neural Network
A neural network is a processing device, either an algorithm or genuine hardware, that endeavors to recognize underlying relationships in a set of data through a process that mimics the way the human brain operates. The computing world has a ton to acquire from neural networks, also known as artific
3 min read
Introduction to Capsule Neural Networks | ML
Capsule Neural Network also known as CapsNet is an artificial neural network (ANN) in machine learning to designed to overcome limitations of traditional convolutional neural networks (CNNs). The article explores the fundamentals, working and architecture of CapsNet. Table of Content Limitation of C
12 min read
Weights and Bias in Neural Networks
Machine learning, with its ever-expanding applications in various domains, has revolutionized the way we approach complex problems and make data-driven decisions. At the heart of this transformative technology lies neural networks, computational models inspired by the human brain's architecture. Neu
13 min read
Classification of Neural Network in TensorFlow
Classification is used for feature categorization, and only allows one output response for every input pattern as opposed to permitting various faults to occur with a specific set of operating parameters. The category that has the greatest output value is chosen by the classification network. When i
10 min read
Introduction to Artificial Neural Networks | Set 1
ANN learning is robust to errors in the training data and has been successfully applied for learning real-valued, discrete-valued, and vector-valued functions containing problems such as interpreting visual scenes, speech recognition, and learning robot control strategies. The study of artificial ne
8 min read
Introduction to Residual Networks
Recent years have seen tremendous progress in the field of Image Processing and Recognition. Deep Neural Networks are becoming deeper and more complex. It has been proved that adding more layers to a Neural Network can make it more robust for image-related tasks. But it can also cause them to lose a
3 min read
Emotion Detection Using Convolutional Neural Networks (CNNs)
Emotion detection, also known as facial emotion recognition, is a fascinating field within the realm of artificial intelligence and computer vision. It involves the identification and interpretation of human emotions from facial expressions. Accurate emotion detection has numerous practical applicat
15+ min read
Introduction to Artificial Neural Network | Set 2
Artificial Neural Networks contain artificial neurons which are called units. These units are arranged in a series of layers that together constitute the whole Artificial Neural Network in a system. This article provides the outline for understanding the Artificial Neural Network. Characteristics of
3 min read