Is it possible to show the members of the communities shown in the http://projects.skewed.de/graph-tool/doc/community.html#graph_tool.community.condensation_graph
condensation graph documentation. For example, I have a graph in GraphML
that I import with the vertex property "_graphml_vertex_id", from which I
follow the rest of the example posted in the documentation to produce a
condensation graph.
However, I want to see which vertices end up being grouped together. How
would one go about reversing the condensation graph to see the groupings? I
apologise if my question is silly, I'm still very new to graph-tool, which I
think is a remarkable piece of work (thank you!).
Is it possible to show the members of the communities shown in the http://projects.skewed.de/graph-tool/doc/community.html#graph_tool.community.condensation_graph
condensation graph documentation. For example, I have a graph in GraphML
that I import with the vertex property "_graphml_vertex_id", from which I
follow the rest of the example posted in the documentation to produce a
condensation graph.
However, I want to see which vertices end up being grouped together. How
would one go about reversing the condensation graph to see the groupings? I
apologise if my question is silly, I'm still very new to graph-tool, which I
think is a remarkable piece of work (thank you!).
All you have to do is search for vertices with a specific value of the
property map. You can do this by looping:
groups = defaultdict(list)
for v in g.vertices():
groups[vertex_id[v]].append(v)
# now 'groups' is a dictionary with all the vertices for each group
You can also search for individual groups by using the find_vertex() function:
Hi Tiago, thank you for the response! I've tried what you said, but I'm
still a little stuck. I don't know how to incorporate the group numbers of
ng into the loop and associate them with the vertices of g, so all I end up
with currently is a dictionary of vertices (and their labels) in the
largest component. Here's the code I have. Any help would be greatly
appreciated!
import graph_tool.all as gt, collections
from pylab import *
g=gt.load_graph("network.xml")
name = g.vertex_properties['_graphml_vertex_id']
g = gt.GraphView(g, vfilt=gt.label_largest_component(g))
spins = gt.community_structure(g, 1000, 100)
ng = gt.condensation_graph(g, spins)
gt.graphviz_draw(ng[0], overlap=False, output="network.pdf")
groups = collections.defaultdict(list)
for v in g.vertices():
groups[name[v]].append(v)
That fixed it! Thanks so much. Sorry about being noob, but I'm learning a
lot. Hopefully my question can help other newcomers. I think this is
definitely the best network analysis library around; it's so
well-documented, and I hope to contribute to the graph-tool community in
whatever way I can as soon as I understand it better. You should be very
proud of your work.