# Erdos-Renyi (ER) Model¶

[1]:

import graspy

import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

/opt/buildhome/python3.6/lib/python3.6/site-packages/sklearn/utils/deprecation.py:144: FutureWarning: The sklearn.mixture.gaussian_mixture module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.mixture. Anything that cannot be imported from sklearn.mixture is now part of the private API.
warnings.warn(message, FutureWarning)


Erdos-Renyi (ER) graphs are the simplest generative model. We assume that each edge for all pairs of vertices is sampled independently from all the edges. There are two ways to parameterize the model:

1. ER(n, p) - this model specifies the number of vertices, $$n$$, and each pair of vertices has $$p$$ probability of an edge existing between the two.
2. ER(n, m) - this model specifies the number of vertices, $$n$$, and the total number of edges $$m$$.

Below, we sample two binary graphs (undirected and no self-loops) $$G_1 \sim ER_{NP}(50, 0.3)$$ and $$G_2 \sim ER_{NM}(50, 250)$$.

[2]:

from graspy.simulations import er_nm, er_np

n = 50
m = 250
p = 0.3

np.random.seed(1)
G1 = er_np(n=n, p=p)
G2 = er_nm(n=n, m=m)


## Visualize the graphs using heatmap¶

[3]:

from graspy.plot import heatmap

heatmap(G1, title = 'ER-NP(50, 0.3) Simulation')
heatmap(G2, title = 'ER-NM(50, 250) Simulation')

[3]:

<matplotlib.axes._subplots.AxesSubplot at 0x14d9be943630>


## Weighted ER Graphs¶

Both er_np and er_nm functions provide ways to sample weights for all edges that were sampled via a probability distribution function. In order to sample with weights, one provide a probability distribution function with corresponding keyword arguments for the distribution function.

Below we sample $$G_1 \sim ER_{NP}(50, 0.2)$$ where the weights are distributed on normal with $$\mu = 0,~\sigma^2 = 1$$.

[4]:

wt = np.random.normal
wtargs = dict(loc=0, scale=1)

G1 = er_np(n=50, p=0.2, wt=wt, wtargs=wtargs)


## Visualize the graph using heatmap¶

[5]:

heatmap(G1, title = 'ER-NP(50, 0.2) with N(0,1) Weights Simulation')

[5]:

<matplotlib.axes._subplots.AxesSubplot at 0x14d9be6e8a58>