Nonnegative tensor decomposition example using Tensorly

时间:2019-04-17 01:33:54

标签: python tensorflow tensor

I am very new to tensor and also to tensorly Library.I come across one of the best examples of tensor decomposition on jeankossaifi but I need an example of tensorly function non_negative_tucker() for tensor decomposition by extending the example on the link above (for Olivetti dataset).

1 个答案:

答案 0 :(得分:0)

界面与robust_pca界面几乎相同。

让我们创建一个随机的示例张量X

import tensorly as tl
import numpy as np

X = tl.tensor(np.random.random((10, 11, 12)))

您将如下应用稳健的张量PCA:

from tensorly.decomposition import robust_pca

D, E = robust_pca(X)

这为您提供了一个低阶张量D和一个稀疏张量E,从而使D + E = X(大约)。

相反,非负Tucker会为您提供非负核心和一些非负因素。请注意,现在您还必须为分解指定一个等级。

from tensorly.decomposition import non_negative_tucker
core, factors = non_negative_tucker(X, rank=(12, 12, 12), n_iter_max=1000)

您可以使用这些重建张量并检查重建错误:

reconstruction = tl.tucker_to_tensor(core, factors)
error = tl.norm(reconstruction - X)/tl.norm(X)

您可以查看该功能的API page