def compute_user_pagerank(network, user, directed_networks, weighted): if len(network.es) == 0: return 1 options = igraph.ARPACKOptions() options.mxiter = 100000 # Igraph 0.7 has a bad bug! It does not give pagerank of a specific user. It # only returns pagerank of first user in the graph, no matter what the # vertices argument is. So we get a list of all pageranks, then query in the # list with the index of node with name user user_index = network.vs.find(user).index if weighted: # if weights are requested, we should use the original weights rather than their inverse # (in contrast to closeness). In case of pagerank, large edge weights are good for the # incoming node. They give it more credit. weights = network.es['weight'] else: weights = None user_pagerank = network.pagerank(directed=directed_networks, damping=0.85, weights=weights, implementation="prpack", arpack_options=options)[user_index] if user_pagerank > 1: sys.stderr.write('Error: Pagerank of user %s is greater than one: %f' % (user, user_pagerank)) # Igraph returns tiny non-zero values for page ranks that should be really zero. # manually zero them out. if user_pagerank < pow(10, -15): user_pagerank = 0 return utils.round_to_sigfigs(user_pagerank, NUM_SIGFIGS)
def compute_user_satoshi_pagerank(network, user, weighted): if len(network.es) == 0: return 1 if 'satoshi' not in network.vs["name"]: return 0 # increase the pagerank computation max number of iterations. sometimes arpack does not # converge. options = igraph.ARPACKOptions() options.mxiter = 100000 # Igraph 0.7 has a bad bug! It does not give pagerank of a specific user. It # only returns pagerank of first user in the graph, no matter what the # vertices argument is. So we get a list of all pageranks, then query in the # list with the index of node with name user user_index = network.vs.find(user).index if weighted: # if weights are requested, we should use the original weights rather than their inverse # (in contrast to closeness). In case of pagerank, large edge weights are good for the # incoming node. They give it more credit. weights = network.es['weight'] else: weights = None # Vertices should be the active user whose page rank we want to compute. directed # should be true so that directed paths are considered. damping is the probability # that we reset the random walk on Satoshi at each step. reset_vertices should only # contain Satoshi, since we are interested in flow from Satoshi. weights should be # the 'weight' attribute so that weights are used in page rank computation. user_satoshi_pagerank = network.personalized_pagerank( directed=True, damping=0.85, reset_vertices='satoshi', weights=weights, implementation="prpack", arpack_options=options)[user_index] if user_satoshi_pagerank > 1: sys.stderr.write( 'Error: Satoshi pagerank of user %s is greater than one: %f' % (user, user_satoshi_pagerank)) # Igraph returns tiny non-zero values for page ranks that should be really zero. # manually zero them out. if user_satoshi_pagerank < pow(10, -15): user_satoshi_pagerank = 0 return utils.round_to_sigfigs(user_satoshi_pagerank, NUM_SIGFIGS)
def compute_mean_median_std_pagerank(network, directed_networks, weighted): if len(network.es) == 0: return [1] * 3 options = igraph.ARPACKOptions() options.mxiter = 100000 if weighted: weights = network.es['weight'] else: weights = None s = network.pagerank(directed=directed_networks, damping=0.85, weights=weights, implementation="prpack", arpack_options=options) return [numpy.mean(s), numpy.median(s), numpy.std(s)]
def compute_mean_median_std_satoshi_pagerank(network, directed_networks, weighted): if len(network.es) == 0: return [1] * 3 if 'satoshi' not in network.vs["name"]: return [0] * 3 options = igraph.ARPACKOptions() options.mxiter = 100000 if weighted: weights = network.es['weight'] else: weights = None s = network.personalized_pagerank(directed=directed_networks, damping=0.85, reset_vertices='satoshi', weights=weights, implementation="prpack", arpack_options=options) return [numpy.mean(s), numpy.median(s), numpy.std(s)]