Alternating Least Squares (ALS) algorithm with optional constraints for the minimization of the Candecomp/Parafac (CP) loss function.
cp_als(X, n, m, p, ncomp, const = "none", start = "random",
conv = 1e-06, maxit = 10000, trace = FALSE)
A three-way array or a matrix. If X
is a matrix
(matricised threeway array), n
, m
and p
must be given and
are the number of A-, B- and C-mode entities respectively
Number of A-mode entities
Number of B-mode entities
Number of C-mode entities
Number of components to extract
Optional constraints for each mode. Can be a three element character
vector or a single character, one of "none"
for no constraints (default),
"orth"
for orthogonality constraints, "nonneg"
for nonnegativity constraints or
"zerocor"
for zero correlation between the extracted factors. For example,
const="orth"
means orthogonality constraints for all modes,
while const=c("orth", "none", "none")
sets the orthogonality constraint
only for mode A.
Initial values for the A, B and C components. Can be "svd"
for starting point of the algorithm from SVD's, "random"
for random
starting point (orthonormalized component matrices or nonnegative matrices in
case of nonnegativity constraint), or a list containing user specified components.
Convergence criterion, default is conv=1e-6
.
Maximum number of iterations, default is maxit=10000
.
Logical, provide trace output.
The result of the decomposition as a list with the following elements:
A
Component matrix for the A-mode
B
Component matrix for the B-mode
C
Component matrix for the C-mode
f
Value of the loss function
fp
Fit value expressed as a percentage
iter
Number of iterations
tripcos
Minimal triple cosine between two components
across the three component matrices, used to inspect degeneracy
mintripcos
Minimal triple cosine during the iterative
algorithm observed at every 10 iterations, used to inspect degeneracy
ftiter
Matrix containing in each row the function value
and the minimal triple cosine at every 10 iterations
const
Optional constraints (same as the input parameter const
)
Harshman, R.A. (1970). Foundations of Parafac procedure: models and conditions for an "explanatory" multi-mode factor analysis. UCLA Working Papers in Phonetics, 16: 1--84.
Harshman, R. A., & Lundy, M. E. (1994). PARAFAC: Parallel factor analysis. Computational Statistics and Data Analysis, 18, 39--72.
Lawson CL, Hanson RJ (1974). Solving Least Squares Problems. Prentice Hall, Englewood Cliffs, NJ.
# NOT RUN {
## Example with the OECD data
data(elind)
dim(elind)
res <- cp_als(elind, ncomp=3)
res$fp
res$fp
res$iter
res <- cp_als(elind, ncomp=3, const="nonneg")
res$A
# }
Run the code above in your browser using DataCamp Workspace