Small World Model - Using Python Networkx
Last Updated :
05 Aug, 2022
In this article, we will learn how to create a Small World Network using Networx module in Python. Before proceeding that let's first understand some basics about Small World Phenomenon. What is Small World Phenomenon ? Small World Phenomenon is the study and notion that we are all connected via a small number of edges. There have been three notable experiments to prove the Small World Phenomenon :
- Milgram Small World Phenomenon Experiment : 296 randomly chosen persons were asked to forward a letter to a 'target' person (a Stockbroker in Boston). The letter was to be sent directly to him if the person was known personally, otherwise, the letter was to be sent to someone who has a higher probability of knowing him personally. 64 letters reached the target person with a median length of 6 ie. on average a random person was connected to the target person via 6 people in between.
- Microsoft Instant Messenger Experiment : There are 240 million active users of Microsoft Instant Messenger. They are connected if two users were engaged in a 2-way communication over the period of a month. For any two random people, the median distance was 7 i.e. 2 random people were connected via 7 intermediate connections.
- Facebook based Experiment : The experiment conducted by Facebook calculated the average path length to be 5.28 in 2008 whereas it reduced to be 4.74 in 2011.
In 1998, Duncan Watts and Steven Strogatz furthered the study of Small World Model by publishing a research paper titled "Collective Dynamics of Small World Networks". They studied three different kinds of networks:
- A network of film actors, where the individual nodes were film actors and they were connected only if the actors appeared in the same movie.
- A power grid network where nodes are generators, transformers and substations and two nodes are linked if they have a transmission line between them.
- A network where nodes are neurons and two nodes are linked if they have a synapse or a gap junction.
They concluded that Small World Networks generally has low average path length but high clustering coefficient.
How can Small World Networks be formed ?
Watts and Strogatz came up with a model about how to construct Small World Networks. Let there be n nodes, where each node is connected to m nearest neighbors, this is known as Regular Lattice and looks like as shown in the figure below, where n = 10 and m = 4.
Consider each edge (u, v) and with probability p, select a node w at random and rewire the edge (u, v) so that it becomes (u, w). For p = 0, the Regular Lattice retains its structure and has a high average distance and high clustering. For p = 1, a Random Network is formed with small average distance and low clustering. It looks like the figure shown below, where n = 10, m = 4 and p = 1.
For an intermediate value of p, we would get an ideal Small World Network with small average distance and high clustering. For Python, we can easily construct a Small World Network using Networkx.
Python3
import networkx as nx
import matplotlib.pyplot as plt
G = nx.watts_strogatz_graph(n = 10, m = 4, p = 0.5)
pos = nx.circular_layout()
plt.figure(figsize = (12, 12))
nx.draw_networkx(G, pos)
Output:
The resultant Small World Network maybe a disconnected Graph. If we wish to get a connected Graph, we can modify line number 4 of the above code as follows:
Python3
G = nx.connected_watts_strogatz_graph(n=10, m=4, p=0.5, t=20)
It runs the original function t times (in this case t = 20) till a connected network is achieved. It will give the following network:
Python3
G = nx.newman_watts_strogatz_graph(n=10, m=4, p=0.5)
The above code will run a similar model but add new edges with probability p instead of rewiring already existing edges. It will produce the following network: 
Similar Reads
NetworkX : Python software package for study of complex networks NetworkX is a Python language software package for the creation, manipulation, and study of the structure, dynamics, and function of complex networks. It is used to study large complex networks represented in form of graphs with nodes and edges. Using networkx we can load and store complex networks.
3 min read
Python | Visualize graphs generated in NetworkX using Matplotlib Prerequisites: Generating Graph using Network X, Matplotlib IntroIn this article, we will be discussing how to plot a graph generated by NetworkX in Python using Matplotlib. NetworkX is not a graph visualizing package but basic drawing with Matplotlib is included in the software package. Step 1 : Im
3 min read
Directed Graphs, Multigraphs and Visualization in Networkx Prerequisite: Basic visualization technique for a Graph In the previous article, we have learned about the basics of Networkx module and how to create an undirected graph. Note that Networkx module easily outputs the various Graph parameters easily, as shown below with an example. Python3 1== import
10 min read
Complete Graph using Networkx in Python A complete graph also called a Full Graph it is a graph that has n vertices where the degree of each vertex is n-1. In other words, each vertex is connected with every other vertex. Example: Complete Graph with 6 edges: C_G6 Properties of Complete Graph: The degree of each vertex is n-1.The total nu
3 min read
Introduction to Social Networks using NetworkX in Python Prerequisite - Python Basics Ever wondered how the most popular social networking site Facebook works? How we are connected with friends using just Facebook? So, Facebook and other social networking sites work on a methodology called social networks. Social networking is used in mostly all social m
4 min read
Wheel Graph using Networkx Python A wheel graph is a type of graph in which if we connect each node in an n-1 node cycle graph to nth node kept at the centre we get a wheel graph. The definition would be more clear after seeing the example below. Wheel Graph with n nodes is represented by Wn . Example: W5: W5 Â W6: W6 Properties of W
2 min read
Small World Model - Using Python Networkx In this article, we will learn how to create a Small World Network using Networx module in Python. Before proceeding that let's first understand some basics about Small World Phenomenon. What is Small World Phenomenon ? Small World Phenomenon is the study and notion that we are all connected via a s
4 min read
Ego graph Using Networkx in Python Prerequisite - Graphs, Networkx Basics Ego network is a special type of network consisting of one central node and all other nodes directly connected to it. The central node is known as ego, while the other surrounding nodes directly connected to it are known as alters. Ego networks are mostly used
4 min read
Star Graph using Networkx Python In this article, we are going to see Star Graph using Networkx Python. A Star graph is a special type of graph in which n-1 vertices have degree 1 and a single vertex have degree n â 1. This looks like that n â 1 vertex is connected to a single central vertex. A star graph with total n â vertex is t
2 min read
Network Centrality Measures in a Graph using Networkx | Python Centrality Measures allows us to pinpoint the most important nodes of a Graph. This essentially helps us to identify : Influential nodes in a Social Network. Nodes that disseminate information to many nodes Hubs in a transportation network Important pages in the Web Nodes that prevent the Network fr
6 min read