I have just fitted an SBM to my graph. Having run state =
gt.minimize_nested_blockmodel_dl(g, deg_corr=True) I now would like to
investigate the results a bit more closely. More specifically I am after the
best way to access all vertices assigned to a given block.
I can use get_levels() and then get_blocks() to obtain the block membership
of each vertex and from that I can use find_vertex() for a given block
number to find the list of all vertices in that block which I can then use
to loop through them. I wonder, however, if there is a more efficient way of
obtaining all vertices in a given block?
My current pseudo code looks something like the following:
state = gt.minimize_nested_blockmodel_dl(g, deg_corr=True)
#now do something for all vertices in each of the blocks
levels = state.get_levels()
graphs = state.get_bstacks() #Return the nested levels as individual graphs.
num_blocks = graphs.num_vertices() #find the number of blocks at level 0
blocks = levels.get_blocks() #Returns property map with block labels for
for i in range(num_blocks): #cycle through all blocks
vs = gt.find_vertex(g,blocks,i)
for v in vs: #cylce through all vertices in a given block
Is there some more efficient way of doing this that I am missing? I would
ideally ultimately run it after each sweep of the mcmc algorithm so would
like to minimise looping that I am doing in python if graph-tool has methods
for what I am doing which will, presumably, be faster.
Thank you for any advice in advance!
With best wishes,