Drawing OverlapBlockState()

Hi Prof. Peixoto,

gt version: 2.92
os: ubuntu 22
python: 3.9

the documentation clearly describes how to draw node marginals for BlockState() and NestedBlockState().
But is there any way we can draw OverlapBlockState() in a similar way?

MWE:

import graph_tool.all as gt
import numpy as np

g = gt.collection.data['lesmis']

state = gt.minimize_blockmodel_dl(g, state=gt.OverlapBlockState, state_args=dict(deg_corr=True, B=25))

state.draw()

This gives error:

state.draw()

File ~/miniconda3/envs/gt/lib/python3.9/site-packages/graph_tool/inference/overlap_blockmodel.py:689, in OverlapBlockState.draw(self, **kwargs)
    686     pie_fractions = bc_total.copy("vector<double>")
    687 else:
    688     pie_fractions = self.base_g.new_vp("vector<double>",
--> 689                                        vals=[ones(len(bv[v])) for v
    690                                              in self.base_g.vertices()])
    692 gradient = kwargs.get("edge_gradient",
    693                       get_block_edge_gradient(self.base_g,
    694                                               self.get_edge_blocks(),
    695                                               cmap=kwargs.get("ecmap",
    696                                                               None)))
    697 from graph_tool.draw import graph_draw

File ~/miniconda3/envs/gt/lib/python3.9/site-packages/graph_tool/inference/overlap_blockmodel.py:689, in <listcomp>(.0)
    686     pie_fractions = bc_total.copy("vector<double>")
    687 else:
    688     pie_fractions = self.base_g.new_vp("vector<double>",
--> 689                                        vals=[ones(len(bv[v])) for v
    690                                              in self.base_g.vertices()])
    692 gradient = kwargs.get("edge_gradient",
    693                       get_block_edge_gradient(self.base_g,
    694                                               self.get_edge_blocks(),
    695                                               cmap=kwargs.get("ecmap",
    696                                                               None)))
    697 from graph_tool.draw import graph_draw

NameError: name 'ones' is not defined

Many thanks,
Govinda

Yes, just update to a more recent version where this bug has been fixed.

Thank you,
but it is still throws the error message.

my graph-tool version is 2.96

The code above does not throw the error, but I see it when I set deg_corr=False. I’ve fixed it in git. In the meantime, just use deg_corr=True for drawing.

1 Like