PIXELBANKv9.1.0
Menu

Implement a function to compute the derivative of the Rectified Linear Unit (ReLU) activation function, a crucial component in Backpropagation. The ReLU function is defined as f(x)=max⁡(0,x)f(x) = \max(0, x), and its derivative is essential for training Deep Learning models.

The ReLU derivative is a piecewise function that depends on the input value xx. Understanding this derivative is vital for optimizing neural networks using Backpropagation, as it helps compute the gradients of the loss function with respect to the model's parameters.

To compute the ReLU derivative, follow these steps:

  1. Evaluate the input value xx.
  2. Apply the derivative formula based on the value of xx.
ddxReLU(x)={1x>00x≤0\frac{d}{dx}\text{ReLU}(x) = \begin{cases} 1 & x > 0 \\ 0 & x \leq 0 \end{cases}

This technique is widely used in Deep Learning models for image and speech recognition tasks.

Example:

Input:
relu_derivative([-1, 0, 1, 2])
Output:
[0, 0, 1, 1]
Reasoning:
  • For each input value, apply the ReLU derivative rule: if x>0x > 0, the derivative is 1; if x≤0x \leq 0, the derivative is 0[5]
  • Evaluate each element: −1≤0-1 \leq 0 → 0, 0≤00 \leq 0 → 0, 1>01 > 0 → 1, 2>02 > 0 → 1[5]
  • The output is the array of derivatives corresponding to each input: [0, 0, 1, 1]

Constraints:

  • Return derivative for each element
solution.py

Test Results

0/0
Run code to see test results.
ReLU Derivative - Easy | PixelBank