Hi,

 

There seems to be problem with get_edges_prob for the layered SBM. Here is a minimal example:

 

import graph_tool.all as gt

import numpy as np

gr=gt.generate_sbm(b=np.array([0]*500+[1]*500),probs=np.array([[10000,200],[200,10000]]))

etype=gr.new_edge_property('int')

gr.ep.etype=etype

t=0

for e in gr.edges():

    gr.ep.etype[e]=t%4

    t+=1

state = gt.minimize_nested_blockmodel_dl(gr, deg_corr=True,layers=True,state_args=dict(ec=gr.ep.etype,layers=True))

print(state.get_edges_prob(missing=[[2,32,0]],spurious=[]))

print(state.get_edges_prob(missing=[[2,32,0],[3,4,2]],spurious=[]))

print(state.get_edges_prob(missing=[[2,32,0],[3,4,2],[36,7,0]],spurious=[]))

pr=state.get_edges_prob(missing=[[2,32,0],[3,4,2]],spurious=gr.get_edges([gr.ep.etype])[:3])

 

Output:

0.0

-7.883180576649465

-7.883180576649465

---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-11-1f73a43d95dd> in <module>

     12 print(state.get_edges_prob(missing=[[2,32,0],[3,4,2]],spurious=[]))

     13 print(state.get_edges_prob(missing=[[2,32,0],[3,4,2],[36,7,0]],spurious=[]))

---> 14 pr=state.get_edges_prob(missing=[[2,32,0],[3,4,2]],spurious=gr.get_edges([gr.ep.etype])[:3])

 

/usr/lib/python3/dist-packages/graph_tool/inference/nested_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)

    499                     lstate._state.clear_egroups()

    500

--> 501             L += lstate.get_edges_prob(missing, spurious, entropy_args=eargs)

    502             if isinstance(self.levels[0], LayeredBlockState):

    503                 missing = [(lstate.b[u], lstate.b[v], l_) for u, v, l_ in missing]

 

/usr/lib/python3/dist-packages/graph_tool/inference/layered_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)

    896                 if e is None:

    897                     raise ValueError("edge not found: (%d, %d, %d)" % \

--> 898                                      (int(u), int(v), l[0]))

    899

    900                 if state.is_weighted:

 

ValueError: edge not found: (3, 4, 2)

 

The error occurs only when spurious edges are included but even without spurious edges the outputs above seem to be inaccurate.  I tried to resolve the issue myself but couldn’t make it work.

 

Best wishes,

Anatol