# Problem extracting hierarchical blocks

Dear community / Tiago

I have a hierarchical partition of a nested block state.
The original network contained 4453 vertices and 50051 edges.

state.print_summary()
l: 0, N: 4453, B: 126
l: 1, N: 126, B: 46
l: 2, N: 46, B: 20
l: 3, N: 20, B: 9
l: 4, N: 9, B: 3
l: 5, N: 3, B: 1

I want to extract the community label of each vertex of each possible hierarchical level.
To do this I wrote a loop based upon the guide at https://graph-tool.skewed.de/static/doc/demos/inference/inference.html
Where vertexblocksdf is simply a df populated with the vertex numbers 0-4452.

for idx in range(len(vertexblocksdf)):

r = levels[0].get_blocks()[idx] # group membership of node idx in level 0
vertexblocksdf.ix[idx, 'level0'] = r

r = levels[0].get_blocks()[r] # group membership of node idx in level 1
vertexblocksdf.ix[idx, 'level1'] = r

r = levels[0].get_blocks()[r] # group membership of node idx in level 2
vertexblocksdf.ix[idx, 'level2'] = r

r = levels[0].get_blocks()[r] # group membership of node idx in level 3
vertexblocksdf.ix[idx, 'level3'] = r

r = levels[0].get_blocks()[r] # group membership of node idx in level 4
vertexblocksdf.ix[idx, 'level4'] = r

r = levels[0].get_blocks()[r] # group membership of node idx in level 5
vertexblocksdf.ix[idx, 'level5'] = r

But, I am getting strange results. My level0 column variables make sense, with 126 possibilities (as per l0 above). But my level1 column is a number between 0 and 13; of which none of my levels have 14 blocks. My level2 output is either 0 or 1, again doesn’t make sense! Level3-5 are all simply 0.
*this also reproduces the same behaviour if done manually without loop.

Any ideas??

James

attachment.html (3.23 KB)

Ni! Hi James, see below.

r = levels[0].get_blocks()[idx] # group membership of node idx in
level 0
vertexblocksdf.ix[idx, 'level0'] = r

r = levels[0].get_blocks()[r] # group membership of node idx in
level 1
vertexblocksdf.ix[idx, 'level1'] = r

Shouldn't here the second paragraph be `levels[1]`, and so forth?

In any case, take a look at the `state.project_level()` method, as it
provides what you're looking for.

Also, I wouldn't use `.ix[]`, as it has been deprecated in pandas for quite
a while now.

Abraços,
l
e
.~´

attachment.html (1.35 KB)

Hi Tiago!

Could it be that the problem highlighted by this thread is fueled by a bug
in the documentation at the end of this section
<https://graph-tool.skewed.de/static/doc/demos/inference/inference.html#hierarchical-partitions&gt;
?

This has been fixed.