In graph theory, the Erdos–Rényi model is either of two closely related models for generating random graphs.
There are two closely related variants of the Erdos–Rényi (ER) random graph model.
In the G(n, M) model, a graph is chosen uniformly at random from the collection of all graphs which have n nodes and M edges. For example, in the G(3, 2) model, each of the three possible graphs on three vertices and two edges are included with probability 1/3.
In the G(n, p) model, a graph is constructed by connecting nodes randomly. Each edge is included in the graph with probability p independent from every other edge. Equivalently, all graphs with n nodes and M edges have equal probability of
A graph generated by the binomial model of Erdos and Rényi (p = 0.01)
The parameter p in this model can be thought of as a weighting function; as p increases from 0 to 1, the model becomes more and more likely to include graphs with more edges and less and less likely to include graphs with fewer edges. In particular, the case p = 0.5 corresponds to the case where all
The article will basically deal with the G (n,p) model where n is the no of nodes to be created and p defines the probability of joining of each node to the other.
Properties of G(n, p)
With the notation above, a graph in G(n, p) has on average
Where n is the total number of vertices in the graph.
Since
- If np < 1, then a graph in G(n, p) will almost surely have no connected components of size larger than O(log(n)).
- If np = 1, then a graph in G(n, p) will almost surely have a largest component whose size is of order
. - If np
c > 1, where c is a constant, then a graph in G(n, p) will almost surely have a unique giant component containing a positive fraction of the vertices. No other component will contain more than O(log(n)) vertices. - If
, then a graph in G(n, p) will almost surely contain isolated vertices, and thus be disconnected. - If
, then a graph in G(n, p) will almost surely be connected.
Thus
Next I’ll describe the code to be used for making the ER graph. For implementation of the code below, you’ll need to install the netwrokx library as well you’ll need to install the matplotlib library. Following you’ll see the exact code of the graph which has been used as a function of the networkx library lately in this article.
Erdos_renyi_graph(n, p, seed=None, directed=False)
Returns a G(n,p) random graph, also known as an Erdos-Rényi graph or a binomial graph.
The G(n,p) model chooses each of the possible edges with probability p. The functions binomial_graph() and erdos_renyi_graph() are aliases of this function.
Parameters: n (int) – The number of nodes.
p (float) – Probability for edge creation.
seed (int, optional) – Seed for random number generator (default=None).
directed (bool, optional (default=False)) – If True, this function returns a directed graph.
#importing the networkx library >>> import networkx as nx
#importing the matplotlib library for plotting the graph >>> import matplotlib.pyplot as plt
>>> G = nx.erdos_renyi_graph( 50 , 0.5 )
>>> nx.draw(G, with_labels = True )
>>> plt.show() |
The above example is for 50 nodes and is thus a bit unclear.
When considering the case for lesser no of nodes (for example 10), you can clearly see the difference.
Using the codes for various probabilities, we can see the difference easily:
>>>H = nx.erdos_renyi_graph( 10 , 0.5 )
>>> nx.draw(H, with_labels = True )
>>> plt.show() |
>>> K = nx.erdos_renyi_graph( 10 , 0.25 )
>>> nx.draw(K, with_labels = True )
>>> plt.show() |
>>>H = nx.erdos_renyi_graph( 10 , 0.5 )
>>> nx.draw(H, with_labels = True )
>>> plt.show() |
This algorithm runs in O(
.