Efficient way to get most-likely hierarchical node partition

Hi Tiago,

I looked at the example in the document here

As the example shows, we can obtain vertex marginals on all hierarchical
levels, i.e. a "vertex_pie_fractions" at each level for each node. However,
I want to find the node partition at each level for each node according to
the *largest* "vertex_pie_fraction". Therefore, I use the following code

# Hierarchical node partition as a list of np.array
bs = [np.array([np.argmax(list(pv[i])[j]) for j in range(len(list(pv[i])))])
for i in range(len(pv))]

where pv is exactly the one shown in the example.

I believe the above line of code is correct since I have checked the results
in several real networks with small sizes (around 200 nodes and 500 edges at

But it will take a quite a long time for a large network (30k nodes with
400k edges or more). Is there any efficient way to do the above work?


You are creating many lists necessarily for every look iteration. A
better alternative is something like:

bs = [[pv[i][v].a.argmax() for v in state.get_levels()[i].g.vertices()]
      for i in range(len(pv))]