pik-copan / pyunicorn

Unified Complex Network and Recurrence Analysis Toolbox
http://pik-potsdam.de/~donges/pyunicorn/
Other
195 stars 86 forks source link

non correlation between eigenvector centrality determined using pyunicorn and networkx #140

Closed kamblesamadhan closed 7 months ago

kamblesamadhan commented 4 years ago

For a simple graph, I compared eigen centrality values using pyunicorn and networkx. And they are quite different (see below),they doesnt even seem correlated(please point out if any). I looked at documentation of both and they use same definition,then why is this discrepancy (which one is correct)?

import numpy as np import pyunicorn.core.network as nw import networkx as nx

initialise networkx graph

a=nx.Graph() a=nx.Graph() a.add_edge(0,1) a.add_edge(0,3) a.add_edge(1,2) a.add_edge(1,4) a.add_edge(2,4)

initialise pyunicorn graph with same edge list

net=nw.Network(edge_list=list(a.edges()))

print eigencentrality

print("eig by networkx: "+str(nx.eigenvector_centrality(a))) print("eig by pyunicorn: "+str(net.eigenvector_centrality()))

o/p: eig by networkx: {0: 0.34248744909850964, 1: 0.6037035301706529, 3: 0.15467056143060928, 2: 0.49715259845254134, 4: 0.49715259845254134}

eig by pyunicorn: [0.56730708 1. 0.82350633 0.25619926 0.82350633]

jdonges commented 7 months ago

Network.eigenvector_centrality() in pyunicorn returns the normalized eigenvector centrality, normalized by a constant factor so that the maximum entry of the eigenvector centrality vector is 1 (see also the documentation of this method).

This explains the difference to the results of networkx, which outputs non-normalized eigenvector centrality. Upon a closer look, the two vectors provided in the example above differ only by a factor of 0.6037035301706529 (load on node 1 in networkx), as expected.