Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reconstruction of tensor in sktensor/scikit-tensor after decomposition using HOSVD

I am currently factorizing a 3-D tensor like [user,item,tags]=rating. I am using sktensor library in python for decomposition. For ex.

T = np.zeros((3, 4, 2))
T[:, :, 0] = [[ 1,  4,  7, 10], [ 2,  5,  8, 11], [3,  6,  9, 12]]
T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
T = dtensor(T) 
Y = hooi(T, [2, 3, 1], init='nvecs')

Now what is actually function hooi is returning and how to reconstruct the tensor from that ???

like image 340
Suraj Upadhyay Avatar asked Apr 20 '17 02:04

Suraj Upadhyay


1 Answers

First of all, the function tucker_hooi computes the Tucker decomposition of a tensor using Higher-Order Orthogonal Iterations.


The function is the following:

hooi(X, rank, init)

where:

  • X is the tensor to be decomposed
  • rank is the rank of the decomposition for each mode of the tensor
  • init: {'random', 'nvecs'} is the initialization method to use (random or HOSVD)

Example:

from sktensor.tucker import hooi
import numpy as np
from sktensor import dtensor

T = np.zeros((3, 4, 2))
T[:, :, 0] = [[ 1,  4,  7, 10], [ 2,  5,  8, 11], [3,  6,  9, 12]]
T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
T = dtensor(T) 
print(T.shape)
#(3, 4, 2)

Y = hooi(T, [2, 3, 1], init='nvecs')

core_S = Y[0]
core_S = np.array(core_S)
print(core_S.shape)
#(2, 3, 1)

U1 = Y[1][0]
U2 = Y[1][1]
U3 = Y[1][2]

print(U1)

[[ 0.54043979  0.7357025 ]
 [ 0.57659506  0.02952065]
 [ 0.61275033 -0.67666119]]

Interpretation of results

  • core_S is the core tensor S
  • Ux is the left singular matrix Ux for the mode x

Visualization

enter image description here


EDIT 1:

To reconstruct the original tensor T do this:

from sktensor.core import ttm

core, U = hooi(T,rank= [2, 3, 1])
Trec = ttm(core, U)

print(Trec.shape)
#(3, 4, 2)

Source: https://github.com/mnick/scikit-tensor/blob/master/sktensor/tests/test_tucker_hooi.py

like image 183
seralouk Avatar answered Sep 29 '22 12:09

seralouk