def __init__(self, sess, n, filename, jump_prob=0.05, epsilon=1e-4, max_iteration=100, drop_tol=1e-8, verbose=False):
"""
Computes PPR using iterative method. `epsilon` denotes convergence threshold.
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.
epsilon (float): Convergence threshold (uses l2-norm of difference).
max_iteration (int): Maximum number of allowed iterations.
drop_tol (float): No effect.
verbose (bool): Prints step messages if True.
"""
self.alias = 'iter'
self.verbose = verbose
self.pp("initializing")
self.sess = sess
self.n = n
self.c = jump_prob
self.e = epsilon
self.max_iteration = max_iteration
d = 1 - self.c
self.pp("preprocessing")
self.node2index, A = read_matrix(filename, d=d)
self.pp("tf init")
with tf.variable_scope('ppr_iterative_tf'):
t_A = tf.SparseTensorValue(list(zip(A.row, A.col)), A.data, dense_shape=[n, n])
t_old_r = tf.Variable((np.ones(n) / n)[:, np.newaxis])
self.t_cq = tf.placeholder(tf.float64, shape=[n, 1])
self.t_new_r = tf.Variable((np.ones(n) / n)[:, np.newaxis])
self.t_new_r_assign = tf.assign(self.t_new_r, _sdmm(t_A, t_old_r) + self.t_cq)
self.t_old_r_assign = tf.assign(t_old_r, self.t_new_r)
self.t_loss = tf.norm(self.t_new_r - t_old_r)
del A
评论列表
文章目录