rescal_01: transformation of the real-number-RESCAL-decompositions to...

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

View source: R/CP_01.R

Description

applies different thresholds to get a number of triples from A and R (result of RESCAL) decomposition as scale_fact*the_number_of_triples_in_original_tensor.

Usage

1
rescal_01(X, A, R, scale_fact = 1)

Arguments

X

is a sparse tensor as set of sparse matrices, one for every relation (predicate). (a LIST of SparseMatrix )

A

the A matrix returned by RESCAL factorization

R

the R LIST returned by RESCAL factorization

scale_fact

scale of the number of triples to be considered in the result. When it is 1 then a threshold will be taken to get the same number of triples in each slice as the original tensor.

Value

a LIST

X_

The reconstructed tensor as a set of frontal slices.

tp

the number of true positives

fp

the number of false positives

fn

the number of false negatives

sr

the details of each slice i.e the number of tp, fn, fp, etc

Author(s)

Abdelmoneim Amer Desouki

References

-Maximilian Nickel, Volker Tresp, Hans-Peter-Kriegel, "A Three-Way Model for Collective Learning on Multi-Relational Data", ICML 2011, Bellevue, WA, USA

See Also

rescal CP_01

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    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
    tmp=rescal_01(Xs,A,R,scale_fact=1.5)#generate 1.5*original number of triples
    print(sprintf('Precision:%.4f, Recall:%.4f',tmp$tp/(tmp$tp+tmp$fp),tmp$tp/(tmp$tp+tmp$fn)))

RDFTensor documentation built on Jan. 16, 2021, 5:19 p.m.