Multilinear tensors

Multilinear tensors

using TensorDec

We consider a multi-linear tensor of size 3 x 5 x 4, which is sum of r=4 tensor products of the random column vectors of the matrices A0, B0, C0with weights w0:

r=4
w0 = rand(r)
A0 = rand(3,r)
B0 = rand(5,r)
C0 = rand(4,r)

T0 = tensor(w0, A0, B0, C0)
3×5×4 Array{Float64,3}:
[:, :, 1] =
 0.347299  0.151553    0.114054    0.155983    0.282425 
 0.010721  0.00987083  0.00909818  0.00590759  0.0139975
 0.389758  0.24162     0.203963    0.201205    0.300751 

[:, :, 2] =
 0.328047   0.150379   0.12208    0.142833   0.262686 
 0.0530373  0.0496668  0.0546258  0.0193254  0.0734109
 0.490219   0.341215   0.31404    0.244133   0.393444 

[:, :, 3] =
 0.358308   0.147021   0.115107   0.14935    0.293383 
 0.0626374  0.0587502  0.0648279  0.0224873  0.0878258
 0.385146   0.229846   0.210108   0.170616   0.342252 

[:, :, 4] =
 0.20043    0.0894733  0.0626167  0.0954052  0.17385  
 0.0382902  0.0375343  0.0393505  0.0163238  0.0554182
 0.203668   0.128217   0.106686   0.103265   0.198758

We compute its decomposition:

w, A, B, C = decompose(T0);

We obtain a decomposition of rank 4 with weights:

w
4-element Array{Float64,1}:
 0.30720814696815224
 0.5694221275090653 
 0.9706126355492068 
 0.0400306207408488

The r=4 vectors of norm 1 of the first components of the decomposition are the columns of the matrix A:

A
3×4 Array{Float64,2}:
 0.0956115  0.19154     0.827422    0.603317
 0.638545   0.00713372  0.00592765  0.124732
 0.763622   0.981459    0.561549    0.787687

The r=4 vectors of norm 1 of the second components are the columns of the matrix B:

B
5×4 Array{Float64,2}:
 -0.436806  -0.558735  -0.700754  0.118617 
 -0.419512  -0.489725  -0.259599  0.485964 
 -0.466462  -0.454027  -0.193181  0.0261587
 -0.154209  -0.334743  -0.285791  0.677514 
 -0.625974  -0.360266  -0.567941  0.538572

The r=4 vectors of norm 1 of the third components are the columns of the matrix C:

C
4×4 LinearAlgebra.Adjoint{Float64,Array{Float64,2}}:
 -0.0811061  -0.537059   -0.554383  0.535713 
 -0.575176   -0.788566   -0.484317  0.0169553
 -0.695558   -0.283155   -0.590019  0.0269297
 -0.422839   -0.0977454  -0.331624  0.8438

It corresponds to the tensor $\sum_{i=1}^{r} w_i \, A[:,i] \otimes B[:,i] \otimes C[:,i]$ for $i \in 1:r$:

T = tensor(w, A, B, C)
3×5×4 Array{Float64,3}:
[:, :, 1] =
 0.347299  0.151553    0.114054    0.155983    0.282425 
 0.010721  0.00987083  0.00909818  0.00590759  0.0139975
 0.389758  0.24162     0.203963    0.201205    0.300751 

[:, :, 2] =
 0.328047   0.150379   0.12208    0.142833   0.262686 
 0.0530373  0.0496668  0.0546258  0.0193254  0.0734109
 0.490219   0.341215   0.31404    0.244133   0.393444 

[:, :, 3] =
 0.358308   0.147021   0.115107   0.14935    0.293383 
 0.0626374  0.0587502  0.0648279  0.0224873  0.0878258
 0.385146   0.229846   0.210108   0.170616   0.342252 

[:, :, 4] =
 0.20043    0.0894733  0.0626167  0.0954052  0.17385  
 0.0382902  0.0375343  0.0393505  0.0163238  0.0554182
 0.203668   0.128217   0.106686   0.103265   0.198758

We compute the $L^2$ norm of the difference between $T$ and $T_0$:

using LinearAlgebra
norm(T-T0)
2.5632252009555643e-15