The source project of this merge request has been removed.
mcmc_multilevel: make B_next account for 0-valued vweights
This should be thoroughly reviewed, but it fixes the example below which I stumbled upon and which motivated this patch suggestion.
In the example, where a single vertex is weighted zero, minimize_blockmodel_dl()
enters an infinite loop.
This happens because:
- In
mcmc_multilevel()
: the break condition isstate.B > B:
- In
shrink()
:B_next
is compared tonB = bstate.get_nonempty_B()
, permitting the full sizestate.B
not to shrink accordingly when satisfying the break condition ofnB > B_next
Also relevant is that the global target B
itself is derived from state.get_nonempty_B()
in bisection_minimize()
, where also b_cache
is fed values from state.get_nonempty_B()
.
This suggests comparing apples to apples in the break condition and when calculating B_next
, thus the patch.
import graph_tool.all as gt
g = gt.collection.data["karate"]
# g = gt.collection.data["celegansneural"] # same problem arises
vweight = g.new_vertex_property('int',
vals=[(0 if int(v)<1 else 1)
for v in g.vertices()] )
so = gt.minimize_blockmodel_dl( g, verbose=True,
state_args={'vweight':vweight} )