tensorly.contrib.sparse.decomposition.parafac
- parafac(tensor, rank, n_iter_max=100, init='svd', svd='truncated_svd', normalize_factors=False, orthogonalise=False, tol=1e-08, random_state=None, verbose=0, return_errors=False, sparsity=None, l2_reg=0, mask=None, cvg_criterion='abs_rec_error', fixed_modes=None, svd_mask_repeats=5, linesearch=False, callback=None)
CANDECOMP/PARAFAC decomposition via alternating least squares (ALS) 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’, CPTensor}, optional
Type of factor matrix initialization. If a CPTensor is passed, this is directly used for initalization. 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.
- linesearchbool, default is False
Whether to perform line search as proposed by Bro [3].
- Returns:
- CPTensor(weight, factors)
weights : 1D array of shape (rank, )
all ones if normalize_factors is False (default)
weights of the (normalized) factors otherwise
factors : List 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