Commit 6cccd783 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Correct degree sequence description length in blockmodel.py

parent 2d574cb3
...@@ -297,10 +297,10 @@ class BlockState(object): ...@@ -297,10 +297,10 @@ class BlockState(object):
.. math:: .. math::
\mathcal{L}_c = \mathcal{L}_t - N\sum_kp_k\ln p_k, \mathcal{L}_c = \mathcal{L}_t - \sum_rn_r\sum_kp^r_k\ln p^r_k,
where :math:`p_k` is the fraction of nodes with degree :math:`p_k`, and where :math:`p^r_k` is the fraction of nodes in block $r$ with degree :math:`k`. For directed
we have instead :math:`k \to (k^-, k^+)` for directed graphs. graphs we have instead :math:`k \to (k^-, k^+)`.
If the "dense" entropies are requested, they will be computed as If the "dense" entropies are requested, they will be computed as
...@@ -378,15 +378,15 @@ class BlockState(object): ...@@ -378,15 +378,15 @@ class BlockState(object):
else: else:
S += model_entropy(self.B, N, E, directed=self.g.is_directed(), nr=self.wr.a) * E S += model_entropy(self.B, N, E, directed=self.g.is_directed(), nr=self.wr.a) * E
if complete and self.deg_corr: if self.deg_corr:
S_seq = 0 S_seq = 0
hist = defaultdict(int) hist = [defaultdict(int) for r in range(self.B)]
for v in self.g.vertices(): for v in self.g.vertices():
hist[(v.in_degree(), v.out_degree())] += 1 hist[self.b[v]][(v.in_degree(), v.out_degree())] += 1
for k, v in hist.items(): for r in range(self.B):
p = v / float(self.g.num_vertices()) for k, v in hist[r].items():
S_seq -= p * log(p) p = v / float(self.wr.a[r])
S_seq *= self.g.num_vertices() S_seq -= p * log(p) * self.wr.a[r]
S += S_seq S += S_seq
return S / E return S / E
......
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