Ask Your Question
0

motifs and subgraphs

asked 2013-05-26 19:02:15 -0500

gvdr gravatar image

updated 2013-05-26 19:03:00 -0500

I'm counting the number of motifs (3-nodes isophormic class of connected subgraphs) in a random directed network. There are 13 of this. One is, for example S1={1 -> 2, 2 -> 3} and another one S2={1 -> 2, 2 -> 3, 1 -> 3}. They are two distinct motifs, and I wouldn't count a S1 when I actually find S2. The problem is that S1 is in S2, hence subgraph_search() finds a S1 in each S2 and all related functions inherit the problem (wrong counting, wrong iterator...).

Any idea how to resolve this issue? Similar things would happen for 4-nodes motifs and so on...

The code I used goes like:

import numpy
M1 = DiGraph(numpy.array([[0,1,0],[0,0,1],[0,0,0]])) #first motif
M5 = DiGraph(numpy.array([[0,1,1],[0,0,1],[0,0,0]])) #second motif
g = digraphs.RandomDirectedGNP(20,0.1) #a random network
l1 = []
for p in g.subgraph_search_iterator(M1): #search first motif
  l1.append(p) #make a list of its occurences
l5 = []
for p in g.subgraph_search_iterator(M5): #the same for the second motif
  l5.append(p)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-05-26 19:37:07 -0500

First of all, you do not need numpy to initialize a graph. Simply write

M1 = DiGraph(matrix([[0,1,0],[0,0,1],[0,0,0]])) #first motif
M5 = DiGraph(matrix([[0,1,1],[0,0,1],[0,0,0]])) #second motif

Your question is documented in subgraph_search, subgraph_search_iterator and subgraph_search_count. You can access the documentation through

sage: G = DiGraph()
sage: G.subgraph_search?

There is an option induced which allows you to search only for induced subgraph and which is False by default.

sage: M5.subgraph_search_count(M1)
1
sage: M5.subgraph_search_count(M1,induced=True)
0
edit flag offensive delete link more

Comments

And be extra careful when you *COUNT* these patterns, for subgraph_search will return the same set of vertices several times ! For example : digraphs.Circuit(3).subgraph_search_count(digraphs.Circuit(3)) returns 3, and not one ! If you only want to count the number of copies of a graph H in G which have a different vertex set, then you should divide the result by H.automorphism_group().cardinality().

Nathann gravatar imageNathann ( 2013-05-26 22:40:01 -0500 )edit

(and you can also create your graphs like that : DiGraph([ (1,2), (2,3) ])

Nathann gravatar imageNathann ( 2013-05-26 22:40:46 -0500 )edit

Thanks, I use numpy as I have to do some matrices manipulation on the starting graph. But thanks for the reminder!

gvdr gravatar imagegvdr ( 2013-05-27 08:26:29 -0500 )edit

Yep, the induce option works! I overview that part (but take into account the automorphism group cardinality...). Thanks twice.

gvdr gravatar imagegvdr ( 2013-05-27 08:35:26 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-05-26 19:02:15 -0500

Seen: 218 times

Last updated: May 26 '13