[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] making random graphs from matrices
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] making random graphs from matrices |
Date: |
Thu, 23 Feb 2012 12:58:29 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111229 Thunderbird/9.0 |
Dear Robin,
Assuming that your square matrix of probabilities is given in a matrix p,
you can do this:
> p <- matrix(c(0,0.5,0.5,0.5, 0.5,0,0.5,0.5, 0,0,0,0, 1,0,1,0), nrow=4)
> r <- matrix(runif(nrow(p)*ncol(p)), nrow=nrow(p))
> g <- graph.adjacency(r < p, mode="undirected")
--
T.
On 02/23/2012 11:40 AM, Robin Cowan wrote:
> Dear List,
>
> Is there a simple way of taking a square (symmetric) matrix of reals
> and generating a random graph of fixed density using that matrix as
> the (relative) probability of a particular link forming.
>
> I am using igraph inside R.
>
> It seems one way to do that would be with a two-dimensional version
> of the sample() statement, to create an adjacency matrix, but I can't
> find documentation on that.
>
> It also seems related to igraph's preference.game() but I can't see a
> way there to control density
>
> Thanks for your help.
>
> Robin Cowan
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>