Commit 9668242a authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

inference.blockmodel: Avoid clabel overflow

This fixes issue #344
parent aa26ba20
......@@ -24,7 +24,8 @@ if sys.version_info < (3,):
range = xrange
from .. import _degree, _prop, Graph, GraphView, libcore, _get_rng, PropertyMap, \
conv_pickle_state, Vector_size_t, Vector_double, group_vector_property
conv_pickle_state, Vector_size_t, Vector_double, group_vector_property, \
perfect_prop_hash
from .. generation import condensation_graph
from .. stats import label_self_loops
from .. spectral import adjacency
......@@ -586,12 +587,18 @@ class BlockState(object):
pmap(bclabel, self.pclabel)
return bclabel
def _check_clabel(self):
b = self.b.fa + self.clabel.fa * self.B
b2 = self.b.fa.copy()
def _check_clabel(self, clabel=None, b=None):
if b is None:
b = self.b
if clabel is None:
clabel = self.clabel
joint = group_vector_property([b, clabel])
joint = perfect_prop_hash([joint])[0]
joint = b.fa.copy()
b = b.fa.copy()
continuous_map(joint)
continuous_map(b)
continuous_map(b2)
return (b == b2).all()
return (b == joint).all()
def _couple_state(self, state, entropy_args):
if state is None:
......
......@@ -438,10 +438,12 @@ class NestedBlockState(object):
clabel = self.get_clabel(l)
state = self.levels[l]
if b_max is None:
b_max = state.g.vertex_index.copy("int").a
b_max = state.g.vertex_index.copy("int").fa
else:
b_max = b_max + (b_max.max() + 1) * clabel.fa
continuous_map(b_max)
b_max = state.g.new_vp("int", b_max)
b_max = group_vector_property([b_max, clabel])
b_max = perfect_prop_hash([b_max])[0].fa
continuous_map(b_max)
max_state = state.copy(b=b_max, clabel=clabel)
if B_max is not None and max_state.B > B_max:
max_state = mcmc_multilevel(max_state, B_max,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment