def compute(self, c=0.15, epsilon=1e-6, max_iters=100, handles_deadend=True): ''' Compute the PageRank score vector (global ranking) inputs c : float restart probability epsilon : float error tolerance for power iteration max_iters : int maximum number of iterations for power iteration handles_deadend : bool if true, it will handle the deadend issue in power iteration otherwise, it won't, i.e., no guarantee for sum of RWR scores to be 1 in directed graphs outputs r : ndarray PageRank score vector ''' self.normalize() q = np.ones((self.n, 1)) q = q / self.n r, residuals = iterator.iterate(self.nAT, q, c, epsilon, max_iters, handles_deadend) return r
def compute(self, seeds, c=0.15, epsilon=1e-9, max_iters=100, handles_deadend=True): ''' Compute the PPR score vector w.r.t. the seed node inputs seeds : list list of seeds c : float restart probability epsilon : float error tolerance for power iteration max_iters : int maximum number of iterations for power iteration handles_deadend : bool if true, it will handle the deadend issue in power iteration otherwise, it won't, i.e., no guarantee for sum of RWR scores to be 1 in directed graphs outputs r : ndarray PPR score vector ''' self.normalize() seeds = [seed - self.base for seed in seeds] if len(seeds) is 0: raise ValueError('Seeds are empty') if min(seeds) < 0 or max(seeds) >= self.n: raise ValueError('Out of range of seed node id') # q = np.zeros((self.n, 1)) q = np.zeros(self.n) q[seeds] = 1.0 / len(seeds) r, residuals = iterator.iterate(self.nAT, q, c, epsilon, max_iters, handles_deadend) return r
def compute(self, seed, c=0.15, epsilon=1e-6, max_iters=100, handles_deadend=True): ''' Compute the RWR score vector w.r.t. the seed node inputs seed : int seed (query) node id c : float restart probability epsilon : float error tolerance for power iteration max_iters : int maximum number of iterations for power iteration handles_deadend : bool if true, it will handle the deadend issue in power iteration otherwise, it won't, i.e., no guarantee for sum of RWR scores to be 1 in directed graphs outputs r : ndarray RWR score vector ''' self.normalize() # adjust range of seed node id seed = seed - self.base # q = np.zeros((self.n, 1)) q = np.zeros(self.n) if seed < 0 or seed >= self.n: raise ValueError('Out of range of seed node id') q[seed] = 1.0 r, residuals = iterator.iterate(self.nAT, q, c, epsilon, max_iters, handles_deadend) return r