All problems
Low-Rank Truncation Error
Problem
Return the Frobenius norm error of the best rank-r approximation of a matrix, from its singular values:
error = sqrt(sum of squares of the singular values after the first r)
This is the Eckart-Young theorem in error form.
Hint
Truncating at r leaves only the tail singular values as error.
Test cases
case 1
in: [[5,3,1],1]
expected: 3.1622776601683795
case 2
in: [[5,3,1],0]
expected: 5.916079783099616
case 3
in: [[5,3,1],3]
expected: 0
case 4
in: [[4,0,0],1]
expected: 0
Starter codePython
def low_rank_error(singular_values, r):
# Your code here
pass4 test cases · run your code against them in the editor