igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Calculation of Coordination Number


From: Gabor Csardi
Subject: Re: [igraph] Calculation of Coordination Number
Date: Sun, 17 Feb 2008 19:19:13 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Lorenzo, i'm not sure why you would like to use adjacency matrices,
igraph graphs are much better in most cases, espacially if the graph 
is large. Here is how to calculate the mean degree per connected 
component in R, assuming your graph is 'g':

comps <- decompose.graph(g)
sapply(comps, function(x) mean(degree(x)))

Gabor

On Sun, Feb 17, 2008 at 07:13:07PM +0100, Lorenzo Isella wrote:
> Hello,
> Thanks for your answers and sorry for the late reply.
> One final question: since I deal with rather large adjacency matrices, I 
> need to be efficient when working out the quantities of interest.
> For instance, starting from the adjacency matrix, I first work out the 
> connected components, then I would like to evaluate the mean degree (thanks 
> for fixing my jargon) within each set of connected components.
> What is the most efficient way of doing this, without re-writing the 
> adjacency matrix for the components I already know to be connected and 
> re-calculating various properties I know already plus the mean degree?
> Cheers
> 
> Lorenzo
> 
> 
> 
> Message: 15
> Date: Wed, 13 Feb 2008 10:47:50 +0100
> From: Tamas Nepusz <address@hidden>
> Subject: Re: [igraph] Calculation of Coordination Number
> To: Help for igraph users <address@hidden>
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
> 
> 
> >> Lorenzo,
> >> if your graph is `g` then
> >>    degree(g)
> >> gives the number of direct neighbors of each vertex (or particle).
> >  
> Just to translate it to Python: g.degree() gives the number of direct  
> neighbors of each vertex. If your graph is directed, you may only want  
> to count only the outgoing or the incoming edges: g.degree(igraph.OUT)  
> or g.degree(igraph.IN)
> 
> 
> >> So
> >>    mean(degree(g))
> >  
> In Python: sum(g.degree()) / float(g.vcount())
> 
> 
> >> (and to turn an adjacency matrix `am` into an igraph object `g` just  
> >> use "g <- graph.adjacency(am)")
> >  
> In Python: g = Graph.Adjacency(matrix)
> e.g. g = Graph.Adjacency([[0,1,0],[1,0,1],[0,1,0]])
> 
> -- T.
> 
> 
> 
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help

-- 
Csardi Gabor <address@hidden>    UNIL DGM




reply via email to

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