Skip to content
DeepForgeby svx
All problems
HardCalculusca-335

Relative Gradient Check Error

Problem

Gradient checks compare an analytic gradient a against a numerical gradient n using the relative error ||a - n|| / max(1e-8, ||a|| + ||n||), where the norm is Euclidean.

Given the two vectors, return the relative error.

Hint

Guard the denominator against two zero gradients.

Test cases

case 1
in: [[1,2],[1,2]]
expected: 0
case 2
in: [[1,0],[1.001,0.001]]
expected: 0.0007067532280607271
case 3
in: [[0,0],[1,1]]
expected: 1
Starter codePython
def relative_gradient_check_error(analytic, numeric):
    # Your code here
    pass

3 test cases · run your code against them in the editor