# ReLU (Rectified Linear Unit)

April 28, 2023

ReLU (Rectified Linear Unit) is a popular activation function used in artificial neural networks and deep learning. The activation function plays an essential role in learning models as it determines the output of a neuron or the layer of neurons. ReLU is widely used due to its simplicity and effectiveness in learning complex patterns in data. In this article, we will explore the concept and applications of ReLU in detail.

## Introduction to Activation Function

Before discussing ReLU, let’s understand the importance of activation functions. Activation functions are mathematical functions applied to the output of a neuron or a set of neurons in a neural network. The activation function allows the neural network to model the non-linear relationships between inputs and outputs, which is essential for learning complex patterns in data.

The activation function takes the weighted sum of inputs and adds a bias term, which is then passed through the activation function to generate the output of the neuron. The activation function is an element-wise function that applies to each neuron, and it helps in introducing non-linearity into the neural network, which makes it capable of modeling non-linear relationships between inputs and outputs.

Some popular activation functions used in deep learning include Sigmoid, Tanh, and ReLU. Activation functions like Sigmoid and Tanh were widely used in the early days of deep learning, but they have some limitations. For instance, Sigmoid and Tanh have a vanishing gradient problem, which means that the gradient of the activation function becomes too small, making it difficult for the neural network to learn.

ReLU was introduced to overcome some of the limitations of Sigmoid and Tanh and has become a popular choice in recent years.

## What is ReLU?

ReLU stands for Rectified Linear Unit, and it is an activation function that returns the input if it is positive, and zero otherwise. In other words, ReLU is defined as:

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

ReLU is a simple yet powerful activation function that can learn complex patterns in data. It is computationally efficient and has low memory requirements compared to other activation functions like Sigmoid and Tanh.

ReLU has become a popular choice for activation functions due to several reasons:

### 1. Simplicity

ReLU is a simple activation function that is easy to implement and computationally efficient. It has only one parameter and requires less memory compared to other activation functions like Sigmoid and Tanh.

### 2. Non-linearity

ReLU is a non-linear activation function that introduces non-linearity into the neural network. Non-linearity is essential for learning complex patterns in data and helps in improving the performance of the neural network.

### 3. Sparsity

ReLU introduces sparsity into the neural network as it sets negative values to zero. Sparsity means that only a small fraction of neurons are active at any given time, which can help in reducing overfitting and improving generalization performance.

ReLU provides better gradient flow compared to other activation functions like Sigmoid and Tanh. The gradient of ReLU is either 0 or 1, which makes it easier for the neural network to learn and converge faster.

## ReLU Variants

ReLU has several variants, each with its own advantages and disadvantages. In this section, we will discuss some of the popular variants of ReLU.

### 1. Leaky ReLU

Leaky ReLU is a variant of ReLU that addresses the problem of “dying ReLU.” Dying ReLU refers to the situation where the gradient of ReLU becomes zero, and the neuron stops learning. Leaky ReLU solves this problem by allowing a small negative slope for negative inputs.

Leaky ReLU is defined as:

``````f(x) = max(αx, x)
``````

where α is a small constant, typically 0.01.

Leaky ReLU has been shown to perform better than ReLU in some cases, especially in deep neural networks.

### 2. Parametric ReLU

Parametric ReLU (PReLU) is a variant of Leaky ReLU that allows the negative slope to be learned during training. In PReLU, the negative slope is not fixed, but it is learned from data, which makes it more flexible than Leaky ReLU.

PReLU is defined as:

``````f(x) = max(αx, x)
``````

where α is a learnable parameter.

PReLU has been shown to perform better than ReLU and Leaky ReLU in some cases, especially in large-scale image recognition tasks.

### 3. Exponential ReLU

Exponential ReLU (ELU) is a variant of ReLU that addresses the problem of “dying ReLU” and provides better performance than ReLU and its variants.

ELU is defined as:

``````f(x) = x if x>0
f(x) = α(e^x -1) if x<=0
``````

where α is a small constant, typically 1.0.

ELU has been shown to perform better than ReLU and its variants, especially in deep neural networks.