I am trying to understand the truncation error when performing an SVD using ITensors. According to ITensor Examples · ITensors.jl, the truncation error is defined as sum_{discarded n} lambda_n^2 / sum_{n} lambda_n^2, where lambda_n are the singular values. However, running the following code, I get inconsistent results:
using ITensors
i = Index(10,"i”);
j = Index(40,"j”);
k = Index(20,"k”);
T = random_itensor(i,j,k)
# Approximate calculation, get truncated spectrum
maxdim = 10
U,S,V,spec = svd(T, (i,k), maxdim = maxdim)
# The following lines give the same result
@show (norm(U * S * V - T)/norm(T))^2
@show truncerror(spec)
# Exact calculation to get the entire spectrum
U,S,V,spec = svd(T,(i,k))
spec_vals = eigs(spec)
# This line gives a result that does not agree with the truncation errors from above
@show (sum(spec_vals[maxdim+1:end].^2)/sum(spec_vals.^2))
What am I missing?