[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Turn a directed network into a weighted undirected network
From: |
MikeS |
Subject: |
Re: [igraph] Turn a directed network into a weighted undirected network |
Date: |
Tue, 7 Jun 2016 15:15:38 +0700 |
Hello,
Tamas, thanks a lot.
I have used the your function.
In order to trace calculation step by step, I reduced the original
graph G, now it has only one triangle (type #2).
On the step # 2 I have found all triangles in the undirected graph.
There are k=6 subisomorphisms.
On the step # 3 I have found subisomorphisms in the directed graph to
all of the four templates.
> subisom
[[1]]
list()
[[2]]
[[2]][[1]]
+ 3/3 vertices, named:
[1] a b c
[[3]]
list()
[[4]]
list()
As can see only one list subisom[[2]][[1]] is not empty, and the index
of this list corresponds to the triangle type (type #2). This is the
weight for the triangle in the undirected graph.
I'm looking an idea for the function to check which template graph it
was isomorphic on the step #4:
function_check_which_template_graph_it_was_isomorphic(subisom[j],
sbg.triangle[i])
Could someone please give an idea how to check it?
library(igraph)
set.seed(42)
d <- matrix(c(0,1,0, 0,0,1, 1,1,0),nrow=3,ncol=3)
G <- graph.adjacency(d)
V(G)$name <- letters[1:dim(d)[1]]
V(G)$shape = "none"
plot(G, edge.arrow.size=0.5, edge.curved=TRUE)
# Here are the adjacency matrices for each of the four subgraphs
d0<-matrix(c(0,1,0,0,0,1,1,0,0),nrow=3,ncol=3)
d1<-matrix(c(0,1,0,0,0,1,1,1,0),nrow=3,ncol=3)
d2<-matrix(c(0,1,0,1,0,1,1,1,0),nrow=3,ncol=3)
d3<-matrix(c(0,1,1,1,0,1,1,1,0),nrow=3,ncol=3)
# Turn them into a convenient list
sbgCycle.mat<-list(d0,d1,d2,d3)
n <- length(list(d0,d1,d2,d3))
# And then into a list of graph objects
pattern <- lapply(sbgCycle.mat, graph.adjacency)
# 1. Convert the directed graph to undirected one
UG <- simplify(G)
UG <- as.undirected(UG)
# 2. Search for triangles in the undirected graph
triangle <- graph.full(3)
# names of incident vertices of triangle in the undirected graph
sbg.triangle <- unique(graph.get.subisomorphisms.vf2(UG, triangle))
k <- length(sbg.triangle)
vertices_of_triangle <- function (x) { c(x[1], x[2], x[2], x[3], x[3], x[1]) }
vlist <- lapply(1:k, function(x) vertices_of_triangle(sbg.triangle[[x]]) )
# edge IDs triangle in the undirected graph
eids <- lapply(1:k, function(x) get.edge.ids(graph = UG, vp =
as.numeric(unlist(vlist[x])) ))
# 3. Search for subisomorphisms in the directed graph to all of the
four templates
subisom <- lapply(1:n, function(x) subgraph_isomorphisms(pattern[[x]],
G, method="lad", induced=TRUE))
# 4. For each triangle check which pattern it was isomorphic
for(i in 1:k)
{
for(j in 1:n)
{
weght_triangle <-
function_check_which_template_graph_it_was_isomorphic(subisom[j],
sbg.triangle[i])
} # for_j
E(UG)[eids[k]]$weght <- weght_triangle
} # for_i
plot(UG, edge.arrow.size=0.2, edge.label=E(UG)$weght)
--
Mikes
- Re: [igraph] Turn a directed network into a weighted undirected network,
MikeS <=