Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-365

Gradient Norm Relative Change

Problem

A convergence diagnostic compares successive gradient norms by the relative change |new - old| / max(old, eps).

Given the old and new norms and eps, return the relative change.

Hint

The epsilon guard avoids division by an exactly zero old norm.

Test cases

case 1
in: [1,0.1]
expected: 0.9
case 2
in: [10,10]
expected: 0
case 3
in: [0,1]
expected: 1000000000000
Starter codePython
def gradient_norm_relative_change(old_norm, new_norm, eps=1e-12):
    # Your code here
    pass

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