In [1]:
cd ../../
In [2]:
import networkit
In [3]:
G = networkit.graphio.readGraph("input/celegans_metabolic.graph", networkit.Format.METIS)
First, we just compute the Python EVZ and display a sample. The "scores()" method returns a list of centrality scores in order of the vertices. Thus, what you see below are the (normalized, see the respective argument) centrality scores for G.nodes()[0], G.nodes()[1], ...
In [4]:
evzSciPy = networkit.centrality.SciPyEVZ(G, normalized=True)
evzSciPy.run()
evzSciPy.scores()[:10]
Out[4]:
We now take a look at the 10 most central vertices according to the four heuristics. Here, the centrality algorithms offer the ranking() method that returns a list of (vertex, centrality) ordered by centrality.
In [5]:
evzSciPy.ranking()[:10]
Out[5]:
Compute the EVZ using the C++ backend and also display the 10 most important vertices, just as above. This should hopefully look similar...
Please note: The normalization argument may not be passed as a named argument to the C++-backed centrality measures. This is due to some limitation in the C++ wrapping code.
In [6]:
evz = networkit.centrality.EigenvectorCentrality(G, True)
evz.run()
evz.ranking()[:10]
Out[6]:
Now, let's take a look at the PageRank. First, compute the PageRank using the C++ backend and display the 10 most important vertices. The second argument to the algorithm is the dampening factor, i.e. the probability that a random walk just stops at a vertex and instead teleports to some other vertex.
In [7]:
pageRank = networkit.centrality.PageRank(G, 0.95, True)
pageRank.run()
pageRank.ranking()[:10]
Out[7]:
Same in Python...
In [8]:
SciPyPageRank = networkit.centrality.SciPyPageRank(G, 0.95, normalized=True)
SciPyPageRank.run()
SciPyPageRank.ranking()[:10]
Out[8]:
If everything went well, these should look similar, too.
Finally, we take a look at the relative differences between the computed centralities for the vertices:
In [9]:
differences = [(max(x[0], x[1]) / min(x[0], x[1])) - 1 for x in zip(evz.scores(), evzSciPy.scores())]
print("Average relative difference: {}".format(sum(differences) / len(differences)))
print("Maximum relative difference: {}".format(max(differences)))
In [ ]: