Package: tensorlearn
TensorLearnTensorLearn is a Python library distributed onPypito implement
tensor learning methods.This is a project under development. Yet, the available methods are final and functional. The requirment isNumpy.InstallationUse the package managerpipto install tensorlearn in Python.pipinstalltensorlearnmethodsDecomposition Methodsauto_rank_ttcp_als_rand_initTensor Operations for Tensor-Traintt_to_tensortt_compression_ratioTensor Operations for CANDECOMP/PARAFAC (CP)cp_to_tensorcp_compression_ratioTensor Operationstensor_resizeunfoldtensor_frobenius_normMatrix Operationserror_truncated_svdcolumn_wise_kroneckerauto_rank_tttensorlearn.auto_rank_tt(tensor,epsilon)This implementation oftensor-train decompositiondetermines the ranks automatically based on a given error bound according toOseledets (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 pagetensor-train decomposition.Argumentstensor < array >: The given tensor to be decomposed.epsilon < float >:The error bound of decompositionin the range [0,1].ReturnTT 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.Examplecp_als_rand_inittensorlearn.cp_als_rand_init(tensor,rank,iteration,random_seed=None)This is an implementation ofCANDECOMP/PARAFAC (CP) decompositionusingalternating least squares (ALS) algorithmwith random initialization of factors.Argumentstensor < array >: the given tensor to be decomposedrank < int >: number of ranksiterations < int >: the number of iterations of the ALS algorithmrandom_seed < int >: the seed of random number generator for random initialization of the factor matricesReturnweights < array >: the vector of normalization weights (lambda) in CP decompositionfactors < list of arrays >: factor matrices of the CP decompositionExamplett_to_tensortensorlearn.tt_to_tensor(factors)Returns the full tensor given the TT factorsArgumentsfactors < list of numpy arrays >: TT factorsReturnfull tensor < numpy array >Examplett_compression_ratiotensorlearn.tt_compression_ratio(factors)Returnsdata compression ratiofortensor-train decompostionArgumentsfactors < list of numpy arrays >: TT factorsReturnCompression ratio < float >Examplecp_to_tensorReturns the full tensor given the CP factor matrices and weightstensorlearn.cp_to_tensor(weights,factors)Argumentsweights < array >: the vector of normalization weights (lambda) in CP decompositionfactors < list of arrays >: factor matrices of the CP decompositionReturnfull tensor < array >Examplecp_compression_ratioReturnsdata compression ratioforCP- decompostiontensorlearn.cp_compression_ratio(weights,factors)Argumentsweights < array >: the vector of normalization weights (lambda) in CP decompositionfactors < list of arrays >: factor matrices of the CP decompositionReturnCompression ratio < float >Exampletensor_resizetensorlearn.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 tonumpy.ndarray.resize()Argumentstensor < array >: the given tensornew_shape < tuple >: new shapeReturntensor < array >: tensor with new given shapeunfoldtensorlearn.unfold(tensor,n)Unfold the tensor with respect to dimension n.Argumentstensor < array >: tensor to be unfoldedn < int >: dimension based on which the tensor is unfoldedReturnmatrix < array >: unfolded tensor with respect to dimension ntensor_frobenius_normtensorlearn.tensor_frobenius_norm(tensor)Calculates thefrobenius normof the given tensor.Argumentstensor < array >: the given tensorReturnfrobenius norm < float >Exampleerror_truncated_svdtensorlearn.error_truncated_svd(x,error)This method conducts acompact svdand returnsigma (error)-truncated SVDof a given matrix. This is an implementation usingnumpy.linalg.svdwith full_matrices=False. This method is used inTT-SVD algorithminauto_rank_tt.Argumentsx < 2D array >: the given matrix to be decomposederror < float >: the given error in the range [0,1]Returnr, u, s, vh < int, numpy array, numpy array, numpy array >column_wise_kroneckertensorlearn.column_wise_kronecker(a,b)Returns thecolumn wise Kronecker product (Sometimes known as Khatri Rao)of two given matrices.Argumentsa,b < 2D array >: the given matricesReturncolumn wise Kronecker product < array >