NetworkX

Previous topic

networkx.algorithms.neighbor_degree.average_in_degree_connectivity

Next topic

networkx.algorithms.neighbor_degree.k_nearest_neighbors

networkx.algorithms.neighbor_degree.average_out_degree_connectivity

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

Compute the average degree connectivity of graph.

The average degree connectivity is the average nearest neighbor degree of nodes with degree k. For weighted graphs, an analogous measure can be computed using the weighted average neighbors degree defined in [R145], for a node i, as:

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 degree k with the value of average neighbor degree.

See also

neighbors_average_degree

Notes

This algorithm is sometimes called “k nearest neighbors’.

References

[R145](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[1][2]['weight'] = 3
>>> nx.k_nearest_neighbors(G)
{1: 2.0, 2: 1.5}
>>> nx.k_nearest_neighbors(G, weighted=True)
{1: 2.0, 2: 1.75}