[Top][All Lists]

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

Re: [igraph] clustering coefficients for bipartite networks

From: Tamas Nepusz
Subject: Re: [igraph] clustering coefficients for bipartite networks
Date: Wed, 02 Feb 2011 15:54:59 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7


The ccdot attribute is probably a list at the end of your function, and
lists cannot be saved as GraphML attributes. If you need them later,
save the graph in pickle format which preserves all the attributes
irrespectively of their types. (But of course you cannot load the graph
from another program, only from Python).


On 02/02/2011 01:00 PM, Simone Gabbriellini wrote:
> 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
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/igraph-help
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help

reply via email to

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