Description Usage Arguments Value Author(s) See Also Examples
View source: R/scRescal.R View source: R/rescal.R
Calculates error (Eculidean distance) between X:sparse tensor (frontal slices) and the approximations as R :core tensor and matrix :A.
1 | Tensor_error(X, A, R)
|
X |
|
A |
matrix A from RESCAL factorization (n by r). |
R |
core tensor from RESCAL factorization as set of frontal slices ( r by r by r) |
return numeric value as the Eculidean distance between the two tensors.
Abdelmoneim Amer Desouki
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | X1=matrix(c(1,0,0,0,0, 0,1,0,0,0, 0,0,1,1,0, 0,0,0,0,1, 1,0,0,0,0),byrow=TRUE,nrow=5,ncol=5)
X2=matrix(c(0,1,0,1,1, 1,0,0,1,0, 0,1,0,1,1, 0,0,0,0,1, 0,0,1,0,0),byrow=TRUE,nrow=5,ncol=5)
X2_=matrix(c(0,1,0,1,1, 1,0,0,1,0, 0,0,0,0,0, 0,0,0,0,1, 0,0,1,0,0),byrow=TRUE,nrow=5,ncol=5)
X=list(t(X1),t(X2),t(X2_))
N=nrow(X1)
Xs=list()
for(s in 1:length(X)){
aa=which(X[[s]]==1,arr.ind=TRUE)
Xs[[s]]=Matrix::sparseMatrix(x=rep(1,nrow(aa)),i=aa[,1],j=aa[,2],dims=c(N,N))
}
print(Xs)
rf=rescal(Xs,2)
A=rf$A
R=rf$R
Tensor_error(Xs,A,R)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.