NetworkX

Previous topic

networkx.algorithms.neighbor_degree.k_nearest_neighbors

Next topic

networkx.algorithms.neighbor_degree.average_neighbor_in_degree

networkx.algorithms.neighbor_degree.average_neighbor_degree

networkx.algorithms.neighbor_degree.average_neighbor_degree(G, nodes=None, weighted=False)

Returns the average degree of the neighborhood of each node.

The average degree of a node i is

k_{nn,i} = \frac{1}{|N(i)|} \sum_{j \in N(i)} k_j

where N(i) are the neighbors of node i and k_j is the degree of node j which belongs to N(i). For weighted graphs, an analogous measure can be defined [R142],

k_{nn,i}^{w} = \\frac{1}{s_i} \sum_{j \in N(i)} w_{ij} k_j

where s_i is the weighted degree of node i, w_{ij} is the weight of the edge that links i and j and N(i) are the neighbors of node i.

Parameters :

G : NetworkX graph

nodes: list or iterable (optional) :

Compute neighbor connectivity for these nodes. The default is all nodes.

weighted: bool (default=False) :

Compute weighted average nearest neighbors degree.

Returns :

d: dict :

A dictionary keyed by node with average neighbors degree value.

Notes

For directed graphs you can also specify in-degree or out-degree by calling the relevant functions.

References

[R142](1, 2) A. Barrat, M. Barthélemy, R. Pastor-Satorras, and A. Vespignani, “The architecture of complex weighted networks”. PNAS 101 (11): 3747–3752 (2004).

Examples

>>> G=nx.path_graph(4)
>>> G.edge[0][1]['weight'] = 5
>>> G.edge[2][3]['weight'] = 3
>>> nx.average_neighbor_degree(G)
{0: 2.0, 1: 1.5, 2: 1.5, 3: 2.0}
>>> nx.average_neighbor_degree(G, weighted=True)
{0: 2.0, 1: 1.1666666666666667, 2: 1.25, 3: 2.0}
>>> G=nx.DiGraph()
>>> G.add_path([0,1,2,3])
>>> nx.average_neighbor_in_degree(G)
{0: 1.0, 1: 1.0, 2: 1.0, 3: 0.0}
>>> nx.average_neighbor_out_degree(G)
{0: 1.0, 1: 1.0, 2: 0.0, 3: 0.0}