igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] igraph-help Digest, Vol 118, Issue 5


From: MikeS
Subject: Re: [igraph] igraph-help Digest, Vol 118, Issue 5
Date: Wed, 8 Jun 2016 00:11:08 +0700

Tamas, thanks.
I think you understood me correctly. Sorry for my explanation.

Below is the work example.
For simple case, I can turn the directed graph G into the undirected
weighed graph UG.
Unfortunately, I couldn't use the loop 'for' and the statement 'if' in
order to use for any directed graph G(|V|=3, E).
My current problem is index '1' in the brackets 'eids[1]'.
I don't know how to select this index correctly from the range [1, 6].
On the step # 2 I have obtained the six possible combinations:
> eids
[[1]]
[1] 1 3 2

[[2]]
[1] 2 3 1

[[3]]
[1] 1 2 3

[[4]]
[1] 3 2 1

[[5]]
[1] 2 1 3


library(igraph)
set.seed(42)

d_3 <- matrix(c(0,1,0, 0,0,1, 1,1,0),nrow=3,ncol=3)

G <- graph.adjacency(d_3)
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(y) vertices_of_triangle(sbg.triangle[[y]]) )

# edge IDs triangle in the undirected graph
eids <- lapply(1:k, function(z) get.edge.ids(graph = UG, vp =
as.numeric(unlist(vlist[z])) ))

# 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

i <- 2
j <- 1
#for(i in 1:k){
   #  if (length(subisom[[i]]>0){
        for(j in 1:length(subisom[[i]] )){
         E(UG)[unlist(eids[1])]$weght <- i # why is '1' in the 'eids[1]'?
        }
    # } # if
#} # for_i

plot(UG, edge.arrow.size=0.2, edge.label=E(UG)$weght)

--
MikeS

2016-06-07 23:00 GMT+07:00  <address@hidden>:
> Send igraph-help mailing list submissions to
>         address@hidden
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://lists.nongnu.org/mailman/listinfo/igraph-help
> or, via email, send a message with subject or body 'help' to
>         address@hidden
>
> You can reach the person managing the list at
>         address@hidden
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of igraph-help digest..."
>
>
> Today's Topics:
>
>    1. Re: Turn a directed network into a weighted undirected
>       network (MikeS)
>    2. Re: Turn a directed network into a weighted undirected
>       network (Tamas Nepusz)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 7 Jun 2016 15:15:38 +0700
> From: MikeS <address@hidden>
> To: address@hidden
> Subject: Re: [igraph] Turn a directed network into a weighted
>         undirected network
> Message-ID:
>         <address@hidden>
> Content-Type: text/plain; charset=UTF-8
>
> 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
>
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 7 Jun 2016 12:04:24 +0200
> From: Tamas Nepusz <address@hidden>
> To: Help for igraph users <address@hidden>
> Subject: Re: [igraph] Turn a directed network into a weighted
>         undirected network
> Message-ID:
>         <address@hidden>
> Content-Type: text/plain; charset=UTF-8
>
> Hi,
>
> I'm not sure if I completely understand your problem. After step #3,
> you get a list consisting of four other lists; subisom[[1]] contains
> all the triangles that are isomorphic to template graph #1,
> subisom[[2]] contains all the triangles that are isomorphic to
> template graph #2 and so on. So, in your example, since the triangle
> appears in subisom[[2]], therefore it must be isomoprhic to template
> graph #2.
>
> T.
>
>> 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
>>
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
>
> ------------------------------
>
> End of igraph-help Digest, Vol 118, Issue 5
> *******************************************



reply via email to

[Prev in Thread] Current Thread [Next in Thread]