TensorToolbox

Julia package for tensors as multidimensional arrays, with functionalty within Tucker format, Kruskal (CP) format, Hierarchical Tucker format and Tensor Train format.

https://github.com/lanaperisa/tensortoolbox.jl

Science Score: 64.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    1 of 6 committers (16.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (6.7%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Julia package for tensors as multidimensional arrays, with functionalty within Tucker format, Kruskal (CP) format, Hierarchical Tucker format and Tensor Train format.

Basic Info
  • Host: GitHub
  • Owner: lanaperisa
  • License: other
  • Language: Julia
  • Default Branch: master
  • Homepage:
  • Size: 886 KB
Statistics
  • Stars: 65
  • Watchers: 6
  • Forks: 9
  • Open Issues: 3
  • Releases: 14
Created almost 9 years ago · Last pushed almost 3 years ago
Metadata Files
Readme License Citation

README.md

TensorToolbox.jl

Build Status

DOI

Julia package for tensors. Includes functionality for - dense tensors, - tensors in Tucker format, - tensors in Kruskal (CP) format, - tensors in Hierarchical Tucker format, - tensors in Tensor Train format (work in progress).

Follows the functionality of MATLAB Tensor toolbox and Hierarchical Tucker Toolbox.

Additionally, it contains algorithms from the paper Recompression of Hadamard Products of Tensors in Tucker Format by D. Kressner and L. Periša.

Note: As of 2023, the package will not be updated anymore.

Basics

Start with julia using TensorToolbox

Define tensor as multidimensional array and calculate its norm: julia X=rand(4,3,2) norm(X) Create identity and diagonal tensor: julia Id=neye(2,2,2) D=diagt([1,2,3,4]) For two tensors of same size calculate their inner product: julia X=rand(3,3,3,3);Y=rand(3,3,3,3); innerprod(X,Y) Matricization of a tensor: julia X=rand(4,3,2);n=1; A=tenmat(X,n) #by mode n B=tenmat(X,row=[2,1],col=3) #by row modes [2,1] and column mode 3 Fold matrix back to tensor: julia X=matten(A,n,[4,3,2]) # by mode n X=matten(B,[2,1],[3],[4,3,2]) # by row modes [2,1] and column mode 3 n-mode product of a tensor and a matrix or an array of matrices: julia X=rand(5,4,3); A=[rand(2,5),rand(2,4),rand(2,3)]; ttm(X,A[1],1) #X times A[1] by mode 1 ttm(X,[A[1],A[2]],[1,2]) #X times A[1] by mode 1 and times A[2] by mode 2; same as ttm(X,A,-3) ttm(X,A) #X times matrices from A by each mode n-mode (vector) product of a tensor and a vector or an array of vectors: julia X=rand(5,4,3); V=[rand(5),rand(4),rand(3)]; ttv(X,V[1],1) #X times V[1] by mode 1 ttv(X,[V[1],V[2]],[1,2]) #X times V[1] by mode 1 and times V[2] by mode 2; same as ttm(X,V,-3) ttv(X,V) #X times vectors from V by each mode Outer product of two tensors: julia X=rand(5,4,3,2);Y=rand(2,3,4); ttt(X,Y) Kronecker product of two tensors (straightforward generalization of Kronecker product of matrices): julia X=rand(5,4,3);Y=rand(2,2,2); tkron(X,Y) The n-rank and the mutlilinear rank of a tensor: julia X=rand(5,4,3); n=2; nrank(X,n) mrank(X) The HOSVD: julia X=rand(5,4,3); hosvd(X) #same as hosvd(X,eps_abs=1e-8) hosvd(X,eps_abs=1e-6) #discard singular values lower than 1e-5 hosvd(X,eps_rel=1e-3) #discard singular values lower than 1e-3*sigma_{max} hosvd(X,reqrank=[2,2,2]) The CP decomposition: julia X=rand(5,4,3); R=3; #number of components cp_als(X,R) #same as cp_als(X,R,init="rand",dimorder=1:ndims(X)) cp_als(X,R,init=[rand(5,3),rand(4,3),rand(3,3)]) #initialize factor matrices cp_als(X,R,init="nvecs",dimorder=[2,1,3])

Tensors in Tucker format

Define tensor in Tucker format by its core tensor and factor matrices: julia F=rand(5,4,3); A=[rand(6,5),rand(6,4),rand(6,3)]; ttensor(F,A) Get Tucker format of a tensor by using HOSVD: julia X=rand(8,9,7); hosvd(X) hosvd(X,reqrank=[3,3,3]) #HOSVD with predefined multilinear rank Create random tensor in Tucker format of size 5x4x3 and mulilinear rank (2,2,2): julia X=randttensor([5,4,3],[2,2,2]) Basic functions: julia size(X) coresize(X) ndims(X) norm(X) full(X) #Creates full tensor out of Tucker format reorth(X) #Orthogonalize factor matrices permutedims(X,[2,1,3]) n-mode matricization of a tensor in Tucker format: julia n=1; tenmat(X,n) Basic operations: julia X=randttensor([5,4,3],[2,2,2]);Y=randttensor([5,4,3],[3,2,1]); innerprod(X,Y) X+Y X-Y X==Y #same as isequal(X,Y) 3*X #same as mtimes(3,X) n-mode product of a tensor in Tucker format and a matrix or an array of matrices: julia X=randttensor([5,4,3],[2,2,2]); A=[rand(2,5),rand(2,4),rand(2,3)]; ttm(X,A[1],1) #X times A[1] by mode 1 ttm(X,[A[1],A[2]],[1,2]) #X times A[1] by mode 1 and times A[2] by mode 2; same as ttm(X,A,-3) ttm(X,A) #X times matrices from A by each mode n-mode (vector) product of a tensor in Tucker format and a vector or an array of vectors: julia X=randttensor([5,4,3],[2,2,2]); V=[rand(5),rand(4),rand(3)]; ttv(X,V[1],1) #X times V[1] by mode 1 ttv(X,[V[1],V[2]],[1,2]) #X times V[1] by mode 1 and times V[2] by mode 2; same as ttm(X,V,-3) ttv(X,V) #X times vectors from V by each mode The n-rank and the mutlilinear rank of a tensor in Tucker format: julia X=randttensor([9,8,7],[5,4,3]); n=2; nrank(X,n) mrank(X) HOSVD of a tensor in Tucker format: julia X=randttensor([6,7,5],[4,4,4]); hosvd(X) #same as hosvd(X,eps_abs=1e-8) hosvd(X,eps_abs=1e-6) #discard singular values lower than 1e-5 hosvd(X,eps_rel=1e-3) #discard singular values lower than 1e-3*sigma_{max} hosvd(X,reqrank=[3,3,3]) #HOSVD with predefined multilinear rank The CP decomposition: julia X=randttensor([6,7,5],[4,4,4]); R=3; #number of components cp_als(X,R) #same as cp_als(X,R,init="rand",dimorder=1:ndims(X)) cp_als(X,R,init=[rand(6,3),rand(7,3),rand(5,3)]) #initialize factor matrices cp_als(X,R,init="nvecs",dimorder=[2,1,3])

Tensors in Kruskal format

Define tensor in Kruskal format by its factor matrices (and vector of weights): julia lambda=rand(3) A=[rand(5,3),rand(4,3),rand(3,3)]; ktensor(A) ktensor(lambda,A) Create random tensor in Kruskal format of size 5x4x3 and with 2 components: julia X=randktensor([5,4,3],2) Basic functions: julia size(X) ndims(X) norm(X) full(X) #Creates full tensor out of Kruskal format permutedims(X,[2,1,3]) ncomponents(X) #Number of components n-mode matricization of a tensor in Kruskal format: julia n=1; tenmat(X,n) Basic operations: julia X=randktensor([5,4,3],2);Y=randktensor([5,4,3],3); innerprod(X,Y) X+Y X-Y X==Y #same as isequal(X,Y) 3*X #same as mtimes(3,X) n-mode product of a tensor in Kruskal format and a matrix or an array of matrices: julia X=randktensor([5,4,3],2); A=[rand(2,5),rand(2,4),rand(2,3)]; ttm(X,A[1],1) #X times A[1] by mode 1 ttm(X,[A[1],A[2]],[1,2]) #X times A[1] by mode 1 and times A[2] by mode 2; same as ttm(X,A,-3) ttm(X,A) #X times matrices from A by each mode n-mode (vector) product of a tensor in Kruskal format and a vector or an array of vectors: julia X=randktensor([5,4,3],2); V=[rand(5),rand(4),rand(3)]; ttv(X,V[1],1) #X times V[1] by mode 1 ttv(X,[V[1],V[2]],[1,2]) #X times V[1] by mode 1 and times V[2] by mode 2; same as ttm(X,V,-3) ttv(X,V) #X times vectors from V by each mode Arrange the rank-1 components of a tensor in Kruskal format: julia X=randktensor([6,5,4,3],3); arrange(X) arrange!(X) Fix sign ambiguity of a tensor in Kruskal format: julia X=randktensor([6,5,4,3,4],3); fixsigns(X) fixsigns!(X) Distribute weights a tensor in Kruskal format to a specific mode: julia X=randktensor([3,3,3],3); n=2; redistribute(X,n) redistribute!(X,n) The CP decomposition: julia X=randktensor([6,7,5],4); R=3; #number of components cp_als(X,R) #same as cp_als(X,R,init="rand",dimorder=1:ndims(X)) cp_als(X,R,init=[rand(6,3),rand(7,3),rand(5,3)]) #initialize factor matrices cp_als(X,R,init="nvecs",dimorder=[2,1,3])

Tensors in Hierarchical Tucker format

Define tensor in Hierarchical Tucker format by dimensional tree T, its transfer tensors and factor matrices: julia T=dimtree(3) B=[rand(2,3,1),rand(4,3,2)] A=[rand(5,4),rand(4,3),rand(3,3)] htensor(T,B,A) Define tensor in Hierarchical Tucker format by dimensional tree T, its transfer tensors and factor matrices: julia T=dimtree(3) B=[rand(2,3,1),rand(4,3,2)] A=[rand(5,4),rand(4,3),rand(3,3)] htensor(T,B,A) Get Tucker format of a tensor by using htrunc: julia X=rand(8,9,7); htrunc(X) htrunc(X,maxrank=3) #hrunc with defined maximal rank Create random tensor in Hierarchical Tucker format of size 5x4x3: julia X=randhtensor([5,4,3]) Basic functions: julia size(X) ndims(X) norm(X) full(X) #Creates full tensor out of Hierarchial Tucker format reorth(X) #Orthogonalize factor matrices Basic operations: julia X=randhtensor([5,4,3]);Y=randhtensor([5,4,3]); innerprod(X,Y) X+Y X-Y X==Y #same as isequal(X,Y) 3*X #same as mtimes(3,X) n-mode product of a tensor in Hierarchical Tucker format and a matrix or an array of matrices: julia X=randhtensor([5,4,3]); A=[rand(2,5),rand(2,4),rand(2,3)]; ttm(X,A[1],1) #X times A[1] by mode 1 ttm(X,[A[1],A[2]],[1,2]) #X times A[1] by mode 1 and times A[2] by mode 2; same as ttm(X,A,-3) ttm(X,A) #X times matrices from A by each mode n-mode (vector) product of a tensor in Hierarchical Tucker format and a vector or an array of vectors: julia X=randhtensor([5,4,3]); V=[rand(5),rand(4),rand(3)]; ttv(X,V[1],1) #X times V[1] by mode 1 ttv(X,[V[1],V[2]],[1,2]) #X times V[1] by mode 1 and times V[2] by mode 2; same as ttm(X,V,-3) ttv(X,V) #X times vectors from V by each mode The h-rank of a tensor in Hierarchical Tucker format: julia X=htrunc(rand(9,8,7),maxrank=2) hrank(X)

Tensors in Tensor Train format

Define tensor in TT format by its core tensors: julia G=CoreCell(undef,3) G[1]=rand(1,4,3) G[2]=rand(3,6,4) G[3]=rand(4,3,1) X=TTtensor(G) Get TT format of a tensor by using TTsvd: julia X=rand(5,4,3,2) TTsvd(X) TTsvd(X,reqrank=[2,2,2]) Create random TT tensor of size 5x4x3 and TT-rank (2,2): julia X=randTTtensor([5,4,3],[2,2]) Basic functions:: julia size(X) TTrank(X) ndims(X) norm(X) full(X) #Creates full tensor out of Tucker format reorth(X) Basic operations: ```julia X=randTTtensor([5,4,3],[2,2]) Y=randTTtensor([5,4,3],[3,3])

innerprod(X,Y) X+Y X-Y 3*X TTsvd of a TT tensor: julia X=randTTtensor([7,6,5],[5,4]) TTsvd(X,reqrank=[3,3]) ```

Citation (CITATION.cff)

cff-version: 1.0.0
message: If you use this software, please cite it as below.
authors:
  - family-names: Periša
    given-names: Lana
    orcid: https://orcid.org/0000-0002-9224-6619
title: "Julia Tensor Toolbox"
version: 1.0.2
doi: 10.5281/zenodo.3540787
date-released: 2019-11-13

GitHub Events

Total
  • Issues event: 1
  • Fork event: 1
Last Year
  • Issues event: 1
  • Fork event: 1

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 154
  • Total Committers: 6
  • Avg Commits per committer: 25.667
  • Development Distribution Score (DDS): 0.26
Top Committers
Name Email Commits
Lana Periša l****a@f****r 114
Lana Perisa p****a@m****h 32
Lana Periša l****a@g****m 4
Lana Periša l****a@j****r 2
Alex Arslan a****n@c****t 1
Julia TagBot 5****t@u****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 2 years ago

All Time
  • Total issues: 11
  • Total pull requests: 5
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 4 days
  • Total issue authors: 10
  • Total pull request authors: 5
  • Average comments per issue: 3.18
  • Average comments per pull request: 1.4
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • fhenneke (2)
  • yijun2020 (1)
  • BoianAlexandrov (1)
  • Schroedingberg (1)
  • NS2LPS (1)
  • kevin-w-li (1)
  • dannys4 (1)
  • NicolasL-S (1)
  • raphaelchinchilla (1)
  • zsteve (1)
  • attobot (1)
Pull Request Authors
  • ararslan (1)
  • bovine3dom (1)
  • lanaperisa (1)
  • JuliaTagBot (1)
  • bkmgit (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • julia 14 total
  • Total dependent packages: 3
  • Total dependent repositories: 3
  • Total versions: 4
juliahub.com: TensorToolbox

Julia package for tensors as multidimensional arrays, with functionalty within Tucker format, Kruskal (CP) format, Hierarchical Tucker format and Tensor Train format.

  • Versions: 4
  • Dependent Packages: 3
  • Dependent Repositories: 3
  • Downloads: 14 Total
Rankings
Dependent repos count: 6.9%
Average: 11.7%
Stargazers count: 11.9%
Dependent packages count: 13.5%
Forks count: 14.4%
Last synced: 7 months ago