braintools.analysis.graph.degree_distribution#
- braintools.analysis.graph.degree_distribution(conn, *, direction='in')#
Compute node degrees and their histogram.
The graph is treated as directed and unweighted: the degree counts edges, not weights. Repeated pairs count once. A self-loop counts once in the in- and the out-degree and twice in the total degree, as in networkx.
- Parameters:
conn (
Any) – Connectivity with rows as pre and columns as post neurons. It may be rectangular (pre and post populations of different sizes) fordirection='in'or'out'.direction (
str) –'in': number of incoming edges of each post neuron (column counts);'out': outgoing edges of each pre neuron (row counts);'total': their sum, asnetworkx.DiGraph.degree(needs a square connectivity).
- Returns:
Named tuple
(degrees, values, counts).- Return type:
- Raises:
ValueError – If
directionis unknown, or'total'is asked for a rectangular connectivity.
See also
clustering_coefficientLocal clustering of every node.
Notes
Host-only (NumPy/SciPy): not traceable by
jax.jit,jax.vmaporjax.grad.Examples
>>> import numpy as np >>> from braintools.analysis.graph import degree_distribution >>> adj = np.array([[0, 1, 1], [0, 0, 1], [0, 0, 0]]) >>> result = degree_distribution(adj, direction='in') >>> result.degrees array([0, 1, 2]) >>> result.counts array([1, 1, 1]) >>> >>> degree_distribution(adj, direction='total').degrees array([2, 2, 2]) >>> >>> self_loop = np.array([[1, 0], [1, 0]]) # 0 -> 0 and 1 -> 0 >>> degree_distribution(self_loop, direction='total').degrees array([3, 1])