Quantify how a network’s function degrades under targeted attacks.
This library simulates dismantling trajectories driven by classical centralities (degree, betweenness, PageRank, …) and an entropy-based entanglement centrality, while tracking spectral/diffusion observables derived from the graph Laplacian.
- Spectral entropy of a graph via Laplacian spectrum.
- Entanglement centrality: node impact measured as entropy loss after removing its incident edges.
- Functional dismantling: compare multiple strategies step-by-step and record graph/Laplacian trajectories.
- Tidy outputs for analysis + optional plotting example.
pip install -e .Requirements: Python ≥ 3.10, packages: networkx, numpy, scipy (examples also use matplotlib, pandas).
importnetworkxasnxfromfunctional_robustnessimportentropy, entanglement, F_Robust# Build a toy graphG=nx.erdos_renyi_graph(60, 0.08, seed=7)
beta=1.0# BaselinesH=entropy(G, beta)
ent=entanglement(G, beta)
print(f"Spectral entropy: {H:.3f}")
print("Top-3 by entanglement:", sorted(ent.items(), key=lambdax: x[1], reverse=True)[:3])
# Dismantling trajectoriescentralities, traj_graphs, traj_laps=F_Robust(G, beta=beta)Run the end‑to‑end demo (saves a CSV + plot):
python examples/demo_functional_robustness.pyOutputs will be in ./outputs/:
trajectory_metrics.csventropy_trajectories.png
entropy(G: nx.Graph, beta: float) ->floatCompute the graph’s spectral (Gibbs–Boltzmann) entropy from Laplacian eigenvalues.
entanglement(G: nx.Graph, beta: float) ->dictReturn {node: Δentropy} after removing all edges incident to node. Higher values ⇒ higher functional importance.
F_Robust(G: nx.Graph, beta: float) ->tuple[list[str], dict, dict]Simulate dismantling using multiple centralities. Returns:
centralities: list of strategy namestraj_graphs:{strategy: [G_0, G_1, ...]}traj_laps:{strategy: [L_0, L_1, ...]}
functional_robustness/
__init__.py
entropy.py # entropy & entanglement
centrality.py # classical + functional centralities
dismantling.py # F_Robust trajectories
examples/
demo_functional_robustness.py
pyproject.toml
README.md
LICENSE
MIT © CoMuNe Lab