Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identity of nodes in the giant component, in igraph with Python

Tags:

python

igraph

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?

like image 791
jeffalstott Avatar asked Feb 12 '23 08:02

jeffalstott


2 Answers

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]
like image 155
Tamás Avatar answered Feb 15 '23 02:02

Tamás


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.
like image 29
jeffalstott Avatar answered Feb 15 '23 02:02

jeffalstott