I use the below code for parafac decomposition in scikit-tensor. This code is a sample for scikit-tensor.
from sktensor import dtensor, cp_als, parafac2, tucker_hooi
import numpy
import sktensor
T=dtensor(numpy.arange(100).reshape(2, 5,10))
print (type(T))
P, F, D, A, fit, itr, exectimes = parafac2.parafac2(T, 3, init=3, ma_iter=5, conv= 4)
When I run this code, the output is...
Traceback (most recent call last):
File "C:/Users/meghdad/PycharmProjects/tensorInPython/dtensor1.py", line 17, in <module>
P, F, D, A, fit, itr, exectimes = parafac2.parafac2(T, 3, init=3, ma_iter=5, conv= 4)
File "C:\Anaconda3\lib\site-packages\scikit_tensor-0.1-py3.5.egg\sktensor\parafac2.py", line 50, in parafac2
File "C:\Anaconda3\lib\site-packages\scikit_tensor-0.1-py3.5.egg\sktensor\parafac2.py", line 113, in __init
UnboundLocalError: local variable 'F' referenced before assignment
What do I do to resolve this error?
I looked at the source code for version 0.1. The only valid values for the "init" keyword are "nvecs" or "random". The default is "nvecs". If you try either of those you will get rid of your error:
P, F, D, A, fit, itr, exectimes = parafac2.parafac2(T, 3, init='nvecs', ma_iter=5, conv= 4)
Or
P, F, D, A, fit, itr, exectimes = parafac2.parafac2(T, 3, init='random', ma_iter=5, conv= 4)