Commit 1966c234 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

inference: Fix issue when computing description length using pclabel

parent 39f0cf57
......@@ -988,7 +988,13 @@ public:
dS += ps.get_delta_deg_dl(v, r, nr, gs._vweight, gs._eweight,
gs._degs, gs._g, ea.degree_dl_kind);
if (ea.edges_dl)
dS += ps.get_delta_edges_dl(v, r, nr, gs._vweight, gs._g);
{
size_t actual_B = 0;
for (auto& ps : _partition_stats)
actual_B += ps.get_actual_B();
dS += ps.get_delta_edges_dl(v, r, nr, gs._vweight, actual_B,
gs._g);
}
}
auto positive_entries_op = [&](auto&& w_log_P)
......@@ -1464,7 +1470,10 @@ public:
break;
case weight_type::DELTA_T: // waiting times
for (auto r : vertices_range(_bg))
S += -positive_w_log_P(_mrp[r], _brecsum[r], _alpha, _beta);
{
if (_brecsum[r] > 0)
S += -positive_w_log_P(_mrp[r], _brecsum[r], _alpha, _beta);
}
break;
}
return S;
......
......@@ -442,7 +442,12 @@ public:
if (_deg_corr && ea.degree_dl)
dS += ps.get_delta_deg_dl(v, r, nr, _eweight, _g);
if (ea.edges_dl)
dS += ps.get_delta_edges_dl(v, r, nr, _g);
{
size_t actual_B = 0;
for (auto& ps : _partition_stats)
actual_B += ps.get_actual_B();
dS += ps.get_delta_edges_dl(v, r, nr, actual_B, _g);
}
}
switch (_rec_type)
......
......@@ -862,7 +862,8 @@ struct overlap_partition_stats_t
}
template <class Graph>
double get_delta_edges_dl(size_t v, size_t r, size_t nr, const Graph&)
double get_delta_edges_dl(size_t v, size_t r, size_t nr, size_t actual_B,
const Graph&)
{
if (r == nr || _allow_empty)
return 0;
......@@ -885,8 +886,8 @@ struct overlap_partition_stats_t
return (B * (B + 1)) / 2;
};
S_b += lbinom(get_x(_actual_B) + _E - 1, _E);
S_a += lbinom(get_x(_actual_B + dB) + _E - 1, _E);
S_b += lbinom(get_x(actual_B) + _E - 1, _E);
S_a += lbinom(get_x(actual_B + dB) + _E - 1, _E);
}
return S_a - S_b;
......@@ -1207,6 +1208,11 @@ struct overlap_partition_stats_t
}
size_t get_actual_B()
{
return _actual_B;
}
private:
overlap_stats_t& _overlap_stats;
vector<size_t>& _bmap;
......
......@@ -503,9 +503,9 @@ public:
return S_a - S_b;
}
template <class Graph, class VProp>
template <class VProp, class Graph>
double get_delta_edges_dl(size_t v, size_t r, size_t nr, VProp& vweight,
Graph&)
size_t actual_B, Graph&)
{
if (r == nr || _allow_empty)
return 0;
......@@ -543,8 +543,8 @@ public:
return (B * (B + 1)) / 2;
};
S_b += lbinom(get_x(_actual_B) + _E - 1, _E);
S_a += lbinom(get_x(_actual_B + dB) + _E - 1, _E);
S_b += lbinom(get_x(actual_B) + _E - 1, _E);
S_a += lbinom(get_x(actual_B + dB) + _E - 1, _E);
}
return S_a - S_b;
......@@ -780,6 +780,11 @@ public:
return _N;
}
size_t get_actual_B()
{
return _actual_B;
}
private:
vector<size_t>& _bmap;
size_t _N;
......
......@@ -819,7 +819,7 @@ class BlockState(object):
if self.allow_empty:
actual_B = self.B
else:
actual_B = (self.wr.a > 0).sum()
actual_B = self.get_nonempty_B()
S += model_entropy(actual_B, N, E,
directed=self.g.is_directed(), nr=False)
......
......@@ -209,7 +209,8 @@ class NestedBlockState(object):
continuous_map(b)
continuous_map(b2)
assert ((b == b2).all() and
(bstate.entropy() - self.levels[l].entropy())) < 1e-6, \
(bstate.entropy(dl=False) -
self.levels[l].entropy(dl=False))) < 1e-6, \
"inconsistent level %d (%s %g, %s %g): %s" % \
(l, str(bstate), bstate.entropy(), str(self.levels[l]),
self.levels[l].entropy(), str(self))
......
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