You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add Global Reaching Centrality as measure of hierarchy (migrated from Trac #712) #698
Currently networkx implements one measure to measure how 'hierarchical' the structure of a directed graph is, located at networkx.hierarchy.flow_hierarchy.
Here I suggest another measure called "Global Reaching Centrality" suggested in the paper
''' @Article{mones2012hierarchy,
title={Hierarchy measure for complex networks},
author={Mones, E. and Vicsek, L. and Vicsek, T.},
journal={Arxiv preprint arXiv:1202.0191},
year={2012}
}
'''
I think the appropriate location for this measure is in networkx.hierarchy
This measure is defined for unweighted directed graphs, weighted directed graphs, and unweighted undirected graphs. I will at least implement the measure for both weighted and unweighted directed graphs.
I plan to submit this implementation as a pull request on the github repository.
I updated my pull request with an option to normalize the measure so that it comes back scaled between one and zero. I set the normalized measure to be default.
Please let me know if you will accept the pull request or want the code in some other form.
I added a modified version with your tests. This version doesn't handle weighted graphs. For weighted directed graphs the authors suggest a multiobjective shortest path problem (minimize path length, maximize weight) and there is no algorithm in NetworkX to do that. Maybe that isn't what they mean? The definitions for directed and undirected are quite different too (undirected takes into account path lengths and directed not...)
Maybe I'm not understanding the definitions correctly.
For weighted graphs, I though I created a suitable implementation. Basically the authors want the path with the lowest "average weight". So for every pair of nodes (i,j) you need to find the average weight of the edges on the shortest path between i and j.
NetworkX's shortest path finding functions treat weights as lengths--i.e., the higher the weight, the more distant the two nodes are. That's a problem, because the stronger weight as defined in this multi-objective problem the closer the nodes are. I worked around this by first taking the multiplicative inverse of the edge weights and adding these as a "length" attribute. I then use nx's shortest path routines to find the shortest path with "length" as the weight attribute. Then to find the average edge weight along that path I used the original "weight" attribute.
Why did you modify the implementation I put up on github? Is there something in there that looks wrong? That's certainly possible---but why did you modify the function so that it doesn't work on weighted or undirected graphs?
I looked at the paper again. I misunderstood the value of d(i,j) - it should just be the number of hops between i and j (and not the cost/length between i and j).
So the line
'''
l = nx.single_source_dijkstra_path_length(G, n, weight=length)
'''
should be
'''
l = nx.single_source_shortest_path_length(G, n)
'''
For the weighted and directed case we need a function like single_source_shortest_path_length that finds the path with the shortest hop count and maximum weight. It definitely should not use all_pairs_dijkstra_path which will have very high memory usage. What is the best or simplest algorithm for that problem?
Hi! I don't know if the issue is known and if a fix is planned yet, but make sure "local_reaching_centrality" uses floats. The current development version uses ints and, as a result, it always returns the wrong result.
Hi @mikk-c, can you provide a minimal working example that demonstrates the error (and what you expected as output)? Also what version of Python are you using? From what I see, the from __future__ import division should cause true division everywhere in the networkx.algorithms.centrality.reaching module.
Activity
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @conradlee, 2012-04-06
I implemented this measure for weighted/unweighted/directed/undirected graphs. I also wrote up some tests. I've created a pull request at #6
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @conradlee, 2012-04-10
I updated my pull request with an option to normalize the measure so that it comes back scaled between one and zero. I set the normalized measure to be default.
Please let me know if you will accept the pull request or want the code in some other form.
networkx-trac commentedon Jul 20, 2012
Attachment in Trac by @hagberg, 2012-04-15: hierarchy.py
networkx-trac commentedon Jul 20, 2012
Attachment in Trac by @hagberg, 2012-04-15: test_hierarchy.py
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @hagberg, 2012-04-15
I added a modified version with your tests. This version doesn't handle weighted graphs. For weighted directed graphs the authors suggest a multiobjective shortest path problem (minimize path length, maximize weight) and there is no algorithm in NetworkX to do that. Maybe that isn't what they mean? The definitions for directed and undirected are quite different too (undirected takes into account path lengths and directed not...)
Maybe I'm not understanding the definitions correctly.
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @conradlee, 2012-04-16
For weighted graphs, I though I created a suitable implementation. Basically the authors want the path with the lowest "average weight". So for every pair of nodes (i,j) you need to find the average weight of the edges on the shortest path between i and j.
NetworkX's shortest path finding functions treat weights as lengths--i.e., the higher the weight, the more distant the two nodes are. That's a problem, because the stronger weight as defined in this multi-objective problem the closer the nodes are. I worked around this by first taking the multiplicative inverse of the edge weights and adding these as a "length" attribute. I then use nx's shortest path routines to find the shortest path with "length" as the weight attribute. Then to find the average edge weight along that path I used the original "weight" attribute.
Why did you modify the implementation I put up on github? Is there something in there that looks wrong? That's certainly possible---but why did you modify the function so that it doesn't work on weighted or undirected graphs?
networkx-trac commentedon Jul 20, 2012
Comment in Trac by @hagberg, 2012-04-16
I looked at the paper again. I misunderstood the value of d(i,j) - it should just be the number of hops between i and j (and not the cost/length between i and j).
So the line
'''
l = nx.single_source_dijkstra_path_length(G, n, weight=length)
'''
should be
'''
l = nx.single_source_shortest_path_length(G, n)
'''
For the weighted and directed case we need a function like single_source_shortest_path_length that finds the path with the shortest hop count and maximum weight. It definitely should not use all_pairs_dijkstra_path which will have very high memory usage. What is the best or simplest algorithm for that problem?
mikk-c commentedon Feb 1, 2017
Hi! I don't know if the issue is known and if a fix is planned yet, but make sure "local_reaching_centrality" uses floats. The current development version uses ints and, as a result, it always returns the wrong result.
jfinkels commentedon Feb 6, 2017
Hi @mikk-c, can you provide a minimal working example that demonstrates the error (and what you expected as output)? Also what version of Python are you using? From what I see, the
from __future__ import divisionshould cause true division everywhere in thenetworkx.algorithms.centrality.reachingmodule.dschult commentedon Jul 1, 2017
Closed by #2099