igraph / xdata-igraph

xdata igraph, has been merged into igraph/igraph
GNU General Public License v2.0
18 stars 3 forks source link

bug of local.scan (k=0,weighted=F,mode='all') in igraph_0.6.999-995 #34

Closed whalesandro closed 10 years ago

whalesandro commented 10 years ago

Hello Gabor,

I should find this earlier but i hope this is not too late. It's better than nothing! a bug was found in local.scan in latest igraph. Could you help us fix it? thanks a lot. The following is reproduced code for verification. local.scan1 is my R function and local.scan is implemented in igraph. Please let me know any question. ... set.seed(123456) g1 <- erdos.renyi.game(n=10,p=0.1,directed=TRUE) g2 <- erdos.renyi.game(n=10,p=0.2,directed=TRUE) local.scan(graph.us=g2,graph.them=g1,k=0,mode='all') local.scan1(g=g2,gp=g1,k=0,mode='all') par(mfrow=c(1,2)) plot(g1);plot(g2); ...

results are ...

set.seed(123456) g1 <- erdos.renyi.game(n=10,p=0.1,directed=TRUE) g2 <- erdos.renyi.game(n=10,p=0.2,directed=TRUE) local.scan(graph.us=g2,graph.them=g1,k=0,mode='all') [1] 1 1 1 0 0 0 0 1 0 0 local.scan1(g=g2,gp=g1,k=0,mode='all') [1] 2 2 2 0 1 0 0 4 1 0 ..

rplot

Best, Heng

gaborcsardi commented 10 years ago

I am not sure if this a bug in igraph. Take vertex 1 for example. In g2 it has incident edges 1->2, 1->3, 3->1, 1->8, 1->9, 10->1. Out of these edges, only 1->8 is kept, so the correct answer for vertex 1 is 1. Isn't it?

whalesandro commented 10 years ago

Hi Gabor, thanks, you are right. i guess i misunderstood this today. sorry for the confusion. Heng

gaborcsardi commented 10 years ago

No worries, I am not sure what is right myself, because the definition of "scan-0 them" is not too clear to me. So if you realize igraph is not using the right definition, please reopen this issue. Thanks.

youngser commented 10 years ago

Because he uses mode="all", I believe his code counts edges both from 1->8 and 8->1 in g1, where 8->1 isn't in g2. You're right, it's just matter of how you define it! :-) Thanks!

gaborcsardi commented 10 years ago

Yes, but what is the correct definition? I mean the definition used in the paper(s)?

youngser commented 10 years ago

We've never used mode="all" in our papers, i.e., we've been using only "out" so far. Right, Heng? But, by definition, we use ecount(subgraph(g1,neighborhood(g2,k,v,mode)), so I think counting both "in" and "out" for mode="all" seems to be consistent...

gaborcsardi commented 10 years ago

ecount(subgraph(g1,neighborhood(g2,k,v,mode)) will give you zero for k=0, except if v has loop edges.

youngser commented 10 years ago

Ah, my bad. That's the definition for k>0. For k=0, we use

sapply(1:n,function(x) {
+                 vid <- unlist(neighborhood(g2,1,x,mode));
+                 x.rank <- which(sort(vid)==x);
+                 degree(induced.subgraph(g1,vid),mode)[x.rank]})
 [1] 2 2 2 0 1 0 0 4 1 0
youngser commented 10 years ago

Heng still likes your definition. So, let's leave it as it is.