igraph-help
[Top][All Lists]

## Re: [igraph] clustering coefficients for bipartite networks

 From: Simone Gabbriellini Subject: Re: [igraph] clustering coefficients for bipartite networks Date: Wed, 2 Feb 2011 13:00:24 +0100

```Hi,

yes, right, I am now doing it... but a strange thing happens: I initialize all
the attributes to 0, but after my function updates them, I save the network as
a graphml and those attributes are missing... If I try to save the graphml file
before my CCBN function, they are all there, set to 0...

Am I deleting them in some way with this code?

best,
simo

Il giorno 01/feb/2011, alle ore 21.20, Tamás Nepusz ha scritto:

> Hi,
>
> 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).
>
> --
> Tamas
>
>
> _______________________________________________
> igraph-help mailing list