average_neighbor_degree#
- graph_tool.correlations.average_neighbor_degree(g, source='out', target='out', weight=None, vprop=None)[git][source]#
Return the average degree of the neighbors of every vertex.
- Parameters:
- g
Graph Graph to be used.
- source
str(optional, default:"out") For directed graphs, which neighbors are averaged: those along the
"out"-edges, the"in"-edges, or both ("total").- target
str(optional, default:"out") Degree of the neighbors that is averaged:
"out","in", or"total".- weight
EdgePropertyMap(optional, default:None) Edge weights, which weight the average.
- vprop
VertexPropertyMap(optional, default:None) If provided, the values will be stored in this property map.
- g
- Returns:
- knn
VertexPropertyMap The average neighbor degree of every vertex (zero for vertices without neighbors).
- knn
See also
avg_neighbor_corrAverage nearest-neighbor correlation
scalar_assortativityScalar assortativity coefficient
Notes
The average neighbor degree [barrat-architecture-2004] is
\[k_{nn,i} = \frac{1}{s_i}\sum_j w_{ij}k_j,\]where \(s_i = \sum_j w_{ij}\), \(k_j\) is the degree of vertex \(j\) of the kind given by
target(for undirected graphs, simply its degree), and \(w_{ij}\) is the sum of the weights of the edges from \(i\) to \(j\) (source="out"), from \(j\) to \(i\) (source="in"), or both (source="total"), with unit weights ifweightis not given, so that parallel edges are counted separately. For undirected graphs, \(w_{ij}\) is the total weight of the edges between \(i\) and \(j\), with self-loops counted twice. The value is zero for vertices with \(s_i = 0\). Its average as a function of the degree is given byavg_neighbor_corr(). The algorithm runs in time \(O(V + E)\).References
[barrat-architecture-2004]A. Barrat, M. Barthélemy, R. Pastor-Satorras and A. Vespignani, “The architecture of complex weighted networks”, Proceedings of the National Academy of Sciences 101, 3747-3752 (2004), DOI: 10.1073/pnas.0400087101 [sci-hub, @tor], arXiv: cond-mat/0311416
Examples
>>> g = gt.collection.data["karate"] >>> knn = gt.average_neighbor_degree(g) >>> print(knn[0], knn[16]) 4.3125 4.0
The values can be visualized by drawing the network with vertex colors and sizes given by them:
>>> cmap = matplotlib.colors.LinearSegmentedColormap.from_list( ... "gray-blue", ["#d9d9d9", "#7dabd1"]) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=knn, vcmap=cmap, ... vertex_size=gt.prop_to_size(knn, mi=5, ma=15), ... output="average_neighbor_degree-karate.pdf") <...>
Average neighbor degree of the vertices of Zachary’s karate club network. The vertex colors, from gray to blue, and the vertex sizes increase with the value.#