Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-249

SVD Power Iteration for Singular Vectors

Problem

Estimate the dominant singular triple of A with power iteration on B = A^T A.

Start from v = [1, ..., 1] and repeatedly set v = (B*v) / ||B*v||. After num_iterations, set sigma = ||A*v||, u = A*v / sigma, and return [sigma, u, v]. If B*v is ever 0, return [0.0, zeros, zeros].

Hint

The right singular vectors are eigenvectors of A^T A; u is obtained by normalizing A*v.

Test cases

case 1
in: [[[3,0],[0,1]],10]
expected: [3,[1,0],[1,0]]
case 2
in: [[[1,2],[3,4]],20]
expected: [5.464985704219043,[0.40455358483375686,0.9145142956773044],[0.5760484367663208,0.8174155604703632]]
case 3
in: [[[2,0],[0,0]],5]
expected: [2,[1,0],[1,0]]
case 4
in: [[[1,0],[0,1]],10]
expected: [1,[0.7071067811865476,0.7071067811865476],[0.7071067811865476,0.7071067811865476]]
Starter codePython
def dominant_singular_triple(A, num_iterations):
    # Your code here
    pass

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