igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Random graph


From: Tamás Nepusz
Subject: Re: [igraph] Random graph
Date: Thu, 12 Jul 2012 00:01:53 +0200

> How can I randomly select vertex position assigning different radiuses to 
> each vertex?

What does radius mean in case of a vertex in a graph?
 
> And then, to define that only those at a distance shorter than x are 
> connected by edges? Or that the probability of two vertexes being connected 
> is inverse to the distance between them?

I'm afraid that you have to implement the graph generation methodology for 
these. Since you haven't mentioned whether you are working in R, Python or C 
and the a priori probability is the highest for R, I'm gonna give you an 
example in R. Suppose that the vertex coordinates are given in an Nx2 matrix 
named "coords". You can then do this to obtain the distance matrix:

dist.matrix <- as.matrix(dist(coords))

Then you can get the row and column indices of the elements that have a 
distance smaller than the threshold, and construct the graph:

inds <- which(dist.matrix < threshold, arr.ind = T)
g <- graph(inds)

Sometimes it is useful to fill the diagonal of the distance matrix with NA to 
ensure that no loop edges are created:

diag(dist.matrix) <- NA

Making the probability of a vertex depend on the distance is only a little bit 
more difficult. Assuming that you have a function f that converts your distance 
matrix to probabilities, you can simply do this:

n <- nrow(coords)
inds <- which(matrix(runif(n*n), ncol=n) < f(dist.matrix), arr.ind = T)

The rest is the same.

-- 
T.





reply via email to

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