# Random Dot Product Graph (RDPG) Model¶

:

import graspy

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)


RDPG is a latent position generative model, in which the probability of an edge existing between pairs of vertices is determined by the dot product of the associated latent position vectors. In other words, given $$X \in \mathbb{R}^{n\times d}$$, where $$n$$ is the number of vertices and $$d$$ is the dimensionality of each vector, the probability matrix $$P$$ is given by:

\begin{align*} P = XX^T \end{align*}

Both ER and SBM models can be formulated as a RDPG. Below, we sample $$ER_{NP}(100, 0.5)$$ using RDPG formulation. In this case, we set $$X \in \mathbb{R}^{100\times 2}$$ where all the values in $$X$$ is 0.5. This results in $$P$$ matrix where all the probabilities are also 0.5.

:

from graspy.simulations import rdpg

# Create a latent position matrix
X = np.full((100, 2), 0.5)
print(X @ X.T)

[[0.5 0.5 0.5 ... 0.5 0.5 0.5]
[0.5 0.5 0.5 ... 0.5 0.5 0.5]
[0.5 0.5 0.5 ... 0.5 0.5 0.5]
...
[0.5 0.5 0.5 ... 0.5 0.5 0.5]
[0.5 0.5 0.5 ... 0.5 0.5 0.5]
[0.5 0.5 0.5 ... 0.5 0.5 0.5]]

:

A = rdpg(X)


:

from graspy.plot import heatmap

heatmap(A, title='ER_NP(100, 0.5) Using RDPG')

:

<matplotlib.axes._subplots.AxesSubplot at 0x14dab28400f0> ## Stochastic block model as RDPG¶

We can formulate the following 2-block SBM parameters as RDPG, where the latent positions live in $$\mathbb{R}^3$$.

\begin{align*} n &= [50, 50]\\ p &= \begin{bmatrix}0.33 & 0.09\\ 0.09 & 0.03 \end{bmatrix} \end{align*}

as

\begin{align*} X &= \begin{bmatrix}0.5 & 0.2 & 0.2\\ & \vdots & \\ 0.1 & 0.1 & 0.1\\ & \vdots & \end{bmatrix}\\ P &= XX^T \end{align*}

:

X = np.array([[0.5, 0.2, 0.2]] * 50 + [[0.1, 0.1, 0.1]] * 50)
A_rdpg = rdpg(X, loops=False)
heatmap(A_rdpg, title='2-block SBM as RDPG')

:

<matplotlib.axes._subplots.AxesSubplot at 0x14dab253bb00> ### Results from SBM simulation using same formulation shows similar structure¶

:

from graspy.simulations import sbm

n = [50, 50]
p = [[0.33, 0.09], [0.09, 0.03]]

A_sbm = sbm(n, p)
heatmap(A_sbm, title = 'SBM Simulation')

:

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