Hands-on: Breaking Networks on Purpose

Author

Sadamori Kojaku

Published

August 25, 2026

The theory says hub-heavy networks shrug off random failure and collapse under targeted attack. Here you make that happen and measure it.

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/m03-robustness/coding.py. Run it with marimo edit notebooks/m03-robustness/coding.py.

What you will build

  1. Measure connectivity as the fraction of nodes left in the largest component.
  2. Simulate random failure on the karate-club network and plot its robustness profile.
  3. Simulate an adaptive targeted attack — degrees recomputed after every removal — and lay the two profiles on top of each other.
  4. Build a minimum spanning tree of a weighted network with igraph.
  5. Watch a lattice percolate as the occupation probability rises.
  6. Compute \kappa for a real airport network and check the predicted threshold against the simulated one.

What to watch for

  • The notebook runs random failure once, and one run looks deceptively smooth. Wrap it in a loop, run it fifty times, and plot the spread: for random failure the variance is the story.
  • The targeted attack in the notebook is the adaptive one. Write the fixed-ranking version too — rank by degree once, on the original network — and compare. The gap between the two curves is the value of information to an attacker.
  • Check your measured threshold against f_c = 1 - 1/(\kappa - 1), derived in the appendix. Expect agreement in order of magnitude, not to three decimals: the formula is an asymptotic result for randomly wired networks, and the karate club has 34 nodes and a great deal of structure.
NoteIf the last cells fail in the browser

The airport network is loaded over the network with pd.read_csv from a GitHub URL. The in-browser runtime sandboxes some network access, so if those cells error out, run the notebook locally instead.