I'm trying to label which nodes are in the giant component of a network, and which are not. I am NOT trying to simply grab the giant component. This is what I have so far:
def in_giant(G):
giant = G.components().giant().vs["name"]
return map(lambda x: x in giant, G.vs["name"])
This is slow. I suspect there's something fast that can be done by operating on the G.components()
structure directly. Any ideas?
I'm not sure if I understand your question correctly, but it seems like you simply need a binary list (i.e. a list containing True
and False
only) such that the item at index i in the list is true iff the corresponding vertex is in the giant component. Your solution is fine, but since it depends on NumPy, I thought I'd add an alternative that does not depend on it:
def in_giant(G):
cl = G.components()
cl_sizes = cl.sizes()
giant_component_index = cl_sizes.index(max(cl_sizes))
return [x == giant_component_index for x in cl.membership]
Looks like the answer is:
vc = G.components() ##Get VertexClustering object
array(vc.membership)==argmax(vc.sizes) ##argmax(vc.sizes) may always return 0; not sure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With