Instantly share code, notes, and snippets.

# jg-you/draw_graphon.py Created Aug 25, 2016

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))
Owner Author

### jg-you 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] `````` to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.