TensorLearn is a Python library distributed on Pypi to implement tensor learning methods.
This is a project under development. Yet, the available methods are functional. The requirment is Numpy.
Use the package manager pip to install tensorlearn in Python.
pip install tensorlearn
-
Tensor Train (auto_rank_tt)
-
CANDECOMP/PARAFAC (cp_als_rand_init)
-
Tucker (tucker_hosvd)
tensorlearn.auto_rank_tt(tensor, epsilon)
This implementation of tensor-train decomposition determines the ranks automatically based on a given error bound according to Oseledets (2011). Therefore the user does not need to specify the ranks. Instead the user specifies an upper error bound (epsilon) which bounds the error of the decomposition. For more information and details please see the page tensor-train decomposition.
-
tensor < array >: The given tensor to be decomposed.
-
epsilon < float >: The error bound of decomposition in the range [0,1].
- TT factors < list of arrays >: The list includes numpy arrays of factors (or TT cores) according to TT decomposition. Length of the list equals the dimension of the given tensor to be decomposed.
tensorlearn.cp_als_rand_init(tensor, rank, iteration, random_seed=None)
This is an implementation of CANDECOMP/PARAFAC (CP) decomposition using alternating least squares (ALS) algorithm with random initialization of factors.
-
tensor < array >: the given tensor to be decomposed
-
rank < int >: number of ranks
-
iterations < int >: the number of iterations of the ALS algorithm
-
random_seed < int >: the seed of random number generator for random initialization of the factor matrices
-
weights < array >: the vector of normalization weights (lambda) in CP decomposition
-
factors < list of arrays >: factor matrices of the CP decomposition
tensorlearn.tucker_hosvd(tensor, epsilon)
This implementation of Tucker decomposition determines the rank automatically based on a given error bound using HOSVD algorithm. Therefore the user does not need to specify the rank. Instead the user specifies an upper error bound (epsilon) which bounds the error of the decomposition uisng Frobenius norm.
-
tensor < array >: The given tensor to be decomposed.
-
epsilon < float >: The error bound of decomposition in the range [0,1].
-
core factor < array >: The core factor of Tucker decomposition
-
factor matrices < list of arrays >: The factor matrices
tensorlearn.tt_to_tensor(factors)
Returns the full tensor given the TT factors
- factors < list of numpy arrays >: TT factors
- full tensor < numpy array >
tensorlearn.tt_compression_ratio(factors)
Returns data compression ratio for tensor-train decompostion
- factors < list of numpy arrays >: TT factors
- Compression ratio < float >
Returns the full tensor given the CP factor matrices and weights
tensorlearn.cp_to_tensor(weights, factors)
-
weights < array >: the vector of normalization weights (lambda) in CP decomposition
-
factors < list of arrays >: factor matrices of the CP decomposition
- full tensor < array >
Returns data compression ratio for CP- decompostion
tensorlearn.cp_compression_ratio(weights, factors)
-
weights < array >: the vector of normalization weights (lambda) in CP decomposition
-
factors < list of arrays >: factor matrices of the CP decomposition
- Compression ratio < float >
Returns the full tensor given the tucker factor core and factor matrices
tensorlearn.tucker_to_tensor(core_factor, factor_matrices)
-
core_factor < array >: the core factor of the Tucker format
-
factors < list of arrays >: factor matrices of the Tucker format
- full tensor < array >
Returns data compression ratio for tucker decomposition.
tensorlearn.tucker_compression_ratio(core_factor, factor_matrices)
-
core_factor < array >: the core factor of the Tucker format
-
factors < list of arrays >: factor matrices of the Tucker format
- Compression ratio < float >
tensorlearn.tensor_resize(tensor, new_shape)
This method reshapes the given tensor to a new shape. The new size must be bigger than or equal to the original shape. If the new shape results in a tensor of greater size (number of elements) the tensor fills with zeros. This works similar to numpy.ndarray.resize()
-
tensor < array >: the given tensor
-
new_shape < tuple >: new shape
- tensor < array >: tensor with new given shape
tensorlearn.unfold(tensor, n)
Unfold the tensor with respect to dimension n.
-
tensor < array >: tensor to be unfolded
-
n < int >: dimension based on which the tensor is unfolded
- matrix < array >: unfolded tensor with respect to dimension n
tensorlearn.tensor_frobenius_norm(tensor)
Calculates the frobenius norm of the given tensor.
- tensor < array >: the given tensor
- frobenius norm < float >
tensorlearn.mode_n_product(tensor, matrix, n)
Return product of a tensor by a matrix at mode n.
-
tensor < array >: the given tensor
-
matrix <2D array>: the given matrix
-
n < integer >: mode of tensor
- tensor < array >: tensor product
tensorlearn.error_truncated_svd(x, error)
This method conducts a compact svd and return sigma (error)-truncated SVD of a given matrix. This is an implementation using numpy.linalg.svd with full_matrices=False.
-
x < 2D array >: the given matrix to be decomposed
-
error < float >: the given error (equal to the norm of the error matrix)
- r, u, s, vh < int, numpy array, numpy array, numpy array >
tensorlearn.column_wise_kronecker(a, b)
Returns the column wise Kronecker product (Sometimes known as Khatri Rao) of two given matrices.
- a,b < 2D array >: the given matrices
- column wise Kronecker product < array >