CPfunc: Algorithm for the Candecomp/Parafac (CP) model

Description Usage Arguments Value Note Author(s) References See Also Examples

Description

Alternating Least Squares algorithm for the minimization of the Candecomp/Parafac loss function.

Usage

1
 CPfunc(X, n, m, p, r, ort1, ort2, ort3, start, conv, maxit, A, B, C)

Arguments

X

Matrix (or data.frame coerced to a matrix) of order (n x mp) containing the matricized array (frontal slices)

n

Number of A-mode entities

m

Number of B-mode entities

p

Number of C-mode entities

r

Number of extracted components

ort1

Type of constraints on A (1 for no constraints, 2 for orthogonality constraints, 3 for zero correlations constraints)

ort2

Type of constraints on B (1 for no constraints, 2 for orthogonality constraints, 3 for zero correlations constraints)

ort3

Type of constraints on C (1 for no constraints, 2 for orthogonality constraints, 3 for zero correlations constraints)

start

Starting point (0 for starting point of the algorithm from SVD's, 1 for random starting point (orthonormalized component matrices), 2 for user specified components

conv

Convergence criterion

maxit

Maximal number of iterations

A

Optional (necessary if start=2) starting value for A

B

Optional (necessary if start=2) starting value for B

C

Optional (necessary if start=2) starting value for C

Value

A list including the following components:

A

Component matrix for the A-mode

B

Component matrix for the B-mode

C

Component matrix for the C-mode

f

Loss function value

fp

Fit value expressed as a percentage

iter

Number of iterations

tripcos

Minimal triple cosine between two components across three component matrices (to inspect degeneracy)

mintripcos

Minimal triple cosine during the iterative algorithm observed at every 10 iterations (to inspect degeneracy)

ftiter

Matrix containing in each row the function value and the minimal triple cosine at every 10 iterations

cputime

Computation time

Note

The loss function to be minimized is sum(k)|| X(k) - A D(k) B' ||^2, where D(k) is a diagonal matrix holding the k-th row of C.
CPfunc is the same as CPfuncrep except that all printings are available.

Author(s)

Maria Antonietta Del Ferraro mariaantonietta.delferraro@yahoo.it
Henk A.L. Kiers h.a.l.kiers@rug.nl
Paolo Giordani paolo.giordani@uniroma1.it

References

R.A. Harshman (1970). Foundations of the Parafac procedure: models and conditions for an ‘explanatory’ multi-mode factor analysis. UCLA Working Papers in Phonetics 16:1–84.

See Also

CP, CPfuncrep

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
data(TV)
TVdata=TV[[1]]
# permutation of the modes so that the A-mode refers to students
TVdata <- permnew(TVdata, 16, 15, 30)
TVdata <- permnew(TVdata, 15, 30, 16)
# unconstrained CP solution using two components 
# (rational starting point by SVD [start=0])
TVcp <- CPfunc(TVdata, 30, 16, 15, 2, 1, 1, 1, 0, 1e-6, 10000)
# constrained CP solution using two components with orthogonal A-mode 
# component matrix (rational starting point by SVD [start=0])
TVcp <- CPfunc(TVdata, 30, 16, 15, 2, 2, 1, 1, 0, 1e-6, 10000)
# constrained CP solution using two components with orthogonal A-mode 
# component matrix and zero correlated C-mode component matrix 
# (rational starting point by SVD [start=0])
TVcp <- CPfunc(TVdata, 30, 16, 15, 2, 2, 1, 3, 0, 1e-6, 10000)
# unconstrained CP solution using two components 
# (random orthonormalized starting point [start=1])
TVcp <- CPfunc(TVdata, 30, 16, 15, 2, 1, 1, 1, 1, 1e-6, 10000)
# unconstrained CP solution using two components (user starting point [start=2])
TVcp <- CPfunc(TVdata, 30, 16, 15, 2, 1, 1, 1, 2, 1e-6, 10000, 
 matrix(rnorm(30*2),nrow=30), matrix(rnorm(16*2),nrow=16), 
 matrix(rnorm(15*2),nrow=15))

Example output

Candecomp/Parafac function value at Start is  101608.920671694
f= 60457.8012254395 after 50 iters; diff.= 0.352643067431927
f= 60449.6374827114 after 100 iters; diff.= 0.0753777605204959
Candecomp/Parafac function value is 60448.9103406784 after 111 iterations
Fit percentage is 40.3227169294241 %
Procedure used 0.12 seconds
Candecomp/Parafac function value at Start is  101608.920671694
Candecomp/Parafac function value is 67190.7601382094 after 35 iterations
Fit percentage is 33.6669265021182 %
Procedure used 0.04 seconds
Candecomp/Parafac function value at Start is  101608.920671694
Candecomp/Parafac function value is 67736.2483768222 after 45 iterations
Fit percentage is 33.1284013931642 %
Procedure used 0.06 seconds
Candecomp/Parafac function value at Start is  101293.022120757
f= 60458.5697563569 after 50 iters; diff.= 0.387218499236042
f= 60449.799855909 after 100 iters; diff.= 0.0791966779215727
Candecomp/Parafac function value is 60448.9177356838 after 113 iterations
Fit percentage is 40.3227096288156 %
Procedure used 0.21 seconds
Candecomp/Parafac function value at Start is  114964.519843018
f= 60459.2042710093 after 50 iters; diff.= 0.416857303564029
f= 60449.9287408714 after 100 iters; diff.= 0.0822805128191249
Candecomp/Parafac function value is 60448.9541240113 after 114 iterations
Fit percentage is 40.3226737049832 %
Procedure used 0.1 seconds

ThreeWay documentation built on May 2, 2019, 9:20 a.m.

Related to CPfunc in ThreeWay...