tensorly.decomposition
.CP_NN_HALS
- class CP_NN_HALS(rank, n_iter_max=100, init='svd', svd='truncated_svd', tol=1e-07, sparsity_coefficients=None, fixed_modes=None, nn_modes='all', exact=False, verbose=False, normalize_factors=False, cvg_criterion='abs_rec_error', random_state=None)[source]
Non-Negative Candecomp-Parafac decomposition via Alternating-Least Square
Computes a rank-rank decomposition of tensor [1] such that:
``tensor = [|weights; factors[0], ..., factors[-1] |]``.
- Parameters:
- tensorndarray
- rankint
Number of components.
- n_iter_maxint
Maximum number of iteration
- init{‘svd’, ‘random’}, optional
Type of factor matrix initialization. See initialize_factors.
- svdstr, default is ‘truncated_svd’
function to use to compute the SVD, acceptable values in tensorly.SVD_FUNS
- normalize_factorsif True, aggregate the weights of each factor in a 1D-tensor
of shape (rank, ), which will contain the norms of the factors
- tolfloat, optional
(Default: 1e-6) Relative reconstruction error tolerance. The algorithm is considered to have found the global minimum when the reconstruction error is less than tol.
- random_state{None, int, np.random.RandomState}
- verboseint, optional
Level of verbosity
- return_errorsbool, optional
Activate return of iteration errors
- maskndarray
array of booleans with the same shape as
tensor
should be 0 where the values are missing and 1 everywhere else. Note: if tensor is sparse, then mask should also be sparse with a fill value of 1 (or True). Allows for missing values [2]- cvg_criterion{‘abs_rec_error’, ‘rec_error’}, optional
Stopping criterion for ALS, works if tol is not None. If ‘rec_error’, ALS stops at current iteration if (previous rec_error - current rec_error) < tol. If ‘abs_rec_error’, ALS terminates when
|previous rec_error - current rec_error| < tol
.- sparsityfloat or int
If sparsity is not None, we approximate tensor as a sum of low_rank_component and sparse_component, where low_rank_component = cp_to_tensor((weights, factors)). sparsity denotes desired fraction or number of non-zero elements in the sparse_component of the tensor.
- fixed_modeslist, default is None
A list of modes for which the initial value is not modified. The last mode cannot be fixed due to error computation.
- svd_mask_repeats: int
If using a tensor with masked values, this initializes using SVD multiple times to remove the effect of these missing values on the initialization.
- Returns:
- CPTensor(weight, factors)
- weights1D array of shape (rank, )
all ones if normalize_factors is False (default), weights of the (normalized) factors otherwise
- factorsList of factors of the CP decomposition element i is of shape
(tensor.shape[i], rank)
sparse_component : nD array of shape tensor.shape. Returns only if sparsity is not None.
- errorslist
A list of reconstruction errors at each iteration of the algorithms.
References
[1]T.G.Kolda and B.W.Bader, “Tensor Decompositions and Applications”, SIAM REVIEW, vol. 51, n. 3, pp. 455-500, 2009.
[2]Tomasi, Giorgio, and Rasmus Bro. “PARAFAC and missing values.” Chemometrics and Intelligent Laboratory Systems 75.2 (2005): 163-180.
[3]R. Bro, “Multi-Way Analysis in the Food Industry: Models, Algorithms, and Applications”, PhD., University of Amsterdam, 1998
- fit_transform(tensor)[source]
Decompose an input tensor
- Parameters:
- tensortensorly tensor
input tensor to decompose
- Returns:
- CPTensor
decomposed tensor