In [1]:
import graph_tool.all as gt
import math
import numpy as np
In [2]:
pv = None
In [8]:
g = gt.collection.data["karate"]
state = gt.BlockState(g, B=20)
print('num v:', g.num_vertices())
state = state.copy(B=g.num_vertices())
dS, nmoves = state.mcmc_sweep(niter=1000)
print("Change in description length:", dS)
print("Number of accepted vertex moves:", nmoves)
gt.mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10))
def collect_marginals(s):
global pv
pv = s.collect_vertex_marginals(pv)
gt.mcmc_equilibrate(state, force_niter=10000, mcmc_args=dict(niter=10),
callback=collect_marginals)
print(g.vp.pos)
# Now the node marginals are stored in property map pv. We can
# visualize them as pie charts on the nodes:
state.draw(pos=g.vp.pos, vertex_text=g.vertex_index, vertex_shape="pie", vertex_pie_fractions=pv,
edge_gradient=None, output="karate-sbm-marginals.pdf")
Out[8]:
In [ ]: