[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[igraph] Re: help
From: |
Gabor Csardi |
Subject: |
[igraph] Re: help |
Date: |
Thu, 30 Aug 2007 23:38:52 +0200 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
On Thu, Aug 30, 2007 at 11:34:56AM -0400, Epiphanie
Nyirabahizi/nyirabahizie/O/VCU wrote:
> Let make it simple and see it you will get my idea;
>
> It’s like 2 randomly generated clusters with 10, 20 nodes respectively, and p
> =.8.
>
> But I want the connection between the two clusters to be very low (p=.2 or
> less)
>
> And only nodes with higher degrees should be the most likely to connect the
> two
> clusters.
>
>
>
> Two clusters (graphs)
>
> 1.10 nodes
>
> 2. 20 nodes
>
> 3. probability of connection within cluster=.8
>
>
>
> Network from the two clusters:
>
> The probability of connection between cluster=.2
>
> Highly connected nodes are most likely to connect the two clusters.
>
>
>
> Epiphanie
>
>
>
This is not easy, the extra edges between the two clusters must be added
"by hand". Something like this can be used:
g1 <- erdos.renyi.game(10, .8)
g2 <- erdos.renyi.game(20, .8)
g <- g1 %du% g2
# M will contain the probabilities to connect vertex i from g1 to vertex
# j from g2
# Here the probability to connect a k1 and a k2 vertex is defined
# to be proportional to both k1 and k2. We add 1 to give a chance
# for zero degree vertices too. You might want to modify the
# d1[x]*d2[y]+1 function...
d1 <- degree(g1)
d2 <- degree(g2)
M <- outer(seq(vcount(g1)), seq(vcount(g2)),
function(x, y) { d1[x]*d2[y]+1 })
# Now we norm M to have mean 0.2 and extract the random edges.
# We need to add vcount(g1) to the second column to get the
# new vertex ids. The disjoint union operation luckily keeps
# the order of the vertex ids.
M <- M/mean(M)* 0.2
M <- runif(M) < M
extra <- which(M, arr.ind=TRUE)-1
extra[,2] <- extra[,2] + vcount(g1)
# That is all, we can add them.
g <- add.edges(g, t(extra))
# It is nice to plot the graph with different colors for the
# two clusters, the layout algorithm cleverly collects vertices
# with the same color, that means that indeed they form denser
# subgraphs. We write the degree of the nodes before merging the
# two clusters and the number of extra edges also as labels.
v1 <- seq(vcount(g1))-1
v2 <- vcount(g1)+seq(vcount(g2))-1
V(g)[v1]$color <- "blue"
V(g)[v2]$color <- "red"
V(g)[v1]$label <- paste(d1, degree(g,v1)-d1, sep=",")
V(g)[v2]$label <- paste(d2, degree(g,v2)-d2, sep=",")
E(g)$color <- "grey"
E(g)[ v1 %--% v2 ]$color <- "green"
plot(g, layout=layout.fruchterman.reingold, vertex.size=7,
vertex.label.dist=0.5)
You might want to double check that the code really does what it
should.
Gabor
ps. I'm sending this to the list too, in case someone is interested,
and it is also a good example for some nice R/igraph features.
--
Csardi Gabor <address@hidden> MTA RMKI, ELTE TTK
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [igraph] Re: help,
Gabor Csardi <=