Created
August 25, 2016 21:02
-
-
Save jg-you/104161fd3017cca58776b8f8ac83b50d to your computer and use it in GitHub Desktop.
Draw graphon Stochastic Block Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example with