Commit 70f6e1bd authored by Tiago Peixoto's avatar Tiago Peixoto

blockmodel: change paramter 'max_BE' to a more explicit 'dense_bg'

parent 5a041681
This diff is collapsed.
......@@ -252,15 +252,14 @@ class BlockState(object):
deg_corr : ``bool`` (optional, default: ``True``)
If ``True``, the degree-corrected version of the blockmodel ensemble will
be assumed, otherwise the traditional variant will be used.
max_BE : ``int`` (optional, default: ``1000``)
If the number of blocks exceeds this value, a sparse matrix is used for
the block graph. Otherwise a dense matrix will be used.
dense_bg : ``bool`` (optional, default: ``False``)
If ``True`` a dense matrix is used for the block graph, otherwise a
sparse matrix will be used.
"""
def __init__(self, g, b=None, B=None, eweight=None, vweight=None, recs=[],
rec_types=[], rec_params=[], clabel=None, pclabel=None,
bfield=None, Bfield=None, deg_corr=True, max_BE=1000, **kwargs):
bfield=None, Bfield=None, deg_corr=True, dense_bg=False, **kwargs):
kwargs = kwargs.copy()
# initialize weights to unity, if necessary
......@@ -419,9 +418,8 @@ class BlockState(object):
self.bclabel = self.get_bclabel()
self.hclabel = self.bg.new_vp("int")
self.max_BE = max_BE
self.use_hash = self.B > self.max_BE
self.dense_bg = dense_bg
self.use_hash = not self.dense_bg
self.use_rmap = kwargs.pop("use_rmap", False)
self.merge_map = kwargs.pop("merge_map",
......@@ -596,7 +594,7 @@ class BlockState(object):
def copy(self, g=None, eweight=None, vweight=None, b=None, B=None,
deg_corr=None, clabel=None, overlap=False, pclabel=None,
bfield=None, max_BE=None, **kwargs):
bfield=None, dense_bg=None, **kwargs):
r"""Copies the block state. The parameters override the state properties, and
have the same meaning as in the constructor."""
......@@ -610,7 +608,7 @@ class BlockState(object):
pclabel=self.pclabel if pclabel is None else pclabel,
bfield=self.bfield if bfield is None else bfield,
deg_corr=self.deg_corr if deg_corr is None else deg_corr,
max_BE=self.max_BE if max_BE is None else max_BE,
dense_bg=self.dense_bg if dense_bg is None else dense_bg,
degs=self.degs.copy() if eweight is None else None,
merge_map=kwargs.pop("merge_map",
self.merge_map.copy()),
......@@ -635,7 +633,7 @@ class BlockState(object):
clabel=self.clabel if clabel is None else clabel,
pclabel=self.pclabel if pclabel is None else pclabel,
deg_corr=self.deg_corr if deg_corr is None else deg_corr,
max_BE=self.max_BE if max_BE is None else max_BE,
dense_bg=self.dense_bg if dense_bg is None else dense_bg,
Lrecdx=kwargs.pop("Lrecdx", self.Lrecdx.copy()),
epsilon=kwargs.pop("epsilon",self.epsilon.copy()),
**kwargs)
......@@ -659,7 +657,7 @@ class BlockState(object):
pclabel=self.pclabel,
bfield=self.bfield,
deg_corr=self.deg_corr,
max_BE=self.max_BE,
dense_bg=self.dense_bg,
recs=self.rec,
drec=self.drec,
rec_types=self.rec_types,
......@@ -778,7 +776,7 @@ class BlockState(object):
rec_params=rec_params,
clabel=kwargs.pop("clabel", self.get_bclabel()),
pclabel=kwargs.pop("pclabel", self.get_bpclabel()),
max_BE=self.max_BE,
dense_bg=self.dense_bg,
epsilon=kwargs.pop("epsilon",
self.epsilon.copy()),
**kwargs)
......@@ -874,6 +872,10 @@ class BlockState(object):
r"""Returns the property map which contains the block labels for each vertex."""
return self.b
def get_state(self):
"""Alias to :meth:`~BlockState.get_blocks`."""
return self.get_blocks()
def set_state(self, b):
r"""Sets the internal partition of the state."""
if not isinstance(b, VertexPropertyMap):
......
......@@ -92,10 +92,6 @@ class LayeredBlockState(OverlapBlockState, BlockState):
be assumed, otherwise the traditional variant will be used.
overlap : ``bool`` (optional, default: ``False``)
If ``True``, the overlapping version of the model will be used.
max_BE : ``int`` (optional, default: ``1000``)
If the number of blocks exceeds this value, a sparse matrix is used for
the block graph. Otherwise a dense matrix will be used.
"""
def __init__(self, g, ec, eweight=None, vweight=None, recs=[], rec_types=[],
......@@ -117,9 +113,9 @@ class LayeredBlockState(OverlapBlockState, BlockState):
self.C = len(kwargs.get("gs"))
self.layers = layers
if "max_BE" in kwargs:
del kwargs["max_BE"]
max_BE = 0
if "dense_bg" in kwargs:
del kwargs["dense_bg"]
dense_bg = False
if vweight is None:
vweight = g.new_vp("int", 1)
......@@ -149,7 +145,7 @@ class LayeredBlockState(OverlapBlockState, BlockState):
rec_types=rec_types, rec_params=rec_params,
clabel=clabel, pclabel=pclabel,
deg_corr=deg_corr,
max_BE=max_BE, degs=tdegs,
dense_bg=dense_bg, degs=tdegs,
Lrecdx=self.Lrecdx[0],
use_rmap=True,
**dmask(kwargs, ["degs", "lweights", "gs"]))
......@@ -160,7 +156,7 @@ class LayeredBlockState(OverlapBlockState, BlockState):
rec_types=rec_types,
rec_params=rec_params, clabel=clabel,
pclabel=pclabel, deg_corr=deg_corr,
max_BE=max_BE,
dense_bg=dense_bg,
Lrecdx=self.Lrecdx[0],
**dmask(kwargs, ["degs", "lweights",
"gs", "bfield"]))
......@@ -267,7 +263,7 @@ class LayeredBlockState(OverlapBlockState, BlockState):
self.layer_states = []
self.max_BE = max_BE
self.dense_bg = dense_bg
self.bg = agg_state.bg
self.wr = agg_state.wr
self.mrs = agg_state.mrs
......@@ -370,7 +366,7 @@ class LayeredBlockState(OverlapBlockState, BlockState):
vweight=u.vp["weight"],
deg_corr=self.deg_corr,
degs=degs,
max_BE=self.max_BE,
dense_bg=self.dense_bg,
use_rmap=True)
else:
base_u, node_index = self.__get_base_u(u)
......@@ -385,7 +381,7 @@ class LayeredBlockState(OverlapBlockState, BlockState):
node_index=node_index,
base_g=base_u,
deg_corr=self.deg_corr,
max_BE=self.max_BE)
dense_bg=self.dense_bg)
state.block_rmap = u.vp["brmap"]
state.vmap = u.vp["vmap"]
return state
......@@ -671,7 +667,7 @@ class LayeredBlockState(OverlapBlockState, BlockState):
b=bg.vertex_index.copy("int") if b is None else b,
deg_corr=deg_corr,
overlap=overlap,
max_BE=self.max_BE,
dense_bg=self.dense_bg,
layers=self.layers if layers is None else layers,
ec_done=True,
degs=degs, lweights=lweights,
......
......@@ -730,7 +730,7 @@ class TemperingState(object):
def mcmc_sweep(self, **kwargs):
"""Perform a full mcmc sweep of the parallel states, where swap or moves are
chosen randomly. It accepts an keyword argument ``r`` (default: ``0.1``)
specifying the relative probability with which state swaps is performed
specifying the relative probability with which state swaps are performed
with respect to node moves. All remaining keyword arguments are
propagated to the individual states' `mcmc_sweep()` method.
"""
......@@ -741,7 +741,7 @@ class TemperingState(object):
def multiflip_mcmc_sweep(self, **kwargs):
"""Perform a full mcmc sweep of the parallel states, where swap or moves are
chosen randomly. It accepts an keyword argument ``r`` (default: ``0.1``)
specifying the relative probability with which state swaps is performed
specifying the relative probability with which state swaps are performed
with respect to node moves. All remaining keyword arguments are
propagated to the individual states' `mcmc_sweep()` method.
"""
......@@ -752,7 +752,7 @@ class TemperingState(object):
def gibbs_sweep(self, **kwargs):
"""Perform a full Gibbs mcmc sweep of the parallel states, where swap or moves
are chosen randomly. It accepts an keyword argument ``r`` (default:
``0.1``) specifying the relative probability with which state swaps is
``0.1``) specifying the relative probability with which state swaps are
performed with respect to node moves. All remaining keyword arguments
are propagated to the individual states' `gibbs_sweep()` method.
"""
......
......@@ -215,6 +215,10 @@ class NestedBlockState(object):
"""
return [s.b.fa for s in self.levels]
def get_state(self):
"""Alias to :meth:`~NestedBlockState.get_bs`."""
return self.get_bs()
def set_state(self, bs):
r"""Sets the internal nested partition of the state."""
for i in range(len(bs)):
......
......@@ -75,14 +75,13 @@ class OverlapBlockState(BlockState):
deg_corr : ``bool`` (optional, default: ``True``)
If ``True``, the degree-corrected version of the blockmodel ensemble will
be assumed, otherwise the traditional variant will be used.
max_BE : ``int`` (optional, default: ``1000``)
If the number of blocks exceeds this number, a sparse representation of
the block graph is used, which is slightly less efficient, but uses less
memory,
dense_bg : ``bool`` (optional, default: ``False``)
If ``True`` a dense matrix is used for the block graph, otherwise a
sparse matrix will be used.
"""
def __init__(self, g, b=None, B=None, recs=[], rec_types=[], rec_params=[],
clabel=None, pclabel=None, deg_corr=True, max_BE=1000,
clabel=None, pclabel=None, deg_corr=True, dense_bg=False,
**kwargs):
kwargs = kwargs.copy()
......@@ -251,9 +250,8 @@ class OverlapBlockState(BlockState):
if numpy.any(idx):
self.epsilon[i] = abs(self.rec[i].a[idx]).min() / 10
self.max_BE = max_BE
self.use_hash = self.B > self.max_BE
self.dense_bg = dense_bg
self.use_hash = not self.dense_bg
self.bfield = self.g.new_vp("vector<double>")
self.Bfield = Vector_double()
......@@ -326,14 +324,14 @@ class OverlapBlockState(BlockState):
half_edges=kwargs.get("half_edges", self.half_edges),
node_index=kwargs.get("node_index", self.node_index),
eindex=kwargs.get("eindex", self.eindex),
max_BE=kwargs.get("max_BE", self.max_BE),
dense_bg=kwargs.get("dense_bg", self.dense_bg),
base_g=kwargs.get("base_g", self.base_g),
Lrecdx=kwargs.pop("Lrecdx", self.Lrecdx.copy()),
epsilon=kwargs.pop("epsilon",
self.epsilon.copy()),
**dmask(kwargs, ["half_edges", "node_index",
"eindex", "base_g", "drec",
"max_BE"]))
"dense_bg"]))
if self._coupled_state is not None:
state._couple_state(state.get_block_state(b=state.get_bclabel(),
vweight="nonempty",
......@@ -355,7 +353,7 @@ class OverlapBlockState(BlockState):
half_edges=self.half_edges,
node_index=self.node_index,
eindex=self.eindex,
max_BE=self.max_BE,
dense_bg=self.dense_bg,
base_g=self.base_g)
return state
......
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