# networkx.algorithms.assortativity.average_degree_connectivity¶

average_degree_connectivity(G, source='in+out', target='in+out', nodes=None, weight=None)[source]

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 1, 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)

• source (“in”|”out”|”in+out” (default:”in+out”)) – Directed graphs only. Use “in”- or “out”-degree for source node.

• target (“in”|”out”|”in+out” (default:”in+out”) – Directed graphs only. Use “in”- or “out”-degree for target node.

• nodes (list or iterable (optional)) – Compute neighbor connectivity for these nodes. The default is all nodes.

• weight (string or None, optional (default=None)) – The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1.

Returns

d – A dictionary keyed by degree k with the value of average connectivity.

Return type

dict

Raises

ValueError – If either source or target are not one of ‘in’, ‘out’, or ‘in+out’.

Examples

>>> G=nx.path_graph(4)
>>> G.edges[1, 2]['weight'] = 3
>>> nx.k_nearest_neighbors(G)
{1: 2.0, 2: 1.5}
>>> nx.k_nearest_neighbors(G, weight='weight')
{1: 2.0, 2: 1.75}


neighbors_average_degree()
This algorithm is sometimes called “k nearest neighbors” and is also available as k_nearest_neighbors.