Commit 19cee4ba authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

ModularityState: minor fixes

parent 05eb1d20
...@@ -119,7 +119,7 @@ class ModularityState(MCMCState, MultiflipMCMCState, MultilevelMCMCState, ...@@ -119,7 +119,7 @@ class ModularityState(MCMCState, MultiflipMCMCState, MultilevelMCMCState,
if b is None: if b is None:
self.b = self.g.new_vp("int32_t") self.b = self.g.new_vp("int32_t")
elif isinstance(b, PropertyMap): elif isinstance(b, PropertyMap):
self.b = b.copy("int32_t") self.b = self.g.own_property(b).copy("int32_t")
else: else:
self.b = self.g.new_vp("int32_t", vals=b) self.b = self.g.new_vp("int32_t", vals=b)
...@@ -135,11 +135,6 @@ class ModularityState(MCMCState, MultiflipMCMCState, MultilevelMCMCState, ...@@ -135,11 +135,6 @@ class ModularityState(MCMCState, MultiflipMCMCState, MultilevelMCMCState,
def __copy__(self): def __copy__(self):
return self.copy() return self.copy()
def __deepcopy__(self, memo):
g = copy.deepcopy(self.g, memo)
b = copy.deepcopy(self.b, memo)
return self.copy(g=g, b=b)
def copy(self, g=None, b=None): def copy(self, g=None, b=None):
r"""Copies the state. The parameters override the state properties, and r"""Copies the state. The parameters override the state properties, and
have the same meaning as in the constructor.""" have the same meaning as in the constructor."""
...@@ -158,14 +153,16 @@ class ModularityState(MCMCState, MultiflipMCMCState, MultilevelMCMCState, ...@@ -158,14 +153,16 @@ class ModularityState(MCMCState, MultiflipMCMCState, MultilevelMCMCState,
def get_B(self): def get_B(self):
r"Returns the total number of blocks." r"Returns the total number of blocks."
return len(np.unique(self.b.fa)) rs = np.unique(self.b.fa)
return len(rs)
def get_Be(self): def get_Be(self):
r"""Returns the effective number of blocks, defined as :math:`e^{H}`, with r"""Returns the effective number of blocks, defined as :math:`e^{H}`, with
:math:`H=-\sum_r\frac{n_r}{N}\ln \frac{n_r}{N}`, where :math:`n_r` is :math:`H=-\sum_r\frac{n_r}{N}\ln \frac{n_r}{N}`, where :math:`n_r` is
the number of nodes in group r. the number of nodes in group r.
""" """
w = np.array(np.bincount(self.b.fa), dtype="double") w = np.bincount(self.b.fa)
w = np.array(w, dtype="double")
w = w[w>0] w = w[w>0]
w /= w.sum() w /= w.sum()
return np.exp(-(w*log(w)).sum()) return np.exp(-(w*log(w)).sum())
......
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