Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Draw graphon Stochastic Block Models
import matplotlibt.pyplot as plt
import numpy as np
plt.figure(figsize=(5,4))
X, Y = np.meshgrid(np.linspace(0,1), np.linspace(0,1))
plt.pcolormesh(X,Y,graphon_val(X,Y,p,n))
plt.colorbar()
import numpy as np
# Define vectorized function which returns the value of the graphon
# at point (x,y) given the stochastic block model of probability matrix
# p and size vector n
def graphon_val(x, y, p, n):
ns = np.sum(n)
ncs = np.cumsum(n)
nx = x * ns
ny = y * ns
ix = 0
iy = 0
while nx > ncs[ix]:
ix += 1
while ny > ncs[iy]:
iy += 1
return p[ix, iy]
graphon_val = np.vectorize(graphon_val, excluded=(2,3))
@jg-you

This comment has been minimized.

Copy link
Owner Author

commented Aug 25, 2016

Example with

p = np.array([[0.12, 0.10, 0.10, 0.05, 0.05, 0.00],
              [0.10, 0.12, 0.10, 0.00, 0.05, 0.05],
              [0.10, 0.10, 0.12, 0.05, 0.00, 0.05],
              [0.05, 0.00, 0.05, 0.60, 0.00, 0.00],
              [0.05, 0.05, 0.00, 0.00, 0.60, 0.00],
              [0.00, 0.05, 0.05, 0.00, 0.00, 0.60]])
n = [50, 50, 50, 100, 200, 200]

download

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.