[Top][All Lists]

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

[igraph] degree vs. neighbors degree in bipartite network

From: Simone Gabbriellini
Subject: [igraph] degree vs. neighbors degree in bipartite network
Date: Wed, 9 Mar 2011 17:34:14 +0100

hello list,

following the lead of Jordi on 2-dist neighbors in bipartite networks, here's 
code for the degree vs. neighbors' degree, still on bipartite networks:

def get_neideg(g, node):
        nei = g.neighbors(node)
        nei_deg = []
        for n in nei:
        return sum(nei_deg)/len(nei_deg) if nei_deg else 0

def deg_vs_neideg(g, mode):
        if mode == 'top': t = 0
        else: t = 1
        deg_hist = {}
        for v in g.vs(type=t):
                deg = g.degree(v.index)
                if deg not in deg_hist:
                        deg_hist[deg] = [v.index]
        result = {}
        for deg, lnodes in deg_hist.items():
                r = 0.0
                for node in lnodes:
                        r += get_neideg(node)
                r /= len(lnodes)
                result[deg] = r
        return result

any comment or suggestion or correction more than welcome!


reply via email to

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