All problems
Relative Parameter Change
Problem
Measure the relative change between two parameter vectors.
Return ||new - old||_2 / (||old||_2 + eps), where both norms are Euclidean over the components in common. This is a scale-free progress measure often used in convergence checks.
Hint
eps guards against division by zero when old is the zero vector.
Test cases
case 1
in: [[1,2],[1.1,2.2],1e-8]
expected: 0.09999999955278649
case 2
in: [[0,0],[1,1],0.5]
expected: 2.8284271247461903
case 3
in: [[3,-4],[3,-4],1e-8]
expected: 0
case 4
in: [[0.5,0.5],[0,0],0.01]
expected: 0.9860550753913473
Starter codePython
def relative_param_change(old, new, eps):
# Your code here
pass4 test cases · run your code against them in the editor