Hello,
I am currently working on fitting a multilayer hSBM to my data. This works well so far, however, when I try to filter a specific layer in the resulting NestedBlockState (for the sake of drawing the resulting state for only the specific layer) I get the following numpy error:
ValueError: zero-size array to reduction operation maximum which has no identity
I am using the following graph-tool version:
2.57 (commit a7d8d3b2, )
On wsl ubuntu with the following version:
Distributor ID: Ubuntu
Description: Ubuntu 22.04.2 LTS
Release: 22.04
Codename: jammy
Since the following minimal working example also produces the error I am suspecting some error from the graph-tool side, however there is still a non-negligible probability that I am doing something wrong in how I filter the graph layers:
import graph_tool.all as gt
mwe_g = gt.collection.ns["new_guinea_tribes"]
mwe_state = gt.minimize_nested_blockmodel_dl(mwe_g,
state_args=dict(base_type=gt.LayeredBlockState,
state_args=dict(ec=mwe_g.ep.weight, layers=True)))
eb = mwe_state.g.ep.weight.fa == 1
u = gt.GraphView(g=mwe_state.g, efilt=eb)
lstate = mwe_state.copy(g=u)
Full error output:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[9], line 14
10 eb = mwe_state.g.ep.weight.fa == 1
12 u = gt.GraphView(g=mwe_state.g, efilt=eb)
---> 14 lstate = mwe_state.copy(g=u)
File ~/anaconda3/envs/gt/lib/python3.11/site-packages/graph_tool/inference/nested_blockmodel.py:194, in NestedBlockState.copy(self, **kwargs)
191 r"""Copies the block state. The parameters override the state properties,
192 and have the same meaning as in the constructor."""
193 state = dict(self.__getstate__(), **kwargs)
--> 194 return NestedBlockState(**state)
File ~/anaconda3/envs/gt/lib/python3.11/site-packages/graph_tool/inference/nested_blockmodel.py:96, in NestedBlockState.__init__(self, g, bs, base_type, state_args, hstate_args, hentropy_args, **kwargs)
81 self.hstate_args["copy_bg"] = False
82 self.hentropy_args = dict(hentropy_args,
83 adjacency=True,
84 dense=True,
(...)
93 recs_dl=False,
94 beta_dl=1.)
---> 96 self.levels = [base_type(g, b=bs[0] if bs is not None else None,
97 **self.state_args)]
99 if bs is None:
100 if base_type is OverlapBlockState:
File ~/anaconda3/envs/gt/lib/python3.11/site-packages/graph_tool/inference/layered_blockmodel.py:268, in LayeredBlockState.__init__(self, g, ec, eweight, vweight, recs, rec_types, rec_params, b, B, clabel, pclabel, layers, deg_corr, overlap, **kwargs)
265 self._coupled_state = None
267 for l, u in enumerate(self.gs):
--> 268 state = self.__gen_state(l, u, ldegs)
269 self.layer_states.append(state)
271 if ec is None:
File ~/anaconda3/envs/gt/lib/python3.11/site-packages/graph_tool/inference/layered_blockmodel.py:331, in LayeredBlockState.__gen_state(self, l, u, ldegs)
329 B = u.num_vertices() + 1
330 if not self.overlap:
--> 331 state = BlockState(u, b=u.vp["b"],
332 B=B,
333 recs=u.gp["rec"],
334 drec=u.gp["drec"],
335 rec_types=self.rec_types,
336 rec_params=self.rec_params,
337 epsilon=self.epsilon,
338 Lrecdx=self.Lrecdx[l+1],
339 eweight=u.ep["weight"],
340 vweight=u.vp["weight"],
341 deg_corr=self.deg_corr,
342 dense_bg=self.dense_bg,
343 use_rmap=True)
344 else:
345 base_u, node_index = self.__get_base_u(u)
File ~/anaconda3/envs/gt/lib/python3.11/site-packages/graph_tool/inference/blockmodel.py:339, in BlockState.__init__(self, g, b, B, eweight, vweight, recs, rec_types, rec_params, clabel, pclabel, bfield, Bfield, deg_corr, dense_bg, **kwargs)
336 if not self._check_clabel(b=self.pclabel, clabel=self.clabel):
337 raise ValueError("provided pclabel and clabel are inconsistent")
--> 339 self.bclabel = self.get_bclabel()
340 self.hclabel = self.bg.new_vp("int")
342 self.dense_bg = dense_bg
File ~/anaconda3/envs/gt/lib/python3.11/site-packages/graph_tool/inference/blockmodel.py:713, in BlockState.get_bclabel(self, clabel)
711 bclabel = self.bg.new_vertex_property("int")
712 idx = self.vweight.a > 0
--> 713 reverse_map(self.b.a[idx], bclabel)
714 if clabel is None:
715 clabel = self.clabel
File ~/anaconda3/envs/gt/lib/python3.11/site-packages/graph_tool/inference/util.py:117, in reverse_map(prop, value_map)
115 else:
116 a = value_map
--> 117 if prop.max() >= len(a):
118 raise ValueError("value map is not large enough!" +
119 " max val: %s, map size: %s" % (prop.max(), len(a)))
120 if prop.dtype != a.dtype:
File ~/anaconda3/envs/gt/lib/python3.11/site-packages/numpy/core/_methods.py:41, in _amax(a, axis, out, keepdims, initial, where)
39 def _amax(a, axis=None, out=None, keepdims=False,
40 initial=_NoValue, where=True):
---> 41 return umr_maximum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation maximum which has no identity
Best wishes,
Julian