return maps from clustering.motifs
Hello, I have a question about the Property maps returned by clustering.motif(). Practically, I have the following graph:
pprint(rlf) <Graph object, directed, with 22312 vertices and 44849 edges at 0x1007a3650>
In this graph, vertex and edge have some properties. For example :
rlf.vertex_properties {'status': <PropertyMap object with key type 'Vertex' and value type 'string', for Graph 0x1007a3650, at 0x1007a36d0>, '_graphml_vertex_id': <PropertyMap object with key type 'Vertex' and value type 'string', for Graph 0x1007a3650, at 0x101057c10>, 'name': <PropertyMap object with key type 'Vertex' and value type 'string', for Graph 0x1007a3650, at 0x1007ac750>}
Note that this graph occupies the memory space 0x1007a3650. I've asked to graph-tool the motifs of this graph, with the following instruction:
motifs, counts, vertex_maps = gt.clustering.motifs(gt.GraphView(rlf, directed=False), 4, return_maps=True)
So far, so good. This instruction returned me 3 variables. The first one is a list of graphs (motifs), the second one a list of numbers of counts, but the third is a bit mysterious for me. So, it's a list of list of Property maps and it's ok that every one of this map correspond with a count of motif. However, I expected that this property maps refer to my original graph, but it does not. For example, if I'm looking for the first motif and the first map :
pprint(motifs[0]) <Graph object, undirected, with 4 vertices and 3 edges at 0x1007778d0>
case0 = vertex_maps[0] graph0 = case0[0] pprint(graph0) <PropertyMap object with key type 'Vertex' and value type 'int32_t', for Graph 0x1007778d0, at 0x10a2db7d0>
The first PropertyMap object refer to the motif and not to my original graph. And here, I don't understand. For a motif which occurs 10 times in my graph, I obtain 10 property maps. If I use get_graph on this 10 maps, I obtain 10 identical graphs. What would be the value of returning the maps? I had hoped to obtain sub-graph with original vertex and edges properties. Is it something that I didn't understand? Is it possible to obtain sub-graph with original vertex and edges properties by using clustering.motifs? Best regards, Sandrine
On 05/05/2014 07:21 AM, sandrine ollinger wrote:
I've asked to graph-tool the motifs of this graph, with the following instruction:
motifs, counts, vertex_maps = gt.clustering.motifs(gt.GraphView(rlf, directed=False), 4, return_maps=True)
So far, so good. This instruction returned me 3 variables. The first one is a list of graphs (motifs), the second one a list of numbers of counts, but the third is a bit mysterious for me.
So, it's a list of list of Property maps and it's ok that every one of this map correspond with a count of motif. However, I expected that this property maps refer to my original graph, but it does not.
That's right, the property map points to the graph you passed to the function, which is the graph view gt.GraphView(rlf, directed=False), *not* the original graph rlf. (note that this is not a problem, you can use these maps with the original graph)
The first PropertyMap object refer to the motif and not to my original graph. And here, I don't understand. For a motif which occurs 10 times in my graph, I obtain 10 property maps. If I use get_graph on this 10 maps, I obtain 10 identical graphs. What would be the value of returning the maps? I had hoped to obtain sub-graph with original vertex and edges properties.
This is useful for knowing where in the graph the motifs have occurred.
Is it something that I didn't understand? Is it possible to obtain sub-graph with original vertex and edges properties by using clustering.motifs?
Yes, you can get a subgraph of the original graph by constructing a GraphView and filtering out the nodes which do not belong to the motif: mask = g.new_vertex_property("bool") m = motifs[0] vmap = vertex_maps[0] for v in m.vertices(): mask[g.vertex(vmap[v])] = True m_g = GraphView(rlf, vfilt=mask) # the edge and vertex properties of m_g will correspond to those of g Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
Date: Mon, 5 May 2014 14:12:17 -0600 From: tiago@skewed.de To: graph-tool@skewed.de Subject: Re: [graph-tool] return maps from clustering.motifs On 05/05/2014 07:21 AM, sandrine ollinger wrote:
I've asked to graph-tool the motifs of this graph, with the following instruction:
motifs, counts, vertex_maps = gt.clustering.motifs(gt.GraphView(rlf, directed=False), 4, return_maps=True)
So far, so good. This instruction returned me 3 variables. The first one is a list of graphs (motifs), the second one a list of numbers of counts, but the third is a bit mysterious for me.
So, it's a list of list of Property maps and it's ok that every one of this map correspond with a count of motif. However, I expected that this property maps refer to my original graph, but it does not.
That's right, the property map points to the graph you passed to the function, which is the graph view gt.GraphView(rlf, directed=False), *not* the original graph rlf. (note that this is not a problem, you can use these maps with the original graph) Allright, I was a little distracted.
The first PropertyMap object refer to the motif and not to my original graph. And here, I don't understand. For a motif which occurs 10 times in my graph, I obtain 10 property maps. If I use get_graph on this 10 maps, I obtain 10 identical graphs. What would be the value of returning the maps? I had hoped to obtain sub-graph with original vertex and edges properties.
This is useful for knowing where in the graph the motifs have occurred.
Is it something that I didn't understand? Is it possible to obtain sub-graph with original vertex and edges properties by using clustering.motifs?
Yes, you can get a subgraph of the original graph by constructing a GraphView and filtering out the nodes which do not belong to the motif: mask = g.new_vertex_property("bool") m = motifs[0] vmap = vertex_maps[0] for v in m.vertices(): mask[g.vertex(vmap[v])] = True m_g = GraphView(rlf, vfilt=mask) # the edge and vertex properties of m_g will correspond to those of g I make something slightly different, based on your proposition: mask = g.new_vertex_property("bool") m = motifs[0] vmap = vertex_maps[0] pmap = vmap[0] parray = pmap.get_array() for v in m.vertices(): mask[g.vertex(parray[v])] = True It works! Wonderfull! Thank you very much. Best, Sandrine _______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
participants (2)
-
sandrine ollinger -
Tiago de Paula Peixoto