I'm super lazy, but did it
I have found an inconsistent behaviour with graph_tool version 2.43 on two different systems. In both cases I have installed via conda-forge. On the linux system I have
import graph_tool.all as gt
gt.__version__
'2.43 (commit 5778eb10, )'
for python 3.8, numpy 1.21.2
On os x I have
import graph_tool.all as gt
gt.__version__
'2.43 (commit , )'
for python 3.8 and numpy 1.21.2 again.
I have tried a simple code (following #713 ) which is returning two different errors on both systems. On OSX I have
g = gt.collection.ns["new_guinea_tribes"]
state = gt.minimize_nested_blockmodel_dl(g,
state_args=dict(base_type=gt.LayeredBlockState,
state_args=dict(ec=g.ep.weight, layers=True)))
missing = [(0, 6, 1), (0, 6, -1)]
state.get_edges_prob(missing)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-fadd85695711> in <module>
5
6 missing = [(0, 6, 1), (0, 6, -1)]
----> 7 state.get_edges_prob(missing)
~/anaconda3/envs/experimental/lib/python3.8/site-packages/graph_tool/inference/nested_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)
441 lstate._state.clear_egroups()
442
--> 443 L += lstate.get_edges_prob(missing, spurious, entropy_args=eargs)
444 if isinstance(self.levels[0], LayeredBlockState):
445 missing = [(lstate.b[u], lstate.b[v], l_) for u, v, l_ in missing]
~/anaconda3/envs/experimental/lib/python3.8/site-packages/graph_tool/inference/layered_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)
788
789 nes.append((u, v, (l, False)))
--> 790 nes.append((self._get_lvertex(u, l),
791 self._get_lvertex(v, l), (l, True)))
792
~/anaconda3/envs/experimental/lib/python3.8/site-packages/graph_tool/inference/layered_blockmodel.py in _get_lvertex(self, v, l)
748 def _get_lvertex(self, v, l):
749 i = numpy.searchsorted(self.vc[v].a, l)
--> 750 if i >= len(self.vc[v]) or l != self.vc[v][i]:
751 raise ValueError("vertex %d not present in layer %d" % (v, l))
752 u = self.vmap[v][i]
TypeError: Invalid index type
whereas on linux I have
g = gt.collection.ns["new_guinea_tribes"]
state = gt.minimize_nested_blockmodel_dl(g,
state_args=dict(base_type=gt.LayeredBlockState,
state_args=dict(ec=g.ep.weight, layers=True)))
missing = [(0, 6, 1), (0, 6, -1)]
state.get_edges_prob(missing)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/beegfs/scratch/tmp/ipykernel_16854/740866967.py in <module>
5
6 missing = [(0, 6, 1), (0, 6, -1)]
----> 7 state.get_edges_prob(missing)
~/miniforge3/envs/singlecell/lib/python3.8/site-packages/graph_tool/inference/nested_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)
441 lstate._state.clear_egroups()
442
--> 443 L += lstate.get_edges_prob(missing, spurious, entropy_args=eargs)
444 if isinstance(self.levels[0], LayeredBlockState):
445 missing = [(lstate.b[u], lstate.b[v], l_) for u, v, l_ in missing]
~/miniforge3/envs/singlecell/lib/python3.8/site-packages/graph_tool/inference/layered_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)
789 nes.append((u, v, (l, False)))
790 nes.append((self._get_lvertex(u, l),
--> 791 self._get_lvertex(v, l), (l, True)))
792
793 edge_list = nes
~/miniforge3/envs/singlecell/lib/python3.8/site-packages/graph_tool/inference/layered_blockmodel.py in _get_lvertex(self, v, l)
749 i = numpy.searchsorted(self.vc[v].a, l)
750 if i >= len(self.vc[v]) or l != self.vc[v][i]:
--> 751 raise ValueError("vertex %d not present in layer %d" % (v, l))
752 u = self.vmap[v][i]
753 return u
ValueError: vertex 6 not present in layer 1
which is the correct behaviour (at least for the intent of this bug report).
Oh, I see. So the error won't be raised if my layers are all positive integers, I'll take that!
Hello, sorry to bother again on this (closed) issue. As it may be a problem with the package distributed on conda-forge I have opened an issue for the repository here. While preparing the text I had the chance to test the very same code on a linux machine with 2.43 installed (also from conda-forge). The same code raises a completely different error, which is more "natural":
g = gt.collection.ns["new_guinea_tribes"]
state = gt.minimize_nested_blockmodel_dl(g,
state_args=dict(base_type=gt.LayeredBlockState,
state_args=dict(ec=g.ep.weight, layers=True)))
missing = [(0, 6, 1), (0, 6, -1)]
state.get_edges_prob(missing)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/beegfs/scratch/tmp/ipykernel_16854/740866967.py in <module>
5
6 missing = [(0, 6, 1), (0, 6, -1)]
----> 7 state.get_edges_prob(missing)
~/miniforge3/envs/singlecell/lib/python3.8/site-packages/graph_tool/inference/nested_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)
441 lstate._state.clear_egroups()
442
--> 443 L += lstate.get_edges_prob(missing, spurious, entropy_args=eargs)
444 if isinstance(self.levels[0], LayeredBlockState):
445 missing = [(lstate.b[u], lstate.b[v], l_) for u, v, l_ in missing]
~/miniforge3/envs/singlecell/lib/python3.8/site-packages/graph_tool/inference/layered_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)
789 nes.append((u, v, (l, False)))
790 nes.append((self._get_lvertex(u, l),
--> 791 self._get_lvertex(v, l), (l, True)))
792
793 edge_list = nes
~/miniforge3/envs/singlecell/lib/python3.8/site-packages/graph_tool/inference/layered_blockmodel.py in _get_lvertex(self, v, l)
749 i = numpy.searchsorted(self.vc[v].a, l)
750 if i >= len(self.vc[v]) or l != self.vc[v][i]:
--> 751 raise ValueError("vertex %d not present in layer %d" % (v, l))
752 u = self.vmap[v][i]
753 return u
ValueError: vertex 6 not present in layer 1
Is this behaviour expected?
Since it has been installed from conda I cannot really check if those are in the compiled object (I'm playing with objdump right now, but…). I can see changes highlighted in commit are included in the headers installed together with the package. Maybe I should also mention I'm on osx?
[EDIT] Note that despite what I've raised in the discussion group about the missing function, this issue is about another error :-(
Uhm, that happened with a fresh conda-forge update to 2.43 but I’ll check ASAP
I am playing with edge prediction in particular with LayeredBlockState class. However, a simple example raises a TypeError. Here I'm using the same dataset indicated in the documentation
import graph_tool.all as gt
g = gt.collection.ns["new_guinea_tribes"]
state = gt.minimize_nested_blockmodel_dl(g,
state_args=dict(base_type=gt.LayeredBlockState,
state_args=dict(ec=g.ep.weight, layers=True)))
missing = [(0, 6, 1), (0, 6, -1)]
state.get_edges_prob(missing)
which raises this error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-7a8e892c69fa> in <module>
6
7 missing = [(0, 6, 1), (0, 6, -1)]
----> 8 state.get_edges_prob(missing)
~/anaconda3/envs/experimental/lib/python3.8/site-packages/graph_tool/inference/nested_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)
441 lstate._state.clear_egroups()
442
--> 443 L += lstate.get_edges_prob(missing, spurious, entropy_args=eargs)
444 if isinstance(self.levels[0], LayeredBlockState):
445 missing = [(lstate.b[u], lstate.b[v], l_) for u, v, l_ in missing]
~/anaconda3/envs/experimental/lib/python3.8/site-packages/graph_tool/inference/layered_blockmodel.py in get_edges_prob(self, missing, spurious, entropy_args)
788
789 nes.append((u, v, (l, False)))
--> 790 nes.append((self._get_lvertex(u, l),
791 self._get_lvertex(v, l), (l, True)))
792
~/anaconda3/envs/experimental/lib/python3.8/site-packages/graph_tool/inference/layered_blockmodel.py in _get_lvertex(self, v, l)
748 def _get_lvertex(self, v, l):
749 i = numpy.searchsorted(self.vc[v].a, l)
--> 750 if i >= len(self.vc[v]) or l != self.vc[v][i]:
751 raise ValueError("vertex %d not present in layer %d" % (v, l))
752 u = self.vmap[v][i]
TypeError: Invalid index type
I'm using graph_tool version 2.43
The PartitionModeState functions allow to get the 2D matrix of marginals given the models used to create the object. When it is built using NestedBlockState instances, the marginals are only returned for the deepest BlockState in the hierarchy. Would it be possible to implement a strategy to get the marginals of the blocks at higher levels (i.e. the marginals for blocks at level x to belong to blocks at level x + 1)?