igraph-help
[Top][All Lists]

## Re: [igraph] making random graphs from matrices

 From: robin cowan Subject: Re: [igraph] making random graphs from matrices Date: Fri, 24 Feb 2012 09:50:25 +0100

Thanks Tamas. I figured out how to use sample in 2 dimensions, so I can do it that way.
```Robin

On 23-Feb-12, at 12:58 PM, Tamas Nepusz wrote:

```
```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

Robin Cowan

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

```
```
_______________________________________________
igraph-help mailing list
```