0

I'm looking for motifs of size 5 in graphs with less than 5000 nodes and less than 10000 edges. (everything uncolored)

To do this I use function provided in igraph library for R subgraph_isomorphisms using method vf2 (see example below). I use adjacency matrix to generate subgraph and edgelist to generate the graph itself.

A lot of isomorphic subgraphs that I find have extra edges. Is there any way to only find subgraphs with exact given structure? Looking for answers using igraph or any other library in R

See reproducible example below (looking at this example is way easier if you just draw graph given by this adjacency matrix on a piece of paper)

library(igraph)

subgraph <- matrix(
  data = c(0, 1,
           1, 0), ncol = 2)

graph <- matrix(
  data = c(0, 1, 0, 0,
           1, 1, 0, 1,
           1, 0, 0, 1,
           0, 0, 1, 0), ncol = 4)

subgraph <- graph_from_adjacency_matrix(subgraph, mode = "directed", weighted = T, diag = T)
graph    <- graph_from_adjacency_matrix(graph,    mode = "directed", weighted = T, diag = T)
subgraph_isomorphisms(subgraph, graph, method = "vf2")

Output gives you two pairs of (1,2) and (3,4), when in fact adjacency matrix of (1,2) looks like

(0 1) (1 1)

Which is different from the one we were looking for

Ian
  • 53
  • 9
  • A subgraph of a graph G is another graph formed from a **subset** of the vertices and **edges** of G. That is subgraphs do not need to contain all edges connected to the vertices of the subgraph – emilliman5 Jun 11 '19 at 12:18
  • Right, but I'm looking for subgraphs, that are isomorphical to a given graph. My best guess is that there is something about definition of isomorphism that I don't understand or this algorithm is doing something weird, but I read the paper and it seems like it should be looking for exact solution, so I'm confused – Ian Jun 11 '19 at 15:31
  • A subgraph is **any** subset of vertices and edges from graph G. Using your example data for vertices 1 and 2: [1->2; 2->1], [1->2], [2->1], [1->2; 2->1, 2->2], [1->2, 2->2], [2->1, 2->2] are all valid subgraphs. These subgraphs get searched against your pattern subgraph. – emilliman5 Jun 11 '19 at 15:39
  • Ok. I see, I missed one important thing in a question. What I'm looking for are subgraphs of a graph, that are isomorphic to externally given graph. Examples, that you are giving sure are subgraphs with vertices (1, 2), but they are not what I'm looking for. Thank you for the comment, corrected that – Ian Jun 11 '19 at 16:20

2 Answers2

1

The answer to this question is in definitions of what I'm looking for and what I'm finding.

What I was looking for was network motifs of size 5. When I'm looking for network motifs from the graph theory perspective it means that I'm looking for induced subgraphs with given adjacency matrix.

What this function does is it finds subgraphs of a graph that are isomorphic to a given graph. The difference is I was looking for induced subgraph, whereas the function just gives subgraphs, so extra edges are allowed.

That is exactly the problem that I was experiencing. To deal with it I ended up just comparing adjacency matrix of subgraphs that I found with those of the motif. Hope it will be helpful to someone.

Ian
  • 53
  • 9
0

Adding to the previous comment, I also noticed that the function returns "True" when I try to find an isomorphic triad of type 210 (2 mutual edges and 1 asymmetric) within a complete graph of four vertices. The solution is to add:

subgraph_isomorphisms(subgraph, graph, method = "vf2", **induced = TRUE**)
StupidWolf
  • 45,075
  • 17
  • 40
  • 72