Commit 2fe5bab4 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

blockmodel: change set_blocks() to set_state()

parent c2133547
......@@ -872,7 +872,12 @@ public:
void set_partition(VMap&& b)
{
for (auto v : vertices_range(_g))
move_vertex(v, b[v]);
{
size_t r = b[v];
while (r >= num_vertices(_bg))
add_block();
move_vertex(v, r);
}
}
void set_partition(boost::any& ab)
......
......@@ -23,9 +23,9 @@ import sys
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, \
perfect_prop_hash
from .. import _degree, _prop, Graph, GraphView, libcore, _get_rng, \
PropertyMap, VertexPropertyMap, conv_pickle_state, Vector_size_t, \
Vector_double, group_vector_property, perfect_prop_hash
from .. generation import condensation_graph, random_rewire, generate_sbm, \
solve_sbm_fugacities, generate_maxent_sbm
from .. stats import label_self_loops, remove_parallel_edges, remove_self_loops
......@@ -874,8 +874,10 @@ class BlockState(object):
r"""Returns the property map which contains the block labels for each vertex."""
return self.b
def set_blocks(self, b):
def set_state(self, b):
r"""Sets the internal partition of the state."""
if not isinstance(b, VertexPropertyMap):
b = self.g.new_vp("int32_t", vals=b)
if b.value_type() != "int32_t":
b = b.copy("int32_t")
self._state.set_partition(_prop("v", self.g, b))
......
......@@ -215,6 +215,11 @@ class NestedBlockState(object):
"""
return [s.b.fa for s in self.levels]
def set_state(self, bs):
r"""Sets the internal nested partition of the state."""
for i in range(len(bs)):
self.levels[i].set_state(bs[i])
def get_levels(self):
"""Get hierarchy levels as a list of :class:`~graph_tool.inference.blockmodel.BlockState`
instances."""
......
Supports Markdown
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