Module act_many: operations with a set of TT-tensors¶
Package teneva, module act_many: operations with a set of TT-tensors.
This module contains the basic operations with a set of multiple TT-tensors (Y1, Y2, …), including “add_many” and “outer_many”.
- teneva.act_many.add_many(Y_many, e=1e-10, r=1000000000000.0, trunc_freq=15)[source]¶
Compute Y1 + Y2 + … + Ym in the TT-format.
- Parameters:
Y_many (list) – the list of TT-tensors (some of them may be int/float).
e (float) – desired approximation accuracy. The result will be truncated to this accuracy.
r (int) – maximum rank of the result.
trunc_freq (int) – frequency of intermediate summation result truncation.
- Returns:
TT-tensor, which represents the element wise sum of all given tensors. If all the tensors are numbers, then result will be int/float.
- Return type:
list
Examples:
# 10 random TT-tensors with TT-rank 2: Y_all = [teneva.rand([5]*10, 2) for _ in range(10)] # Compute the sum: Y = teneva.add_many(Y_all, e=1.E-4, r=50, trunc_freq=2) # Show the result: teneva.show(Y) # >>> ---------------------------------------- # >>> Output: # TT-tensor 10D : |5| |5| |5| |5| |5| |5| |5| |5| |5| |5| # <rank> = 17.9 : \5/ \20/ \20/ \20/ \20/ \20/ \20/ \20/ \5/ #
This function also supports float arguments:
Y_all = [ 42., teneva.rand([5]*10, 2), 33., teneva.rand([5]*10, 4) ] Y = teneva.add_many(Y_all, e=1.E-4, r=50, trunc_freq=2) teneva.show(Y) # >>> ---------------------------------------- # >>> Output: # TT-tensor 10D : |5| |5| |5| |5| |5| |5| |5| |5| |5| |5| # <rank> = 6.7 : \5/ \7/ \7/ \7/ \7/ \7/ \7/ \7/ \5/ #
If all arguments are numbers, then function returns the sum of numbers:
Y_all = [10., 20., 2., 10.] Y = teneva.add_many(Y_all, e=1.E-4, r=50, trunc_freq=2) print(Y) # >>> ---------------------------------------- # >>> Output: # 42.0 #
- teneva.act_many.outer_many(Y_many)[source]¶
Compute outer product of given TT-tensors.
- Parameters:
Y_many (list) – list of TT-tensors.
- Returns:
TT-tensor, which is the outer product of given TT-tensors.
- Return type:
list
Note
See also “outer” function, which computes outer kronecker product of two given TT-tensors.
Examples:
Y1 = teneva.rand([4]*5, 2) # 5-dim random TT-tensor with TT-rank 2 Y2 = teneva.rand([3]*5, 3) # 5-dim random TT-tensor with TT-rank 3 Y3 = teneva.rand([2]*5, 4) # 5-dim random TT-tensor with TT-rank 4
Y = teneva.outer_many([Y1, Y2, Y3]) # Compute the outer product teneva.show(Y) # Print the resulting TT-tensor # >>> ---------------------------------------- # >>> Output: # TT-tensor 15D : |4| |4| |4| |4| |4| |3| |3| |3| |3| |3| |2| |2| |2| |2| |2| # <rank> = 2.6 : \2/ \2/ \2/ \2/ \1/ \3/ \3/ \3/ \3/ \1/ \4/ \4/ \4/ \4/ #
Y1_full = teneva.full(Y1) # Compute tensors in the full format Y2_full = teneva.full(Y2) # to check the result Y3_full = teneva.full(Y3) Y_full = teneva.full(Y) Z_full = np.tensordot(Y1_full, Y2_full, 0) Z_full = np.tensordot(Z_full, Y3_full, 0) e = np.linalg.norm(Y_full - Z_full) # Compute error for TT-tensor vs full tensor e /= np.linalg.norm(Z_full) # print(f'Error : {e:-8.2e}') # Rel. error for TT-tensor vs full tensor # >>> ---------------------------------------- # >>> Output: # Error : 3.61e-16 #