RDFTensor (version 1.3)

Tensor_error: RESCAL Tensor error

Description

Calculates error (Eculidean distance) between X:sparse tensor (frontal slices) and the approximations as R :core tensor and matrix :A.

Usage

Tensor_error(X, A, R)

Arguments

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)

Value

return numeric value as the Eculidean distance between the two tensors.

See Also

rescal

Examples

Run this code
# NOT RUN {
 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)

# }

Run the code above in your browser using DataLab