Inhomogeneous Erdos Renyi (IER) Random Network Model
Contents
4.4. Inhomogeneous Erdos Renyi (IER) Random Network Model#
Now that you’ve learned about the ER, SBM, and RDPG random networks, it’s time to figure out why we keep using coin flips! To this end, you will learn about the most general model for an independent edge random network, the Inhomogeneous Erdos Renyi (IER) Random Network.
Click to show
import numpy as np
from graspologic.simulations import sample_edges
from graphbook_code import draw_multiplot
def my_unit_circle(r):
d = 2*r + 1
rx, ry = d/2, d/2
x, y = np.indices((d, d))
return (np.abs(np.hypot(rx - x, ry - y)-r) < 0.5).astype(int)
def add_smile():
Ptmp = np.zeros((51, 51))
Ptmp[2:45, 2:45] = my_unit_circle(21)
mask = np.zeros((51, 51), dtype=bool)
mask[np.triu_indices_from(mask)] = True
upper_left = np.rot90(mask)
Ptmp[upper_left] = 0
return Ptmp
def smiley_prob(upper_p, lower_p):
smiley = add_smile()
P = my_unit_circle(25)
P[5:16, 25:36] = my_unit_circle(5)
P[smiley != 0] = smiley[smiley != 0]
mask = np.zeros((51, 51), dtype=bool)
mask[np.triu_indices_from(mask)] = True
P[~mask] = 0
P = (P + P.T - np.diag(np.diag(P))).astype(float)
P[P == 1] = lower_p
P[P == 0] = upper_p
return P
P = smiley_prob(.95, 0.05)
A = sample_edges(P, directed=False, loops=False)
draw_multiplot(A, title="IER Random Network");

4.4.1. The Inhomogeneous Erdos-Renyi (IER) Random Network Model is parametrized by a matrix of independent-edge probabilities#
The IER random network is the most general random network model for a binary graph. The way you can think of the IER random network is that a probability matrix
4.4.1.1. Generating a sample from an random network#
As before, you can develop a procedure to produce for you a network
Simulating a sample from an
Choose a probability matrix
, whose entries are probabilities.For each pair of nodes
an :Obtain a weighted coin
which has a probability of landing on heads, and a probability of landing on tails.Flip the
coin, and if it lands on heads, the corresponding entry in the adjacency matrix is . If the coin lands on tails, the corresponding entry is .
The adjacency matrix you produce,
, is a sample of an random network.
Let’s put this in practice. Since you know about probability matrices from the section on RDPG, you’ll first take a look at the probability matrix for your IER network. This example is very unnecessarily sophisticated, but we have a reason for it:
import numpy as np
def my_unit_circle(r):
d = 2*r + 1
rx, ry = d/2, d/2
x, y = np.indices((d, d))
return (np.abs(np.hypot(rx - x, ry - y)-r) < 0.5).astype(int)
def add_smile():
Ptmp = np.zeros((51, 51))
Ptmp[2:45, 2:45] = my_unit_circle(21)
mask = np.zeros((51, 51), dtype=bool)
mask[np.triu_indices_from(mask)] = True
upper_left = np.rot90(mask)
Ptmp[upper_left] = 0
return Ptmp
def smiley_prob(upper_p, lower_p):
smiley = add_smile()
P = my_unit_circle(25)
P[5:16, 25:36] = my_unit_circle(5)
P[smiley != 0] = smiley[smiley != 0]
mask = np.zeros((51, 51), dtype=bool)
mask[np.triu_indices_from(mask)] = True
P[~mask] = 0
P = (P + P.T - np.diag(np.diag(P))).astype(float)
P[P == 1] = lower_p
P[P == 0] = upper_p
return P
P = smiley_prob(.95, 0.05)
Click to show
from graphbook_code import heatmap
ax = heatmap(P, vmin=0, vmax=1, title="Probability matrix for smiley face example")
ax.set_xlabel("Node")
ax.set_ylabel("Node");

If the edge is between a pair of nodes that defines the smiley face, the probability is
A = sample_edges(P, directed=False, loops=False)
Click to show
draw_multiplot(A, title="Sample from IER Network");

We used this example to show you the key idea behind the IER Network’s probability matrix is simple: the entries can really be anything as long as they are probabilities (between
4.4.2. The IER model unifies independent-edge random network models#
It is important to realize that all of the networks you have learned so far are also IER random networks. The previous single network models you have covered to date simply place restrictions on the way in which you acquire

Fig. 4.2 The IER network unifies independent-edge random networks, as it is the most general independent-edge random network model. What this means is that all models discussed so far, and many not discussed but found in the appendix, can be conceptualized as special cases of the IER network. Stated in other words, a probability matrix is the fundamental unit necessary to describe an independent-edge random network model. For the models covered so far, all GRDPGs are IER networks (by taking
4.4.2.1. How do you obtain a probability matrix for an SBM programmatically?#
One thing that will come up frequently over the course of this book is that we will need to sometimes programmatically generate the probability matrix directly (rather than just using the community assignment vector
Basically, the idea is as follows. If
You begin by constructing a matrix,
, that has rows and columns; one row for each node, and one column for each community.For each node in the network
:For each community in the network
, if , then let . if , then let .
Let
.
The matrix produced,
Let’s work through this example programmatically, because it comes up a few times over the course of the book. Let’s imagine that we have
def make_community_mtx(z):
"""
A function to generate the one-hot-encoded community
assignment matrix from a community assignment vector.
"""
K = len(np.unique(z))
n = len(z)
Z = np.zeros((n, K))
for i, zi in enumerate(z):
Z[i, zi - 1] = 1
return Z
# the community assignment vector
z = [1 for i in range(0, 25)] + [2 for i in range(0, 25)]
Z = make_community_mtx(z)
# block matrix
B = np.array([[0.6, 0.3], [0.3, 0.6]])
# probability matrix
P = Z @ B @ Z.T
4.4.2.2. Limitations of the IER model when you have one network#
This construction is not entirely useful when you have one sample, because for each edge, you only get to see one sample (either the edge exists or doesn’t exist). This means that you won’t really be able to learn about the individual edge probabilities in practice when you only have a single sample of a network in a way which would differentiate them from other single networks. What we mean by this is, if you learn about other single networks, you are still technically learning about an IER random network, because like you saw in the last paragraph, all of these other single network models are just special cases of the IER random network. However, you can’t learn any random network with one sample that could only be described by an IER random network, so it almost feels a little bit useless from what you’ve covered so far. As you will learn shortly, the IER random network is, on the other hand, extremely useful when you have multiple networks. When you have multiple networks, with some limited assumptions, you can learn about networks that you would otherwise not be able to describe with more simple random networks like ER, SBM, or RDPG random netweorks. This will make the IER random network extremely powerful when you have multiple samples of network data.
4.4.3. References#
The survey paper [3] and the appendix section Section 11.3 give an overview of the theoretical properties of IER networks.
- 1
Avanti Athreya, Donniell E. Fishkind, Minh Tang, Carey E. Priebe, Youngser Park, Joshua T. Vogelstein, Keith Levin, Vince Lyzinski, and Yichen Qin. Statistical inference on random dot product graphs: a survey. J. Mach. Learn. Res., 18(1):8393–8484, January 2017. doi:10.5555/3122009.3242083.