Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Behavior with truncerr(η) and p=Inf Truncation Scheme #150

Closed
Confusio opened this issue Aug 29, 2024 · 5 comments
Closed

Unexpected Behavior with truncerr(η) and p=Inf Truncation Scheme #150

Confusio opened this issue Aug 29, 2024 · 5 comments

Comments

@Confusio
Copy link

I expected the truncation scheme using truncerr(η) with p = Inf to behave such that "every singular value is larger than η * max(S)". However, I observed a different behavior with the following example:

aa = TensorMap(diagm(1.0:10.0), ℝ^10, ℝ^10)
U, S, V, e = tsvd(aa; trunc=truncerr(1.001), p=Inf)

The output for S is:

TensorMap(ℝ^9 ^9):
 10.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
  0.0  9.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  8.0  0.0  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  7.0  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  6.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0  5.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0  0.0  4.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0  0.0  0.0  3.0  0.0
  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  2.0

Given that η * max(S) = 10.01, I expected that singular values smaller than 10.01 would be discarded. However, in this case, only the singular value s = 1.0 is discarded.

Could you please provide more clarification on how the truncation scheme for truncerr works, especially when using p = Inf? Specifically, why is only the smallest singular value discarded in this case?

@Jutho
Copy link
Owner

Jutho commented Aug 29, 2024

Good catch; it seems like the documentation is not in line with the implementation here, and that η counts as absolute error rather than relative, i.e. with p = Inf, it will truncate all singular values that are below η instead of η * max(S).

I guess that at some point, the implementation switched from relative to absolute error, as it is quite easy to get to relative error by simply multiplying the absolute error with norm(tensor, p). The documentation did not get updated in the process.

Is it ok to simply update the documentation to resolve this issue?

@Jutho
Copy link
Owner

Jutho commented Aug 29, 2024

My comment is not entirely correct, as norm(tensor, p) is not equal to norm(S, p) with S the singular values of tensor. That only works with p=2. I guess I am used to reason in 2-norm. Note that there is also truncbelow if you want to cut singular values below a specific (absolute) threshold.

@Confusio
Copy link
Author

Now I set η=2.2' and p=2`, and the output is unchanged.

TensorMap(ℝ^9 ^9):
 10.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
  0.0  9.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  8.0  0.0  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  7.0  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  6.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0  5.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0  0.0  4.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0  0.0  0.0  3.0  0.0
  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  2.0

s=2.0 is smaller than η now but remains. So truncerr behaves different from truncbelow. Anyway, I can use truncbelow as I don't understand the behavior of truncerr.

@Jutho
Copy link
Owner

Jutho commented Aug 29, 2024

with p=2, the truncerr is:

  • sqrt(1^2) = 1 if you truncate only the smallest one
  • sqrt(1^2 + 2^2) = 2.236... if you truncate the two smallest ones, which is already higher then your eta = 2.2
    so it just sticks to trunctating the smallest one.

With p=Inf, it should behave more or less identical to truncbelow.

@Confusio
Copy link
Author

I got it, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants