Skip to content
DeepForgeby svx
All problems
HardDeep Learningdl-089

Spectral Norm Power Iteration

Problem

One power-iteration step for spectral normalization. Compute v_new = normalize(W^T u), then u_new = normalize(W v_new), and return the spectral norm estimate sigma = ||W v_new||_2.

The signature is spectral_norm_step(W, u, v). u is the current left singular vector estimate and v the right one; return [sigma, u_new, v_new].

Hint

Normalize after each matrix-vector product; the sigma estimate is the norm of W v_new.

Test cases

case 1
in: [[[3,0],[0,4]],[1,0],[1,0]]
expected: [3,[1,0],[1,0]]
case 2
in: [[[1,2],[3,4]],[1,0],[1,0]]
expected: [5.4037024344,[0.4138029443,0.9103664775],[0.4472135955,0.894427191]]
case 3
in: [[[2,0],[0,2]],[1,1],[1,1]]
expected: [2,[0.7071067812,0.7071067812],[0.7071067812,0.7071067812]]
case 4
in: [[[0,1],[1,0]],[1,0],[1,0]]
expected: [1,[1,0],[0,1]]
Starter codePython
import math
def spectral_norm_step(W, u, v):
    # Your code here
    pass

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