Description Usage Arguments Value Author(s) References See Also Examples
RESCAL-ALS algorithm to compute the RESCAL tensor factorization. The solution is a matrix and a core tensor. RESCAL factors a (usually sparse) three-way tensor X such that each frontal slice X_k is factored into X_k = A * R_k * A^T
1 2 3 |
X |
is a sparse tensor as set of sparse matrices, one for every relation (predicate). (a LIST of SparseMatrix ) |
rnk |
The rank of the factorization |
ainit |
the method used to initialize matrix A |
verbose |
the level of messages to be displayed, 0 is minimal. |
Ainit |
the initial value of matrix A. |
Rinit |
the initial value of R (the core tensor, as LIST of frontal slices) |
lambdaA |
Regularization parameter for A factor matrix. 0 by default |
lambdaR |
Regularization parameter for R_k factor matrices. 0 by default |
lambdaV |
Regularization parameter for R_k factor matrices. 0 by default |
epsilon |
error threshold |
maxIter |
Maximum number of iterations |
minIter |
Minimum number of iterations |
P |
Not implemented |
orthogonalize |
Not implemented |
func_compute_fval |
function used to compute fit. |
list(A=A, R=R, all_err, nitr=itr + 1, times=as.vector(exectimes) Returns a LIST of the following:
A |
The matrix A of the factorization ( n by r) |
R |
The core tensor R the factorization as r (rank) matrices of ( r by r) |
nitr |
number of iterations |
times |
list of running times of each step. |
Abdelmoneim Amer Desouki
-Maximilian Nickel, Volker Tresp, Hans-Peter-Kriegel, "A Three-Way Model for Collective Learning on Multi-Relational Data", ICML 2011, Bellevue, WA, USA
-Maximilian Nickel, Volker Tresp, Hans-Peter-Kriegel, "Factorizing YAGO: Scalable Machine Learning for Linked Data" WWW 2012, Lyon, France
cp_apr
serial_parCube
cp_nmu
cp_als
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 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)
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)))
#using RESCAL for prediction missing relations.
aa=read.table(file = paste0(path.package("RDFTensor"), '/toy_vicePresident.nt'),
sep=' ',header=FALSE,stringsAsFactors=FALSE)
trp=aa[,1:3]
tnsr=getTensor(trp)
r=4
sr=NULL
t0=proc.time()
X_=list()
library(Matrix)
tt=rescal(tnsr$X,rnk=r,ainit='nvecs',verbose=1,lambdaA=0,epsilon=1e-4,lambdaR=0)
R=tt$R
A=tt$A
s1=A%*%R[[1]]%*%Matrix::t(A)
s2=A%*%R[[2]]%*%Matrix::t(A)
#predict the party of AlGore (no explicit info is given in the nt file)
print(s1[tnsr$SO=='<http://example.com/AlGore>',tnsr$SO=='<http://example.com/RepublicanParty>'])
print(s1[tnsr$SO=='<http://example.com/AlGore>',tnsr$SO=='<http://example.com/DemocraticParty>'])
partyOf=data.frame(tnsr$SO,Repub=s1[,tnsr$SO=='<http://example.com/RepublicanParty>'],
Democ=s1[,tnsr$SO=='<http://example.com/DemocraticParty>'],
GivenRepub=tnsr$X[[1]][,tnsr$SO=='<http://example.com/RepublicanParty>'],
GivenDemoc=tnsr$X[[1]][,tnsr$SO=='<http://example.com/DemocraticParty>'],
stringsAsFactors=FALSE)
print(partyOf)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.