Hands-on: Measuring How Small the World Is
You now know what average path length and clustering mean. Here you measure them, on networks whose answers you can check by hand and on networks large enough that you cannot.
NoteWhere the code lives
This course keeps its lecture note free of runnable code. Everything you execute lives in a marimo notebook, so it stays interactive and reactive instead of being a wall of output frozen into a web page.
Run this notebook — it runs in your browser, with nothing to install and nothing to sign into. The first load takes a few seconds while Python itself is downloaded.
Prefer to work locally? The notebook is in the repository at notebooks/m02-small-world/coding.py. Run it with marimo edit notebooks/m02-small-world/coding.py.
What you will build
- Build a graph in igraph from an edge list, then compute shortest paths and pull out connected components. The library is new; the concepts are the ones from Module 1 and from the previous page.
- Compute local, average-local and global clustering, and reconcile the three by hand on the small graph before trusting the function.
- Generate ring lattices, Erdős-Rényi random graphs and Watts-Strogatz networks, and compare their clustering and path length side by side.
What to watch for
- Average local clustering and global clustering will disagree. Work out which nodes cause the gap before reading on — the six-node example on the concepts page gives 0.70 and 0.43 for the same network.
- The ring lattice and the random graph sit at opposite extremes. Note how far each is from the network you would actually want to live in.