Skip to content

SUIlf/trd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub package version License: BSD-3

Table of contents

Introduction

Tensor networks have emerged as the powerful tools for solving the large-scale optimization problems in recent years and tensor ring decomposition has become popular as the building blocks for the complicated tensor networks. trd is a python package implementing tensor ring decomposition, which is licensed under BSD. trd supports several basic tensor operations, four kinds of latent cores optimization algorithms in tensor ring decomposition based on the sequential SVDs, ALS scheme, and block-wise ALS techniques, as well as a tensor completion method based on TR decomposition.

For an overview of tensor ring decompositions please see the following:

Installation

You can install trd using pip.

pip install trd

Dependencies: trd works with Python 3.5 or later. TRDstest depends on NumPy (version >= 1.19)

Usage and Examples

The trd library contains implementations for the following methods:

  • trd.base: implements core tensor operations.
    • unfold: Mode-n unfolding of a tensor.
    • fold: Refolds the Mode-n unfolded tensor.
    • tensor2vec: Vectorization of a tensor.
    • vec2tensor: Reshape the vectorised tensor to tensor.
  • trd.functions: contains utilities for tensor algebra operations.
    • n_mode_product: The n-mode product of a tensor with a matrix.
    • inner_product: The inner product of two tensor with same shape.
    • n_mode_inner_product: The n mode inner product of two tensor.
    • outer_products: The outer product of a list of tensors.
    • kronecker: The Kronecker product of a list of matrices.
    • khatri_rao: The Khatri-Rao product of a list of matrices.
  • trd.decomposition: implements four different algorithms to optimize the latent cores in TR decomposition, and a tensor completion algorithm
    • TRSVD: uses d sequential singular value decomposition (SVD), which is generally efficient in computation due to its non-recursion property and it can approximate an arbitrary tensor as close as possible.
    • TRALS: are based on alternating least squares (ALS) framework.
    • TRALSAR: (ALS with adaptive ranks) is able to adapt TR-ranks during optimization.
    • TRLRF: is a tensor completion algorithm named tensor ring low-rank factors (TRLRF).

The code below shows a simple demo of tensor completion method,

# Completion of a 256*256*3 image by TRLRF
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from trd.functions import gen_W
from trd.decompositions import TRLRF

# Load data
X = (np.array(Image.open('trd/lena.bmp'), dtype='double') / 255)
# The missing rate of the image is set 0.8
mr = 0.8  # missing rate
W = gen_W(X.shape, mr)
# Calling Method of TRLRF
r = 5 * np.ones(3, dtype='int')  # TR-rank
X_completion, _, __ = TRLRF(X, W, r)
plt.figure()
plt.imshow(np.array(X_completion * 255, dtype='uint8'))
plt.show()

Image completion results of TRLRF method Different explanation methods on ImageNet.

More documentation

You can find different examples in the directory examples, they are supplied in the form of Jupyter notebooks:

If you find any bugs or have any other suggestions on how to improve the code then please use the issue tracker on github (https://github.com/SUIlf/trd).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages