v9.1.1
Menu

ReLU Activation

easyFREENeural NetworksDeep LearningCV: Deep Learning

Implement the ReLU activation function, a crucial component in Neural Networks. This function is used to introduce non-linearity in the model, enabling it to learn complex relationships between inputs and outputs.

The ReLU function, or Rectified Linear Unit, is defined as max(0,x)max(0, x), where xx is the input to the function. This function is widely used in Deep Learning due to its simplicity and computational efficiency.

  1. The input xx is passed through the function.
  2. The function returns 00 if xx is negative, and xx if xx is positive.
ReLU(x)=max⁡(0,x)\text{ReLU}(x) = \max(0, x)

This technique is widely used in image classification tasks.

Example

Input
relu([-2, -1, 0, 1, 2])
Output
[0, 0, 0, 1, 2]
Reasoning
  • The input is a list of five real numbers, [-2, -1, 0, 1, 2], which you can picture as the pre-activation outputs of five neurons. The output is a list of the same length, where entry ii is ReLU(xi)=max⁡(0,xi)\text{ReLU}(x_i) = \max(0, x_i).
  • Negative entries get clipped: max⁡(0,−2)=0\max(0, -2) = 0 and max⁡(0,−1)=0\max(0, -1) = 0. Their sign and size are both lost.
  • Zero sits right on the boundary, so max⁡(0,0)=0\max(0, 0) = 0. Either branch of the definition gives the same value.
  • Positive entries pass through unchanged: max⁡(0,1)=1\max(0, 1) = 1 and max⁡(0,2)=2\max(0, 2) = 2.
  • Putting these together in the original order gives [0, 0, 0, 1, 2].
  • Notice that the output is never negative and keeps the input's position order. Every value ≤0\le 0 collapses to the same 00, and that flattening of the negative half is the non-linearity. An empty input has nothing to transform, so it gives an empty output.

Constraints

  • Apply element-wise to input list

Learn this in

More from CV: Deep Learning

solution.py

Test results

Sign in to run your code against the test cases.