# Generating stochastic block model with different intra-group and inter-group probabilities

Dear all,

I am trying to generate a stochastic block model in the graph_tool.
Specifically, I am trying to construct a network with exactly 2 blocks such
that the probabilities inside the groups are higher than that of the
between the groups (assortative structure) but the probabilities inside the
groups are not identical for two groups (say 0.9 for the first group and
0.6 for the second group).

The extreme case of this would be to make the probability between the
groups equal to zero which should give me two isolated modules. My code
given below however fails to generate these two models. Can somebody kindly
explain me my mistake?

import numpy as np
import graph_tool.all as gt

N = 1000
ave_deg = 10
block = np.random.randint(1, 3, N)

def f():
ave_deg = 5
return np.random.poisson(ave_deg)

def corr(a, b):
if a == 1 and b == 1:
return 0.6
elif a == 2 and b == 2 :
return 0.9
else:
return 0.

G, bm = gt.random_graph(N, deg_sampler = f, directed = False, model =
"blockmodel-traditional", block_membership = block, vertex_corr = corr)
largest_comp = gt.Graph(gt.GraphView(G, vfilt =
gt.label_largest_component(G)), prune = True)
gt.graph_draw(G)

Thank you
Snehal

attachment.html (1.63 KB)

What problems do you observe, exactly?

Basically, instead of seeing two disconnected modules, I see that those
modules are connected by few links. (There are some isolated nodes which is
not a problem I guess).

attachment.html (1.36 KB)

The algorithm implemented is a MCMC, which needs to equilibrate. Try passing
something like niter=1000 to the random_graph() function.

That worked. Thank you very much!

Snehal

attachment.html (1.46 KB)