Details and Options
The CP (canonical polyadic) decomposition is also known as the CANDECOMP/PARAFAC decomposition.
The CP decomposition expresses a tensor as the sum of rank-1 tensors, which can be useful for dimensionality reduction, compression, and revealing latent structure in data.
Given an input tensor and a desired tensor rank, ResourceFunction["CPDecomposition"] returns a list of factor matrices representing the decomposed tensor.
In
ResourceFunction["CPDecomposition"][tensor,rank], if
rank, the second dimension of each factor, is set to
Automatic, the default rank is heuristically determined as
Min[16,Total[dims]-Max[dims]], where
dims represents the dimensions of the input tensor.
ResourceFunction["CPDecomposition"] uses the alternating least squares (ALS) algorithm to compute the decomposition.
The ALS algorithm is a randomized algorithm. Due to this,
ResourceFunction["CPDecomposition"] may return different results on different evaluations. Use
SeedRandom or provide "InitialFactors" for reproducibility.
The argument property can be any of the following:
"Factors" | list of matrix factors decomposing an input tensor |
"ReconstructedTensor" | reconstructed tensor |
"Error" | total squared error between input and reconstructed tensors |
"Iterations" | number of iterations performed |
"Rank" | rank of the decompostion |
ResourceFunction["CPDecomposition"] takes the following options:
MaxIterations | 100 | maximum number of iterations for the ALS algorithm |
Tolerance | 10-6 | tolerance threshold for convergence |
"InitialFactors" | Automatic | initial list of factors for the ALS algorithm |
In the setting of the "InitialFactors" option, the ith factor should have dimensions equal to {di,rank} with di being the tensor’s ith dimension.