Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Science
  • Data Science Projects
  • Data Analysis
  • Data Visualization
  • Machine Learning
  • ML Projects
  • Deep Learning
  • NLP
  • Computer Vision
  • Artificial Intelligence
Open In App
Next Article:
Activation functions in Neural Networks
Next article icon

Activation functions in Neural Networks

Last Updated : 03 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

While building a neural network, one key decision is selecting the Activation Function for both the hidden layer and the output layer. It 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.

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.

Before diving into the activation function, you should have prior knowledge of the following topics: Neural Networks, Backpropagation

Activation-functions-in-Neural-Networks
Activation Functions in neural Networks

Introducing Non-Linearity in Neural Network

Non-linearity means that the relationship between input and output is not a straight line. In simple terms the output does not change proportionally with the input. A common choice is the ReLU function defined as \sigma(x) = \max(0, x).

Imagine you want to classify apples and bananas based on their shape and color.

  • If we use a linear function it can only separate them using a straight line.
  • But real-world data is often more complex like overlapping colors, different lighting, etc.
  • By adding a non-linear activation function like ReLU, Sigmoid or Tanh the network can create curved decision boundaries to separate them correctly.

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.

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 help 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 (i_1 \text{and } i_2​), a single hidden layer containing neurons h_1 \text{ and } h_2 and an output neuron (out).

We will use w_1, w_2 as weights connecting the inputs to the hidden neuron and w_5​ as the weight connecting the hidden neuron to the output. We'll also include biases (b_1​ for the hidden neuron and b_2 for the output neuron) to complete the model.

  1. Input Layer: Two inputs i_1 and i_2​.
  2. Hidden Layer: Two neuron h_1​ and h_2
  3. Output Layer: One output neuron.
NeuralNetwok

The input to the hidden neuron h_1 is calculated as a weighted sum of the inputs plus a bias:

{h_1} = i_1.w_1 + i_2.w_3 + b_1

{h_2} = i_1.w_2 + i_2.w_4 + b_2

The output neuron is then a weighted sum of the hidden neuron's output plus a bias:

\text{output} = h_1.w_5 + h_2.w_6 + \text{bias}

Here, h_1 , h_2 \text{ and output} are linear expressions.

In order to add non-linearity, we will be using sigmoid activation function in the output layer:

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

\text{final output} = \sigma(h_1.w_5 + h_2.w_6 + \text{bias})

\text{final output} = \frac{1}{1+e^{-(h_1.w_5+h_2.w_6 + \text{bias})}}

This gives the final output of the network after applying the sigmoid activation function in output layers, introducing the desired non-linearity.

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 (-\infty \text{ to } + \infty).
  • 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
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 A = \frac{1}{1 + e^{-x}}​. 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-Activation-Function
Sigmoid or Logistic Activation Function Graph

2. Tanh Activation Function 

Tanh function (hyperbolic tangent function) is a shifted version of the sigmoid, allowing it to stretch across the y-axis. It is defined as:

f(x) = \tanh(x) = \frac{2}{1 + e^{-2x}} - 1.

Alternatively, it can be expressed using the sigmoid function:

\tanh(x) = 2 \times \text{sigmoid}(2x) - 1

  • 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
Tanh Activation Function

3. ReLU (Rectified Linear Unit) Function 

ReLU activation is defined by A(x) = \max(0,x), this means that if the input x is positive, ReLU returns x, if the input is negative, it returns 0.

  • Value Range: [0, \infty), 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
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
Softmax Activation Function

2. SoftPlus Function

Softplus function is defined mathematically as: A(x) = \log(1 + e^x).

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 (0, \infty), 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
Softplus Activation Function

Impact of Activation Functions on Model Performance

The choice of activation function has a direct impact on the performance of a neural network in several ways:

  1. 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.
  2. 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.
  3. 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.

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.


Next Article
Activation functions in Neural Networks

S

Sakshi_Tiwari
Improve
Article Tags :
  • Misc
  • Machine Learning
  • Neural Network
Practice Tags :
  • Machine Learning
  • Misc

Similar Reads

    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:Structure of an Artificial NeuronEach neuron consists of three major components: A s
    3 min read
    Backpropagation in Neural Network
    Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . 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.It works iteratively to adjust weights and
    9 min read
    Introduction to Convolution Neural Network
    Convolutional Neural Network (CNN) is an advanced version of artificial neural networks (ANNs), primarily designed to extract features from grid-like matrix datasets. This is particularly useful for visual datasets such as images or videos, where data patterns play a crucial role. CNNs are widely us
    8 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, \text{Net Input} =\sum \text{(Weight} \times \text{Input)+Bias} Now the value of net input can be any anything from -inf to +inf
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences