igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] degrees of separation


From: Marie Lalanne
Subject: Re: [igraph] degrees of separation
Date: Mon, 24 Jun 2013 12:23:58 +0100 (BST)

Hi Gabor,

The program works very well on a small edgelists. I have several edgelists, the bigger one contains almost 5000000 edges and when I launch for example the command "sum(colSums(g[s,-s]) != 0)", it says "index larger than maximal 149383" so I guess this is because my data is too big. If it is the case, do you have an idea on how I can solve this?
Many thanks again for your help!

Best regards,
Marie


De : Gábor Csárdi <address@hidden>
À : Marie Lalanne <address@hidden>
Cc : Help for igraph users <address@hidden>
Envoyé le : Jeudi 23 mai 2013 19h18
Objet : Re: [igraph] degrees of separation

On Wed, May 22, 2013 at 6:28 AM, Marie Lalanne <address@hidden> wrote:
Hi Gabor,

many thanks for your quick answer.

When I write one of the command with "g[a,b]", R is telling me that the dimension is not correct. I guess this is due to the graph object (which is a list of edges so R understands one dimension, maybe?)

Maybe you have an old igraph version, or get this is weird bug with the most recent version. It does not work for the first call, but it does for the second and others. If you explicitly load the Matrix package, then it is all good:

library(Matrix)
library(igraph)
data <- "1 2
1 3
2 3
2 5
3 4
3 5
4 5
"
g <- graph.data.frame(read.table(textConnection(data)), 
       directed=FALSE, vertices=data.frame(1:5))
s <- c(1,2)
v <- 4

sum(colSums(g[s,-s]) != 0)

The command "shortest.paths" cannot have as argument "to=1" so I have found the following way to compute the shortest path:

Maybe you really have an old igraph version. The most recent version does have a 'to' argument:
 
c<-get.all.shortest.paths(g, v, to=s)
d<-lapply(c, length)
min(unlist(d))

I did a mistake in my first question: in my example, the number of vertices connected to s would be 3 but I would like to get the number 2 instead (because I want to count 1 for the link 2-5 and 1 for the links 1-3 and 2-3).

I think my code does give 2.

Gabor
 

Many thanks again for all your help!
Very best,
Marie




De : Gábor Csárdi <address@hidden>
À : Marie Lalanne <address@hidden>; Help for igraph users <address@hidden>
Envoyé le : Mardi 21 mai 2013 18h57
Objet : Re: [igraph] degrees of separation

Hi, please see below.

On Tue, May 21, 2013 at 12:11 PM, Marie Lalanne <address@hidden> wrote:
Hello,

I am a new R and igraph user and I am wondering whether you could give me some hints to do the following:

Assuming 'g' is the graph, 's' the subset and 'v' the vertex:

library(igraph)
data <- "1 2
1 3
2 3
2 5
3 4
3 5
4 5
"
g <- graph.data.frame(read.table(textConnection(data)), 
       directed=FALSE, vertices=data.frame(1:5))
s <- c(1,2)
v <- 4


I have an edgelist (undirected). I would like to compute the following four things:
- for a subset of vertices, the number of edges (without counting twice a same vertex linked with two different vertices of the subset)

So this is effectively the number of vertices connected to s? 

sum(colSums(g[s,-s]) != 0)
 
- for a subset of vertices, if at least one of the vertices from this subset is linked with a particular vertex (from the whole set)

any(g[s,v] != 0)
 
- for a subset of vertices, the minimal degree of separation required to reach a particular vertex (from the whole set)

min(shortest.paths(g, v=4, to=s))
 
- for all the vertices (in the whole set), if they are linked with at least one vertex from the subset

colSums(g[s,]) != 0

Please see the manual, in particular ?'[.igraph' for details.

Best,
Gabor

ps. be critical with my answers, and check them, I haven't checked them too extensively. 


For example:
1-2
1-3
2-3
2-5
3-4
3-5
4-5
and consider the subset of vertices being 1 and 2 and the particular vertex being 4
Answer to the first question: 3 (edges 1-3 and 2-3 are count only for one)
Answer to the second question: 0 (neither 1, neither 2 is directly linked to 4)
Answer to the third question: 2 (edge 1-3 and then edge 3-4 or edge 2-3 and then edge 3-4)
Answer to the fourth question: [1] - [2] - [3] 1 [4] 0 [5] 1

Many thanks for your help!

_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help




--
Gabor Csardi <address@hidden>     MTA KFKI RMKI





--
Gabor Csardi <address@hidden>     MTA KFKI RMKI



reply via email to

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