Question

The question was correctly answered in http://ask.sagemath.org/question/2612/motifs-and-subgraphs

I'm counting the number of 3-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... I could remove from the graph the occurrence of S2 after having counted them, but that would be really a awful trick (and dangerous if I wanted to count also 4 motifs).

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)
Was it helpful?

Solution

The trick was to include the option induce=true in the subgraph_search() function as correctly answered in http://ask.sagemath.org/question/2612/motifs-and-subgraphs .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top