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 ???
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 decomposedrank
is the rank of the decomposition for each mode of the tensorinit: {'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]]
core_S
is the core tensor SUx
is the left singular matrix Ux for the mode xTo 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With