/ Small World Networks
A small-world network is a graph characterized by a high clustering coefficient and low distances.
See also a definition in Wikipedia.
# DO NOT REMOVE OR MODIFY
# Import the library that lets you connect Colab with Google Drive
from google.colab import drive
drive.mount('/content/drive')
# ------------------------------------------------------------
# Get the email of the user running the notebook
# and create a folder:
# MyDrive/Taming Data Dragons/
# ------------------------------------------------------------
import os
import subprocess
from google.colab import auth
# Base path in Google Drive
user_path = "/content/drive/MyDrive/Taming Data Dragons/"
# Create the directory if it doesn't exist
os.makedirs(user_path, exist_ok=True)
print(f"User folder ready at: {user_path}")
Mounted at /content/drive User folder ready at: /content/drive/MyDrive/Taming Data Dragons/
Addendum - Small worlds¶
A small-world network is a type of graph in which most nodes are not directly connected, yet any two nodes can be reached by a surprisingly short sequence of steps (i.e., short average path length), and nodes tend to form tightly knit groups (high clustering) — a combination that is common in many real-world networks like social and biological systems.
!pip install networkx matplotlib -q
"""
Small-World Network Demo (Watts–Strogatz Model)
This cell:
1. Creates a small-world network using NetworkX
2. Plots it at double size and 300 DPI
3. Saves the figure to Google Drive in:
MyDrive/Taming Data Dragons/small_world_network.png
"""
import os
import networkx as nx
import matplotlib.pyplot as plt
# ------------------------------------------------------------
# Output path in Google Drive
# ------------------------------------------------------------
os.makedirs(user_path, exist_ok=True)
output_path = os.path.join(user_path, "small_world_network.png")
# ------------------------------------------------------------
# Parameters for the Watts–Strogatz small-world model
# ------------------------------------------------------------
n = 30 # Number of nodes
k = 4 # Each node connected to k nearest neighbors
p = 0.1 # Rewiring probability
# ------------------------------------------------------------
# Create the small-world network
# ------------------------------------------------------------
G = nx.watts_strogatz_graph(n=n, k=k, p=p)
# ------------------------------------------------------------
# Circular layout for visualization
# ------------------------------------------------------------
pos = nx.circular_layout(G)
# ------------------------------------------------------------
# Plot: double size + 300 DPI
# Original was ~8x8, so we go 16x16
# ------------------------------------------------------------
plt.figure(figsize=(8, 8), dpi=100)
nx.draw(
G,
pos,
with_labels=False,
node_size=300,
alpha=0.9
)
plt.title("Small-World Network (Watts–Strogatz Model)")
# ------------------------------------------------------------
# Save to Google Drive
# ------------------------------------------------------------
plt.savefig(output_path, dpi=300, bbox_inches="tight")
plt.show()
print(f"Saved figure to: {output_path}")
Saved figure to: /content/drive/MyDrive/Taming Data Dragons/small_world_network.png
Conclusion: Benefits of Small-World Networks for Modeling¶
Small-world networks are incredibly valuable for modeling real-world systems due to their unique properties:
High Efficiency: Despite their sparse connections (low average path length), information or influence can spread very quickly across the network. This is crucial for modeling phenomena like disease spread, information dissemination in social networks, or signal propagation in neural networks.
Robustness: The presence of tightly clustered nodes (high clustering coefficient) makes these networks resilient to random failures. If a few connections are lost, the overall connectivity and function of the system often remain intact.
Realism: Many natural and artificial systems exhibit small-world characteristics, including social networks, biological neural networks, transportation networks, and even the World Wide Web. Using small-world models allows for a more accurate representation of these complex systems.
Balance of Structure and Randomness: Small-world networks sit at an interesting point between highly regular lattices (which have high clustering but long path lengths) and completely random graphs (which have short path lengths but low clustering). This balance allows them to capture both localized interactions and global connectivity, which is typical in many real-world scenarios.
By leveraging small-world models, researchers and practitioners can gain deeper insights into the dynamics and behavior of complex systems, leading to better predictions, interventions, and design strategies.
Copyright © 2024 icaoberg@psc.edu. Made by the Biomedical Apps Group at the Pittsburgh Supercomputing Center.