Hand-derive the gradient of L = sum(ReLU(x)) w.r.t. x.
Forward: y = max(0, x) element-wise. L = sum(y).
Implement:
relu_forward(x) -> yrelu_backward(x) -> dL/dx of the same shape as xThe harness verifies your analytic backward against central-differences of the forward. Note: the gradient at x = 0 is technically undefined; convention is to treat it as 0.
Math
Related problems
Asked at
import numpy as np
def relu_forward(...):
pass
Premium problem
Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.
Already premium?