Skip to content

mcmc_multilevel: make B_next account for 0-valued vweights

Ale Abdo requested to merge (removed):fix-vweight into master

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:

  1. In mcmc_multilevel(): the break condition is state.B > B:
  2. In shrink(): B_next is compared to nB = bstate.get_nonempty_B(), permitting the full size state.B not to shrink accordingly when satisfying the break condition of nB > 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} )

Merge request reports

Loading