All problems
Normalized Linear Norm Gradient
Problem
For f(x) = ||W x|| with a constant matrix W, the gradient with respect to x is W^T W x / ||W x||.
Given W as nested rows and a nonzero x, return the gradient list.
Hint
Differentiate the norm as (Wx)/||Wx|| and apply the chain rule for W.
Test cases
case 1
in: [[[1,0],[0,1]],[1,1]]
expected: [0.7071067811865475,0.7071067811865475]
case 2
in: [[[1,2]],[1,0]]
expected: [1,2]
case 3
in: [[[2,0],[0,1]],[0,3]]
expected: [0,1]
Starter codePython
def normalized_linear_norm_gradient(w, x):
# Your code here
pass3 test cases · run your code against them in the editor