Lesson 4 of 15
Network Degree Distribution
Network Degree Distribution
A network (or graph) consists of nodes (vertices) connected by edges. Networks appear everywhere in complex systems: social connections, neural circuits, power grids, the internet.
Representation
We represent networks as adjacency lists — a Python dict mapping each node to a set of its neighbours:
adj = {
0: {1, 2, 3},
1: {0, 2},
2: {0, 1},
3: {0},
}
Degree
The degree of node is the number of its neighbours:
The mean degree of a network with nodes and edges is:
(each edge contributes 2 to the total degree sum).
Degree Distribution
The degree distribution gives the fraction of nodes with exactly neighbours. For:
- Random (Erdős–Rényi) graphs: is Poisson-distributed
- Scale-free (Barabási–Albert) graphs: (power law)
Clustering Coefficient
The local clustering coefficient measures how tightly connected node 's neighbours are:
means all neighbours are connected to each other; means none are.
Your Task
Implement:
node_degree(adj, node)— degree of a single nodemean_degree(adj)— average degree over all nodesdegree_distribution(adj)— dict{k: fraction}of nodes with that degreeclustering_coefficient(adj, node)— local clustering coefficient (return 0 if degree < 2)
Python runtime loading...
Loading...
Click "Run" to execute your code.