Module vectors: collection of explicit useful QTT-vectors¶
Package teneva, module vectors: various useful QTT-vectors.
This module contains the collection of functions for explicit construction of various useful QTT-vectors (delta function and others).
- teneva.vectors.vector_delta(q, i, v=1.0)[source]¶
Build QTT-vector that is zero everywhere except for a given index.
Construct a QTT-vector of the length 2^q with only one nonzero element in position i, that is equal to a given value v.
- Parameters:
q (int) – quantization level. The resulting vector will have the total length 2^q.
i (int) – the index for nonzero element (< 2^q). Note that “negative index notation” is supported.
v (float) – the value of the vector at index i.
- Returns:
TT-tensor representing the QTT-vector.
- Return type:
list
Examples:
q = 5 # Quantization level (the size is 2^q) i = 2 # The index for nonzero element v = 42. # The value of the vector at index "i" Y = teneva.vector_delta(q, i, v) # Build QTT-vector teneva.show(Y) # >>> ---------------------------------------- # >>> Output: # TT-tensor 5D : |2| |2| |2| |2| |2| # <rank> = 1.0 : \1/ \1/ \1/ \1/ #
Let check the result:
Y_full = teneva.full(Y) # Transform QTT-vector to full format Y_full = Y_full.flatten('F') i_max = np.argmax(Y_full) # Find index and value for max y_max = Y_full[i_max] # Find number of nonzero vector items: s = len([y for y in Y_full if abs(y) > 1.E-10]) print(f'The max value index :', i_max) print(f'The max value :', y_max) print(f'Number of nonzero items :', s) # >>> ---------------------------------------- # >>> Output: # The max value index : 2 # The max value : 42.0 # Number of nonzero items : 1 #
We can also build some big QTT-vector by “delta” function and check the norm of the result:
q = 100 # Quantization level (the size is 2^q) i = 99 # The index for nonzero element v = 42. # The value of the vector at index "i" Y = teneva.vector_delta(q, i, v) # Build QTT-vector teneva.norm(Y) # >>> ---------------------------------------- # >>> Output: # 42.0 #