def __init__(self, sess, n, filename, jump_prob=0.05, drop_tol=1e-8, verbose=False):
"""
Computes PPR using LU decomposition.
Args:
sess (Session): tensorflow session.
n (int): Number of nodes.
filename (str): A csv file denoting the graph.
jump_prob (float): Jumping probability of PPR.
drop_tol (float): Drops entries with absolute value lower than this value when computing inverse of LU.
verbose (bool): Prints step messages if True.
"""
self.alias = 'ludc'
self.verbose = verbose
self.pp("initializing")
self.sess = sess
self.n = n
self.c = jump_prob
d = 1 - self.c
t = drop_tol
exact = False
if t is None:
t = np.power(n, -0.5)
elif t == 0:
exact = True
self.pp("reading")
self.node2index, H = read_matrix(filename, d=-d, add_identity=True)
self.pp("sorting H")
self.perm = degree_reverse_rank_perm(H)
H = reorder_matrix(H, self.perm).tocsc()
self.pp("computing LU decomposition")
if exact:
self.LU = splu(H)
else:
self.LU = spilu(H, drop_tol=t)
Linv = inv(self.LU.L).tocoo()
Uinv = inv(self.LU.U).tocoo()
self.pp("tf init")
with tf.variable_scope('ppr_lu_decomposition_tf'):
t_Linv = tf.SparseTensorValue(list(zip(Linv.row, Linv.col)), Linv.data, dense_shape=self.LU.L.shape)
t_Uinv = tf.SparseTensorValue(list(zip(Uinv.row, Uinv.col)), Uinv.data, dense_shape=self.LU.U.shape)
self.t_q = tf.placeholder(tf.float64, shape=[self.n, 1])
self.t_r = _sdmm(t_Uinv, _sdmm(t_Linv, self.c * self.t_q))
评论列表
文章目录