[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Weighted bipartite graphs?
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] Weighted bipartite graphs? |
Date: |
Sun, 29 Nov 2009 17:30:40 +0100 |
OK, I added support for keeping the "multiplicity" information of the
edges, this is done automatically:
> print(proj[[2]], e=T)
Vertices: 8
Edges: 19
Directed: FALSE
Edges and their attributes:
weight
[0] 'P1' -- 'P2' 1
[1] 'P1' -- 'P3' 1
[2] 'P1' -- 'P4' 1
[3] 'P1' -- 'P5' 2
[4] 'P1' -- 'P6' 1
[5] 'P1' -- 'P7' 1
[6] 'P1' -- 'P8' 1
[7] 'P2' -- 'P3' 1
[8] 'P2' -- 'P4' 1
[9] 'P2' -- 'P5' 1
[10] 'P3' -- 'P4' 1
[11] 'P3' -- 'P5' 1
[12] 'P4' -- 'P5' 1
[13] 'P5' -- 'P6' 1
[14] 'P5' -- 'P7' 1
[15] 'P5' -- 'P8' 1
[16] 'P6' -- 'P7' 1
[17] 'P6' -- 'P8' 1
[18] 'P7' -- 'P8' 1
Best,
Gabor
On Sun, Nov 29, 2009 at 2:50 PM, Gábor Csárdi <address@hidden> wrote:
> Dear Uri,
>
> On Mon, Nov 23, 2009 at 9:27 PM, Uri Shwed <address@hidden> wrote:
>> Dear Gabor et.al.,
>> What would you guys say is the best way to get a bipartite data set with
>> meta-data into a weighted projection?
>> For example:
>>
>> data<-data.frame(people=c(1:5,5:8,1),events=c(1,1,1,1,1,2,2,2,2,2),year=c(2004,2004,2004,2004,2004,2005,2005,2005,2005,2005))
>>
>> desired outcome:
>> The first graph projection below (achieved through graph.incidence and
>> bipartite.projection), with Edge attribute of weight (giving all edges
>> weight of 1 and the edge between 1 and 5 a weight of 2, because they
>> attended 2 events together), and an edge attribute of year.
>> Any ideas?
>
> I am not sure what you did with graph.incidence, but this is what I would do.
>
> library(igraph)
> data<-data.frame(people=c(1:5,5:8,1),events=c(1,1,1,1,1,2,2,2,2,2),year=c(2004,2004,2004,2004,2004,2005,2005,2005,2005,2005))
> data2 <- data.frame(people=paste(sep="", "P", data[,1]),
> events=paste(sep="", "E", data[,2]))
> G <- graph.data.frame(data2, dir=FALSE)
> V(G)$type <- grepl("^P", V(G)$name)
>
> proj <- bipartite.projection(G)
> V(proj[[1]])$name <- V(G)$name[!V(G)$type]
> V(proj[[2]])$name <- V(G)$name[V(G)$type]
> # We use here that bipartite.projection keeps the order of the vertices
> # ideally it should keep the vertex attributes
>
> Unfortunately, there is no way currently to include the "multiplicity"
> as edge weight,
> at least not easily. But this would be a logical extension, so I will
> add it ASAP.
>
> Best,
> G.
>
>> $proj1
>> Vertices: 8
>> Edges: 19
>> Directed: FALSE
>> Edges:
>>
>> [0] 0 -- 1
>> [1] 0 -- 2
>> [2] 0 -- 3
>> [3] 0 -- 4
>> [4] 0 -- 5
>> [5] 0 -- 6
>> [6] 0 -- 7
>> [7] 1 -- 2
>> [8] 1 -- 3
>> [9] 1 -- 4
>> [10] 2 -- 3
>> [11] 2 -- 4
>> [12] 3 -- 4
>> [13] 4 -- 5
>> [14] 4 -- 6
>> [15] 4 -- 7
>> [16] 5 -- 6
>> [17] 5 -- 7
>> [18] 6 -- 7
>>
>> $proj2
>> Vertices: 2
>> Edges: 1
>> Directed: FALSE
>> Edges:
>> e
>> e [0] 0 -- 1
>>
>>
>> Thanks,
>> Uri
>>
>>
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/igraph-help
>>
>
>
>
> --
> Gabor Csardi <address@hidden> UNIL DGM
>
--
Gabor Csardi <address@hidden> UNIL DGM