Problem extracting hierarchical blocks

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem extracting hierarchical blocks

James Ruffle
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


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: Problem extracting hierarchical blocks

Alexandre Hannud Abdo
Ni! Hi James, see below.

On Thu, Aug 29, 2019 at 4:59 PM James Ruffle <[hidden email]> wrote:
   
    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
.~´


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: Problem extracting hierarchical blocks

Lietz, Haiko
In reply to this post by James Ruffle

Just to iterate:

 

If I have a graph

 

edge_list=[[0,1,1],[0,2,1],[0,3,1],[1,2,1],[1,3,1],[2,3,1],[0,4,2],[0,5,2],[0,6,2],[1,7,2],[1,8,2],[1,9,2],[2,10,2],[2,11,2],[2,12,2],[3,13,2],[3,14,2],[3,15,2],[4,5,2],[4,6,2],[5,6,2],[7,8,2],[7,9,2],[8,9,2],[10,11,2],[10,12,2],[11,12,2],[13,14,2],[13,15,2],[14,15,2]]

g = Graph(directed=False)

weight = g.new_edge_property('int')

g.add_edge_list(edge_list, eprops=[weight])

 

and a nested blockmodel

 

state = minimize_nested_blockmodel_dl(g, state_args=dict(eweight=weight))

 

then I can either draw the graph directly with a partition from a given level l

 

state.project_level(l=0).draw()

 

or store the partition in a property map

 

group = state.project_partition(l=0, j=0)

 

and then use this map in conventional drawing

 

graph_draw(g, vertex_fill_color=group)

 

Best

 

Haiko

 


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: Problem extracting hierarchical blocks

James Ruffle
Thank you!


On 30 Aug 2019, at 13:21, Lietz, Haiko <[hidden email]> wrote:

Just to iterate:
 
If I have a graph
 
edge_list=[[0,1,1],[0,2,1],[0,3,1],[1,2,1],[1,3,1],[2,3,1],[0,4,2],[0,5,2],[0,6,2],[1,7,2],[1,8,2],[1,9,2],[2,10,2],[2,11,2],[2,12,2],[3,13,2],[3,14,2],[3,15,2],[4,5,2],[4,6,2],[5,6,2],[7,8,2],[7,9,2],[8,9,2],[10,11,2],[10,12,2],[11,12,2],[13,14,2],[13,15,2],[14,15,2]]
g = Graph(directed=False)
weight = g.new_edge_property('int')
g.add_edge_list(edge_list, eprops=[weight])
 
and a nested blockmodel
 
state = minimize_nested_blockmodel_dl(g, state_args=dict(eweight=weight))
 
then I can either draw the graph directly with a partition from a given level l
 
state.project_level(l=0).draw()
 
or store the partition in a property map
 
group = state.project_partition(l=0, j=0)
 
and then use this map in conventional drawing
 
graph_draw(g, vertex_fill_color=group)
 
Best
 
Haiko
 
_______________________________________________
graph-tool mailing list
[hidden email]
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.skewed.de%2Fmailman%2Flistinfo%2Fgraph-tool&amp;data=02%7C01%7Cj.ruffle%40qmul.ac.uk%7Cf071cb89d0504bb8730508d72d449f35%7C569df091b01340e386eebd9cb9e25814%7C0%7C0%7C637027645074909230&amp;sdata=t%2B6DUKT3bACGFZZzumqcL3XXCjzz6G9qBhEn9UM%2FsCU%3D&amp;reserved=0


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: Problem extracting hierarchical blocks

santirdnd
In reply to this post by James Ruffle
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>
?




--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: Problem extracting hierarchical blocks

Tiago Peixoto
Administrator
Am 18.03.20 um 23:13 schrieb santirdnd:
> 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>
> ?

This has been fixed.

--
Tiago de Paula Peixoto <[hidden email]>


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool

signature.asc (849 bytes) Download Attachment
--
Tiago de Paula Peixoto <tiago@skewed.de>