All problems
Gradient of the Spectral Norm
Problem
For a matrix A with a unique largest singular value, the gradient of the spectral norm ||A||_2 is u v^T, where u and v are the top left and right singular vectors.
Given the four entries of a 2x2 matrix, compute the top singular pair from the eigen-decomposition of A^T A and return u v^T as a nested list. When the top singular value is tied, use the first coordinate direction.
Hint
The top right singular vector is the top eigenvector of A^T A, and u = A v / ||A v||.
Test cases
case 1
in: [3,0,0,1]
expected: [[1,0],[0,0]]
case 2
in: [0,1,0,0]
expected: [[0,1],[0,0]]
case 3
in: [2,0,0,2]
expected: [[1,0],[0,0]]
case 4
in: [1,2,3,4]
expected: [[0.2330424601316968,0.3306883952871801],[0.526804530425364,0.7475382155592233]]
Starter codePython
def spectral_norm_gradient(a, b, c, d):
# Return u @ v^T
# Your code here
pass4 test cases · run your code against them in the editor