# Prediction of unknown triples for relational learning tasks using RESCAL

Background:

I am focusing on a relational learning task, where links between entities are predicted across several relations. An example of a relation in this task is if two entities have the same survival outcome after a natural disaster; e.g. if Mary and Bob survived then an edge (or a 1) exists between. These relations are concatenated into a 3 mode tensor and the RESCAL relational learning algorithm is applied for entity link prediction. Refer to: Factorizing YAGO Scalable Machine Learning for Linked Data, Nickel, M. et al for specifics. RESCAL is available in Python with pip install sklearn-tensor.

My Question:

In 1, Section 3.1.1, link prediction for new data is given as X_i_j_k ~= A * R_k * A.T. But it's not explicitly stated which matrices are used to predict entity links in relation k. Given a factorization A, R for training relational data and a new factorization new_A, new_R for new relational data, are new links predicted from new_A * R new_A.T?

Code:

from numpy.random import binomial
from scipy.sparse import csr_matrix, coo_matrix
from sktensor.rescal import als as rescal_als

X1 = csr_matrix(binomial(1, 0.25, size=(4,4)))
X2 = csr_matrix(binomial(1, 0.25, size=(4,4)))
X3 = csr_matrix(binomial(1, 0.25, size=(4,4)))
A, R, _, _, _ = rescal_als([X1, X2, X3], 2)

new_X1 = csr_matrix(binomial(1, 0.25, size=(4,4)))
new_X2 = csr_matrix(binomial(1, 0.25, size=(4,4)))
A_new, R_new, _, _, _ = rescal_als([new_X1, new_X2], 2)

# Prediction of Unknown Triples
# see: Section 3.3.1: http://www.dbs.ifi.lmu.de/~tresp/papers/p271.pdf
new_X3 = A_new.dot( R[2] ).dot(A_new.T)
new_X3 > new_X3.mean() # link prediction for some threshold theta?