Dense Tensor
Some operations with respect to basic dense tensor, I need to add some latex equations to my document
Functions
#
SAIGtensor.initTensor
— Function.
InitTensor(N, I, D)
create a tensor object, here is some inline math: $\sqrt[n]{1+x+x^2+\ldots}$
Arguments
N
: Int64, dimensionsI
: Array{Int64}, size of each dimensionD
: Array{Float64}, multi-dimension array
Returns
X
: tensor object
Example
julia> N = 5; I = [23, 42, 13, 14, 17]; D = rand(I...)
julia> X = InitTensor(N, I, D)
#
SAIGtensor.matricization
— Function.
Xn = matricization(X::tensor, n::Int64)
unfolding tensor along n dimension
Arguments
X
: tensor, tensor objectn
: Int64, unfolding along n dimension, 1<= n <= N
Returns
Xn
: Array{Float64,2}, matrix
Example
julia> N = 3; I = [3, 4, 2]; D = reshape(collect(1:prod(I)), I...)
julia> X = initTensor(N, I, D)
julia> n = 3
julia> Xn = matricization(X, n)
#
SAIGtensor.unmatricization
— Function.
X = unmatricization(Xn, n, I)
folding an Array back to tensor
Arguments
Xn
: Array{Float64}, the array to be foldedn
: Int64, folding along n dimension, 1<= n <= NI
: Array{Int64}, size of tensor
Returns
X
: tensor
Example
julia> N = 3; I = [3, 4, 2]; D = reshape(collect(1:prod(I)), I[1], prod(I[2:N]))
julia> n = 1; X = unmatricization(D, n, I)
#
SAIGtensor.KRP
— Function.
r = KRP(a1, a2)
Khatri-Rao product a2 ⊙ a1
Arguments
a1
: Array{Float64}, it can be a 1D or 2D arraya2
: Array{Float64}, it can be a 1D or 2D array
Returns
r
: Array{Float64}, it can be a 1D or 2D array
Example
julia> R = 20; m1 = 77; m2 = 33;
julia> a1 = rand(m1,R); a2 = rand(m2,R);
julia> r = KRP(a1, a2)
#
SAIGtensor.recursiveKRP
— Function.
r = recursiveKRP(A)
recursive Khatri-Rao product A[N]⊙...⊙A[1]
Arguments
A
: Array{Array{Float64}}, each element can be 1D or 2D array
Returns
r
: Array{Float64}, it may be a 1D or 2D array
Example
julia> I = [21, 32, 43, 24]; R = 3;
julia> N = length(I);
julia> A = Array{Array{Float64}}(N)
julia> for m = 1 : N
julia> A[m] = rand(I[m], R)
julia> end
julia> r1 = recursiveKRP(A);
#
SAIGtensor.tnorm
— Function.
l = tnorm(X)
compute the frobenius norm of tensor
Arguments
X
: tensor
Returns
l
: the frobenius norm of X
Example
julia> I = [21, 32, 43]; N = 3; D = rand(I...)
julia> l = tnorm(tensor(N, I, D))
#
SAIGtensor.ttv
— Function.
y = ttv(X, v, dims)
compute tensor times a set of vectors
Arguments
X
: tensorv
: Array{Array{Float64,1}}dims
: specification the multiplication on which dimension
Returns
y
: Array{Float64,1}, length is prod(remdims)