ReLU Derivative
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 , and its derivative is essential for training Deep Learning models.
The ReLU derivative is a piecewise function that depends on the input value . 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:
- Evaluate the input value .
- Apply the derivative formula based on the value of .
This technique is widely used in Deep Learning models for image and speech recognition tasks.
Example
relu_derivative([-1, 0, 1, 2])
[0, 0, 1, 1]
- The input is a list of pre-activation values , the numbers a neuron produces before ReLU is applied. Here .
- The output has one entry per input: the slope of at that point, so four inputs give four slopes.
- On the negative side ReLU is flat at , so its slope is : gives .
- At the function has a kink and no true derivative; the convention in the description () assigns it .
- On the positive side ReLU is the line with slope : and both give , whatever their size.
- Result:
[0, 0, 1, 1], whole numbers rather than decimals. Notice that during backpropagation this acts as a gate: the incoming gradient passes through unchanged where the entry is and is blocked where it is .
Constraints
- Return derivative for each element