[Top][All Lists]

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

Re: [igraph] clustering coefficients for bipartite networks

From: Tamás Nepusz
Subject: Re: [igraph] clustering coefficients for bipartite networks
Date: Tue, 1 Feb 2011 21:20:50 +0100


Cache the values of g.vs(type=0) and g.vs(type=1) in advance, otherwise you 
will be calculating them over and over again needlessly. (The first inner for 
loop will calculate g.vs(type=0) as many times as many vertices of type=0 you 
have). Similarly, calculate the neighbor sets in advance to avoid creating them 
all the time from scratch.

Also, there's no need to convert set(unei+vei) back to a list, just use 
len(set(unei) | set(vnei)).

> I have come to this solution but I don't know if I can consider it a fast one:
>    def CCBN(self):
>        for u in self.g.vs(type=0):
>            ccdot = []
>            for v in g.vs(type=0):

>                unei = g.neighbors(u)
>                vnei = g.neighbors(v)
>                if len(set(unei) & set(vnei)) > 0:
>                    ccdot.append(len(set(unei) & set(vnei)) / 
> len(list(set(unei + vnei))))
>            u['ccdot'] = [float(sum(ccdot)) / len(ccdot) if len(ccdot) > 0 
> else 0] 
>        for u in g.vs(type=1):
>            ccdot = []
>            for v in g.vs(type=0):
The line above should probably be g.vs(type=0). Also, note that the two for 
loops are almost the same, only the vs the for loop is iterating over is 
different, so I would probably put the two for loops in an auxiliary function 
and just call it twice, once with g.vs(type=0) and once with g.vs(type=1).


reply via email to

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