Correlated Graph Pairs

[1]:
import graspy
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

The correlated Graph Pairs Model means that we generate a graph pair with some correlation. We define the probability of observing the same edge in both graphs by adjusting the correlation values and sample the graph pairs.

ER correlation graph pair

There are different ways to define the probability matrix of the first graph. ER model is a simple one. We assume that each edge for all pairs of vertices is sampled independently from all the edges.

ER_CORR(n, p, r) - this model specifies the number of vertices, \(n\), each pair of vertices has \(p\) probability of an edge existing between the two and the correlation values \(r\) between the two.

Below, we sample a graph pair with ER model (undirected and no self-loops) \(G_1, G_2 \sim ER\_{CORR}\,(50, 0.5, 0.3)\).

[2]:
from graspy.simulations import er_corr
[3]:
n = 50
r = 0.3
p = 0.5

np.random.seed(2)
G1, G2 = er_corr(n, p, r, directed = False, loops = False)

Visualize the graphs using heatmap

[4]:
from graspy.plot import heatmap
heatmap(G1, title = 'Correlated ER Simulation Graph 1')
heatmap(G2, title = 'Correlated ER Simulation Graph 2')
[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a26a11f28>
../../_images/tutorials_simulations_corr_8_1.png
../../_images/tutorials_simulations_corr_8_2.png

SBM correlated graph pair

Besides, SBM tends to produce graphs containing communities, subsets characterized by being connected with one another with particular edge densities. We can define the partitioned matrix with different probability of having edges and the correlation values between the two.

Below, we sample a two-block SBM graph pair (undirected and no self-loops) G1 and G2 with the following parameters:

\begin{align*} n &= [20, 30]\\ p &= \begin{bmatrix} 0.5 & 0.2\\ 0.2 & 0.5 \end{bmatrix}\\ r &= 0.3 \end{align*}

[5]:
from graspy.simulations import sbm_corr
[6]:
np.random.seed(3)
n = [20, 30]
p = [[0.5, 0.2], [0.2, 0.5]]
r = 0.3

G1, G2 = sbm_corr(n, p, r, directed=False, loops=False)

Visualize the graphs using heatmap

[7]:
heatmap(G1, title = 'Correlated SBM Simulation Graph 1')
heatmap(G2, title = 'Correlated SBM Simulation Graph 2')
[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a270a50b8>
../../_images/tutorials_simulations_corr_14_1.png
../../_images/tutorials_simulations_corr_14_2.png
[ ]: