-
Notifications
You must be signed in to change notification settings - Fork 67
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
amen_mv
exceeds sweep limit when working with complex numbers
#98
Comments
amen_mv
exceeds sweep limit when working with complex numbers
First of all, it worth to note that tolerance We can see this if we run import numpy as np
from numpy.testing import assert_array_almost_equal
import tt
from tt.amen import amen_mv
def test_amen_mv(nosweeps, d=3):
x = tt.rand(2, d)
x += 0.1j * x
a = tt.matrix(tt.rand(4, d))
y = amen_mv(a, x, 1e-12, nswp=nosweeps, verb=0)[0]
y_exact = np.dot(a.full(), x.full(asvector=True))
error = np.linalg.norm(y.full(asvector=True) - y_exact)
print(f'error: {error:e}')
return y Then we set manually random seed and compute matvecs for 10 sweeps and 11 sweeps. np.random.seed(42)
y_curr = test_amen_mv(10)
np.random.seed(42)
y_next = test_amen_mv(11) We do not see difference in dense output. Resulting vector are the same. assert_array_almost_equal(y_curr.full(), y_next.full()) # Ok However, cores could change significant. def get_cores(self: tt.vector) -> np.ndarray:
"""Tuple of views on TT-cores. Each element in the list is a view on
underlying buffer.
"""
offset = 0
cores = []
ranks = tuple(self.r.tolist())
for core_shape in zip(ranks[:-1], self.n, ranks[1:]):
core_size = np.prod(core_shape)
core = self.core[offset:offset + core_size]
cores.append(core.reshape(core_shape, order='F'))
offset += core_size
return cores
cores_curr = get_cores(y_curr)[::-1]
cores_next = get_cores(y_next)[::-1]
for i, (core_curr, core_next) in enumerate(zip(cores_curr, cores_next)):
print(f'core_curr[{i}] =\n')
print(core_curr.squeeze())
print()
print(f'core_next[{i}] =\n')
print(core_next.squeeze())
print()
assert_array_almost_equal(core_curr, core_next) The absolute difference in this example is about 1.4 and relative is about 1.5, i.e. elements are significantly differ. This is what are the first TT-cores.
This is quite usual situation with ALS-like method in complex arithmetics, I guess. We probably can add another stopping criterion. UPD May be @kharyuk has some thoughts. |
@daskol thank you for the quick response! Now it's clear why such behavior occurs. Another stopping criterion would be a great improvement, in my opinion. Otherwise, the method's behavior isn't quite intuitive. And, in my case, |
amen_mv
weirdly exceeds number of sweeps limit when working with some complex-valued matrices and vectors.Here is the simplest example I could find:
This results in:
The method converges quickly, though, as the error is negligible even if
nswp=1
:The text was updated successfully, but these errors were encountered: