The Wayback Machine - https://web.archive.org/web/20240930175506/https://www.geeksforgeeks.org/activation-functions/
Open In App

Activation Functions

Last Updated : 12 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

33 (1)

Mathematically,

[Tex]\text{net input} =\sum_\text{(weight * input)+bias}[/Tex]

Now the value of net input can be any anything from -inf to +inf. The neuron doesn’t really know how to bound to value and thus is not able to decide the firing pattern. Thus the activation function is an important part of an artificial neural network. They basically decide whether a neuron should be activated or not. Thus it bounds the value of the net input. The activation function is a non-linear transformation that we do over the input before sending it to the next layer of neurons or finalizing it as output.

Types of Activation Functions –

Several different types of activation functions are used in Deep Learning. Some of them are explained below:

Step Function: Step Function is one of the simplest kind of activation functions. In this, we consider a threshold value and if the value of net input say y is greater than the threshold then the neuron is activated. Mathematically,

[Tex]f(x)=1, \text{if x}>=0[/Tex]
[Tex]f(x)=0, \text{if x}<0[/Tex]

Given below is the graphical representation of step function.


Sigmoid Function: Sigmoid function is a widely used activation function. It is defined as:

[Tex]\frac{1}{(1+e^-^x)}[/Tex]

Graphically,

This is a smooth function and is continuously differentiable. The biggest advantage that it has over step and linear function is that it is non-linear. This is an incredibly cool feature of the sigmoid function. This essentially means that when I have multiple neurons having sigmoid function as their activation function – the output is non linear as well. The function ranges from 0-1 having an S shape.


ReLU: The ReLU function is the Rectified linear unit. It is the most widely used activation function. It is defined as:

[Tex]f(x) = \max(0, x)[/Tex]

Graphically,

The main advantage of using the ReLU function over other activation functions is that it does not activate all the neurons at the same time. What does this mean ? If you look at the ReLU function if the input is negative it will convert it to zero and the neuron does not get activated.


Leaky ReLU: Leaky ReLU function is nothing but an improved version of the ReLU function.Instead of defining the Relu function as 0 for x less than 0, we define it as a small linear component of x. It can be defined as:

[Tex]f(x) = ax, x<0[/Tex]
[Tex]f(x) = x, \text{otherwise}[/Tex]

Graphically,

Read More:

Practices Questions – Activation Functions

1. Sigmoid Function Calculation

– Formula: sigma(x) = 1 / (1 + exp(-x))

– Compute the output of the sigmoid activation function for the input values: -1, 0, and 1.

2. Tanh Function Properties

– Output Range:

– Sigmoid: [0, 1]

– Tanh: [-1, 1]

– Gradient:

– Sigmoid: The gradient is sigma(x) * (1 – sigma(x)), which can be very small for large positive or negative values of x, leading to vanishing gradients.

– Tanh: The gradient is 1 – tanh^2(x), which is typically larger than the sigmoid’s gradient, especially for values near zero.

3. ReLU Activation

– Formula: ReLU(x) = max(0, x)

– Calculate the output of the ReLU activation function for the input values: -3, 0, and 3.

4. Leaky ReLU Implementation

– Formula: Leaky ReLU(x) = max(0.01 * x, x)

– Implement the Leaky ReLU activation function for the input value 0.5 with a negative slope coefficient of 0.01.

5. Softmax Function Calculation

– Formula: softmax(x_i) = exp(x_i) / sum(exp(x_j) for all j)

– For the input vector [1, 2, 3], compute the output of the softmax activation function.

6. Activation Function Derivatives

– Sigmoid Gradient:

– Formula: The derivative of the sigmoid function with respect to its input x is: d(sigma(x))/dx = sigma(x) * (1 – sigma(x))

7. Choosing Activation Functions

– Binary Classification:

– Reason: The sigmoid function is commonly used in the output layer for binary classification because it maps any input to a probability range [0, 1], making it suitable for representing the probability of a binary outcome.

8. Vanishing Gradient Problem

– Description: The vanishing gradient problem occurs when gradients become very small during backpropagation, leading to slow or stalled training of deep neural networks.

– Susceptible Activation Functions: Sigmoid and tanh are most susceptible to this issue because their gradients can become very small for large positive or negative inputs, especially in deep networks.

9. Swish Activation Function

– Formula: Swish(x) = x * sigma(x)

– Compute the output of the Swish activation function for an input value of 2.

10. Comparing Activation Functions

– ReLU:

– Formula: ReLU(x) = max(0, x)

– Advantages: Simplicity, computational efficiency, avoids vanishing gradients.

– Disadvantages: Can suffer from the “dying ReLU” problem, where neurons can become inactive and stop learning.

– ELU (Exponential Linear Unit):

– Formula: ELU(x) = x if x > 0, else alpha * (exp(x) – 1)

– Advantages: Helps avoid the dying ReLU problem, has a smooth curve for negative inputs.

– Disadvantages: Slightly more computationally expensive than ReLU.


Previous Article
Next Article

Similar Reads

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 Softplus which are discussed briefly in this articl
3 min read
Activation functions in Neural Networks
It is recommended to understand Neural Networks before reading this article.  In the process of building a neural network, one of the choices you get to make is what Activation Function to use in the hidden layer as well as at the output layer of the network. This article discusses Activation functions in Neural Networks. Table of Content What is a
7 min read
Mathematics | Unimodal functions and Bimodal functions
Unimodal Function : A function f(x) is said to be unimodal function if for some value m it is monotonically increasing for x≤m and monotonically decreasing for x≥m. For function f(x), maximum value is f(m) and there is no other local maximum. See figure (A) and (B): In figure (A), graph has only one maximum point and rest of the graph goes do
2 min read
Composite functions - Relations and functions
Let f : A->B and g : B->C be two functions. Then the composition of f and g, denoted by g o f, is defined as the function g o f : A->C given by g o f (x) = g{f(x)}, ∀ x ∈ A. Clearly, dom(g o f) = dom(f). Also, g o f is defined only when range(f) is a subset of dom(g). Evaluating composite functions We know composite function is written as
5 min read
Classes of Functions | Injective, Surjective and Bijective Functions
Classes of Functions: Functions are fundamental in mathematics and have wide-ranging applications in engineering, computer science, and various other fields. Understanding the different classes of functions—injective, surjective, and bijective—is essential for analyzing mathematical models and solving complex problems. This article explores these c
6 min read
Class 11 RD Sharma Solutions - Chapter 3 Functions - Exercise 3.3
Question 1. Find the domain of each of the following real valued functions of real variable:(i) f (x) = 1/x Solution: We are given, f (x) = 1/x. Here, f (x) is defined for all real values of x, except for the case when x = 0. Therefore, domain of f = R – {0} (ii) f (x) = 1/(x−7) Solution: We are given, f (x) = 1/(x−7). Here, f (x) is defined for al
7 min read
Mathematics | Generating Functions - Set 2
Prerequisite - Generating Functions-Introduction and Prerequisites In Set 1 we came to know basics about Generating Functions. Now we will discuss more details on Generating Functions and its applications. Exponential Generating Functions - Let [Tex]h_0, h_1, h_2, ........., h_n, ...... [/Tex]e a sequence. Then its exponential generating function,
3 min read
Self Dual functions in Digital Logic
A function is said to be Self dual if and only if its dual is equivalent to the given function, i.e., if a given function is f(X, Y, Z) = (XY + YZ + ZX) then its dual is, fd(X, Y, Z) = (X + Y).(Y + Z).(Z + X) (fd = dual of the given function) = (XY + YZ + ZX), it is equivalent to the given function. So function is self dual. In a dual function: AND
2 min read
Number of Boolean functions
In the below article, we are going to find the number of Boolean Functions possible from the given sets of binary number. Statement-1: Suppose two sets are set 'A' = {1, 2, 3, 4, ........, n} where each number will be either '0' or '1' and hence the total number of boolean variable possible will be [Tex]2^n[/Tex] and set 'B' = {0, 1}. Now the numbe
2 min read
Number of possible Functions
In the below articles, we are going to calculate the number of functions possible from given two sets of the element. Statement: Suppose there are two sets 'A' and 'B' containing 'n' and 'm' number of elements respectively, i.e., Sets, 'A' = {1, 2, 3, 4, ............, n}, 'B' = {1, 2, 3, 4, ............, m} Then the number of function possible will
2 min read
Class 12 RD Sharma Solutions - Chapter 17 Increasing and Decreasing Functions - Exercise 17.1
Question 1: Prove that the function f(x) = loge x is increasing on (0,∞). Solution: Let x1, x2 ∈ (0, ∞) We have, x1<x2 ⇒ loge x1 < loge x2 ⇒ f(x1) < f(x2) Therefore, f(x) is increasing in (0, ∞). Question 2: Prove that the function f(x) = loga (x) is increasing on (0,∞) if a>1 and decreasing on (0,∞) if 0<a<1. Solution: Case 1: Wh
4 min read
Class 11 RD Sharma Solutions - Chapter 3 Functions - Exercise 3.2
Question 1. If f(x)=x2-3x+4, then find the values of x satisfying the equation f(x)=f(2x+1). Solution: We have, f(x)=x2-3x+4 Now, f(2x+1)=(2x+1)2-3(2x+1)+4 f(2x+1)=4x2+1+4x-6x-3+4 f(2x+1)=4x2-2x+2 It is given that f(x)=f(2x+1) x2-3x+4=4x2-2x+2 0=4x2-x2-2x+3x+2-4 3x2+x-2=0 3x2+3x-2x-2=0 3x(x+1)-2(x+1)=0 (x+1)(3x-2)=0 x+1=0 or 3x-2=0 x=-1 or x=2/3 Th
4 min read
Class 11 RD Sharma Solutions - Chapter 6 Graphs of Trigonometric Functions - Exercise 6.2
Question 1: Sketch the following graphs:(i) y = cos (x+[Tex]\frac{\pi}{4}[/Tex]) Solution: To obtain this graph y-0 = cos (x+[Tex]\frac{\pi}{4} [/Tex]), Shifting the origin at [Tex](-\frac{\pi}{4},0) [/Tex], we have X = x+[Tex]\frac{\pi}{4} [/Tex] and Y = y-0 Substituting these values, we get Y = cos X First we draw the graph of Y = cos X and shift
3 min read
Class 11 RD Sharma Solutions - Chapter 5 Trigonometric Functions - Exercise 5.1 | Set 2
Question 14. Prove that [Tex]\frac{(1+cotÎļ+tanÎļ)(sinÎļ-cosÎļ)}{sec^3Îļ-cosec^3Îļ}=sin^2Îļcos^2Îļ [/Tex] Solution: We have [Tex]\frac{(1+cotÎļ+tanÎļ)(sinÎļ-cosÎļ)}{sec^3Îļ-cosec^3Îļ}=sin^2Îļcos^2Îļ [/Tex] Taking LHS = [Tex]\frac{(1+cotÎļ+tanÎļ)(sinÎļ-cosÎļ)}{sec^3Îļ-cosec^3Îļ}[/Tex] = [Tex]\frac{(1+\frac{cosÎļ}{sinÎļ}+\frac{sinÎļ}{cosÎļ})(sinÎļ-cosÎļ)}{\frac{1}{cos^3Îļ}-\frac
7 min read
Class 11 RD Sharma Solutions - Chapter 5 Trigonometric Functions - Exercise 5.2
Question 1. Find the values of the other five trigonometric functions in each of the following:(i) cot x = 12/5, x in quadrant III(ii) cos x = -1/2, x in quadrant II(iii) tan x = 3/4, x in quadrant III(iv) sin x = 3/5, x in quadrant I Solution: (i) cot x = 12/5, x in quadrant III As we knew that tan x and cot x are positive in third quadrant and si
7 min read
Class 11 RD Sharma Solutions - Chapter 5 Trigonometric Functions - Exercise 5.3
Question 1. Find the values of the following trigonometric ratios:(i) sin 5π/3 Solution: We have, sin 5π/3 =sin (2π-π/3) [âˆĩsin(2π-Îļ)=-sinÎļ] =-sin(π/3) = - √3/2 (ii) sin 17π Solution: We have, sin 17π ⇒sin 17π=sin (34×π/2) Since, 17π lies in the negative x-axis i.e. between 2nd and 3rd quadrant =sin 17π [âˆĩ sin nπ=0] = 0 (iii) tan11π/6 Solution: Clea
8 min read
Class 11 RD Sharma Solutions - Chapter 3 Functions - Exercise 3.4
Question 1. Find f + g, f – g, cf (c ∈ R, c ≠ 0), fg, 1/f and f/g in each of the following:(i) f(x) = x3 + 1 and g (x) = x + 1 Solution: Given, f(x) = x3 + 1 and g(x) = x + 1 and f(x): R → R and g(x): R → R We know, (f + g)(x) = f(x) + g(x) ⇒ (f + g) (x) = x3 + 1 + x + 1 = x3 + x + 2 So, (f + g)(x) = x3 + x + 2 As, (f – g)(x) = f(x) – g(x) ⇒ (f – g
14 min read
Class 11 RD Sharma Solutions - Chapter 6 Graphs of Trigonometric Functions - Exercise 6.3
Sketch the graphs of the following functions:Question 1: y = sin2 x Solution: As we know that, y = sin2 x = [Tex]\frac{1- cos 2x}{2} = \frac{1}{2} - \frac{cos 2x}{2}[/Tex] [Tex]y - \frac{1}{2} = -\frac{cos 2x}{2}[/Tex] On shifting the origin at (0, 1/2), we get X = x and Y = [Tex]y – \frac{1}{2}[/Tex] On substituting these values, we get [Tex]Y = -
5 min read
Class 12 RD Sharma Solutions - Chapter 17 Increasing and Decreasing Functions - Exercise 17.2 | Set 2
Question 11. Show that f(x) = cos2 x is a decreasing function on (0, π/2). Solution: We have, f(x) = cos2 x On differentiating both sides with respect to x, we get f'(x) = [Tex]\frac{d}{dx}(cos^2 x)[/Tex] f'(x) = 2 cos x (– sin x) f'(x) = – sin 2x Now for 0 < x < π/2, => sin 2x > 0 => – sin 2x < 0 => f'(x) < 0 Thus, f(x) is
9 min read
Onto Functions in Mathematics
Onto Function is one of the many types of functions defined based on the relationship between its domain and codomain. For any function to be onto, it needs to relate two sets with a very specific mapping between elements, meaning that each element of the codomain has at least one element in the domain as its pre-image. In simple words, for any fun
11 min read
Many One Functions
Many-to-One or Many One Function is one of the various types of functions that represent relationships between different entities. As we know, a function is a very specific type of relation in which each input has a unique output. In a many-one function, many inputs can have the same output. For example, x2, where both 1 and -1 have the same output
7 min read
How to evaluate trigonometric functions without a calculator?
Trigonometry is known as the branch of mathematics that deals with certain measurements of triangular regions. A common application of trigonometry is the measurement of the sides and angles of a triangle. For this, we use some trigonometric functions of acute angles. These functions are defined as certain ratios of a right-angled triangle containi
6 min read
Derivatives of Composite Functions
Derivatives are an essential part of calculus. They help us in calculating the rate of change, maxima, and minima for the functions. Derivatives by definition are given by using limits, which is called the first form of the derivative. We already know how to calculate the derivatives for standard functions, but sometimes we need to deal with comple
6 min read
Derivatives of Polynomial Functions
Derivatives are used in Calculus to measure the rate of change of a function with respect to a variable. The use of derivatives is very important in Mathematics. It is used to solve many problems in mathematics like to find out maxima or minima of a function, slope of a function, to tell whether a function is increasing or decreasing. If a function
3 min read
Definite Integrals of Piecewise Functions
Imagine a graph with a function drawn on it, it can be a straight line or a curve or anything as long as it is a function. Now, this is just one function on the graph, can 2 functions simultaneously occur on the graph? Imagine two functions simultaneously occurring on the graph, say, a straight line and a curve, and the limits on the x-axis for whi
5 min read
Functions Defined by Integrals
While thinking about functions, we always imagine that a function is a mathematical machine that gives us an output for any input we give. It is usually thought of in terms of mathematical expressions like squares, exponential and trigonometric function, etc. It is also possible to define the functions in terms of definite integrals. These are simi
5 min read
Class 12 NCERT Solutions- Mathematics Part I - Chapter 1 Relations And Functions - Exercise 1.1 | Set 2
Content of this article has been merged with Chapter 1 Relations And Functions - Exercise 1.1 as per the revised syllabus of NCERT. Question 11. Show that the relation R in the set A of points in a plane given by R ={ (P,Q): distance of the point P from the origin is the same as the distance of the point Q from the origin}, is an equivalence relati
6 min read
Class 12 NCERT Solutions- Mathematics Part I - Chapter 2 Inverse Trigonometric Functions - Exercise 2.2 | Set 2
Content of this article has been merged with Chapter 2 Inverse Trigonometric Functions - Exercise 2.2 as per the revised syllabus of NCERT. Find the values of each of the following: Question 11. tan−1[2cos(2sin−11/2​)] Solution: Let us assume that sin−11/2 = x So, sinx = 1/2 Therefore, x = π​/6 = sin−11/2 Therefore, tan−1[2cos(2sin−11/2​)] = tan−1[
3 min read
Class 12 NCERT Solutions- Mathematics Part I - Chapter 1 Relations And Functions -Miscellaneous Exercise on Chapter 1 | Set 1
Question 1. Let f : R → R be defined as f(x) = 10x + 7. Find the function g : R → R such that g o f = f o g = 1R. Solution: As, it is mentioned here f : R → R be defined as f(x) = 10x + 7 To, prove the function one-one Let's take f(x) = f(y) 10x + 7 = 10y + 7 x = y Hence f is one-one. To, prove the function onto y ∈ R, y = 10x+7 [Tex]x = \frac{y-7}
9 min read
NCERT Solutions Class 12- Mathematics Part I – Chapter 1 Relations And Functions -Miscellaneous Exercise on Chapter 1
Question 1. Show that the function f : R → {x ∈ R : – 1 < x < 1} defined by f(x) = [Tex]\frac{x}{1+|x|} [/Tex], x ∈ R is one one and onto function.Solution: As, it is mentioned here f : R → {x ∈ R : – 1 < x < 1} defined by [Tex]f(x) = \frac{x}{1+|x|} [/Tex], x ∈ R As, we know f is invertible, if and only if f is one-one and onto. ONE-ON
5 min read