if(interactive()){
# Simulation Datasets
set.seed(123)
# I times J times K
X1 <- rand_tensor(modes = c(4, 5, 6))
X1 <- X1@data^2
names(dim(X1)) <- c("I", "J", "K")
# I times P
X2 <- matrix(runif(4 * 7), nrow=4, ncol=7)
names(dim(X2)) <- c("I", "M")
# J times Q
X3 <- matrix(runif(5 * 8), nrow=5, ncol=8)
names(dim(X3)) <- c("J", "N")
# Coupled Tensor/Matrix
X <- list(X1 = X1, X2 = X2, X3 = X3)
# Coupling matrix R (CP)
R_CP <- rbind(
c(1,1,1,0,0),
c(1,0,0,1,0),
c(0,1,0,0,1)
)
rownames(R_CP) <- paste0("X", seq(3))
colnames(R_CP) <- LETTERS[seq(5)]
# Size of Factor matrices (CP)
Ranks_CP <- list(
A=list(I=4, r=3),
B=list(J=5, r=3),
C=list(K=6, r=3),
D=list(M=7, r=3),
E=list(N=8, r=3))
# Coupling matrix R (Tucker)
R_Tucker <- rbind(
c(1,1,1,1,0,0),
c(1,0,0,0,1,0),
c(0,1,0,0,0,1)
)
rownames(R_Tucker) <- paste0("X", seq(3))
colnames(R_Tucker) <- LETTERS[seq(6)]
# Size of Factor matrices (Tucker)
Ranks_Tucker <- list(
A=list(I=4, p=3),
B=list(J=5, q=4),
C=list(K=6, r=3),
D=list(p=3, q=4, r=3),
E=list(M=7, p=3),
F=list(N=8, q=4))
# CP
out.CP_EUC <- GCTF(X, R_CP, Ranks=Ranks_CP, Beta=0, verbose=TRUE)
out.CP_KL <- GCTF(X, R_CP, Ranks=Ranks_CP, Beta=1, verbose=TRUE)
out.CP_IS <- GCTF(X, R_CP, Ranks=Ranks_CP, Beta=2, verbose=TRUE)
# Tucker
out.Tucker_EUC <- GCTF(X, R_Tucker, Ranks=Ranks_Tucker, Beta=0, verbose=TRUE)
out.Tucker_KL <- GCTF(X, R_Tucker, Ranks=Ranks_Tucker, Beta=1, verbose=TRUE)
out.Tucker_IS <- GCTF(X, R_Tucker, Ranks=Ranks_Tucker, Beta=2, verbose=TRUE)
}
Run the code above in your browser using DataLab