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

Fix complexities #166

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions t3f/riemannian.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,16 @@ def project_matmul(what, where, matrix):
a TensorTrain with the TT-ranks equal 2 * tangent_space_tens.get_tt_ranks()

Complexity:
O(d r_where^3 m) for orthogonalizing the TT-cores of where
O(d r_where^3 m) for orthogonalizing the TT-cores
+O(batch_size d R r_what r_where (n r_what + n m R + m r_where))
d is the number of TT-cores (what.ndims());
r_what is the largest TT-rank of what max(what.get_tt_rank())
r_where is the largest TT-rank of where
matrix is of TT-rank R and of raw-shape (m, m, ..., m) x (n, n, ..., n).
or equivalently
O(d r_where^3 m)
+O(batch_size d R^3 r_what r_where n m R)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O(batch_size d R^2 r_what r_where n m)

given that m r_where < n m R and n r_what < n m R, where
d is the number of TT-cores (what.ndims());
r_what is the largest TT-rank of what (max(what.get_tt_rank()))
r_where is the largest TT-rank of where
matrix is of TT-rank R and of raw-shape (m, m, ..., m) x (n, n, ..., n).
"""

if not isinstance(where, TensorTrain):
Expand Down Expand Up @@ -446,8 +450,8 @@ def project_matmul(what, where, matrix):
tens_core = what.tt_cores[core_idx]
right_tang_core = right_tangent_space_tens.tt_cores[core_idx]
matrix_core = matrix.tt_cores[core_idx]
rhs[core_idx] = tf.einsum('bije,cikf,sdef,sajkd->sabc', matrix_core,
right_tang_core, rhs[core_idx + 1], tens_core)
rhs[core_idx] = tf.einsum('cikf,sdef,bije,sajkd->sabc', right_tang_core,
rhs[core_idx + 1], matrix_core, tens_core)
# Prepare lhs vectors.
# lhs[core_idx] is of size
# batch_size x tangent_tt_ranks[core_idx] x matrix_tt_ranks[core_idx] x tensor_tt_ranks[core_idx]
Expand All @@ -458,8 +462,8 @@ def project_matmul(what, where, matrix):
left_tang_core = left_tangent_space_tens.tt_cores[core_idx]
matrix_core = matrix.tt_cores[core_idx]
# TODO: brutforce order of indices in lhs??
lhs[core_idx + 1] = tf.einsum('bije,aikd,sabc,scjkf->sdef', matrix_core,
left_tang_core, lhs[core_idx], tens_core)
lhs[core_idx + 1] = tf.einsum('aikd,sabc,bije,scjkf->sdef', left_tang_core,
lhs[core_idx], matrix_core, tens_core)

# Left to right sweep.
res_cores_list = []
Expand Down