Commit 5b21cc1e authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

inference: fix blockmodel entropy for weighted graphs

parent f78f5614
Pipeline #176 failed with stage
......@@ -39,12 +39,12 @@ python::object make_block_state(boost::python::object ostate,
return state;
}
degs_map_t get_block_degs(GraphInterface& gi, boost::any ab)
degs_map_t get_block_degs(GraphInterface& gi, boost::any ab, boost::any aweight)
{
degs_map_t degs;
vmap_t b = boost::any_cast<vmap_t>(ab);
run_action<>()(gi,
[&](auto& g)
[&](auto& g, auto& eweight)
{
std::vector<gt_hash_map<std::tuple<size_t, size_t>,
size_t>> hist;
......@@ -53,8 +53,8 @@ degs_map_t get_block_degs(GraphInterface& gi, boost::any ab)
size_t r = b[v];
if (r >= hist.size())
hist.resize(r + 1);
size_t kin = in_degreeS()(v, g);
size_t kout = out_degreeS()(v, g);
size_t kin = in_degreeS()(v, g, eweight);
size_t kout = out_degreeS()(v, g, eweight);
hist[r][std::make_tuple(kin, kout)]++;
}
......@@ -66,7 +66,8 @@ degs_map_t get_block_degs(GraphInterface& gi, boost::any ab)
get<1>(kn.first),
kn.second);
}
})();
},
eweight_tr())(aweight);
return degs;
}
......
......@@ -963,8 +963,8 @@ public:
{
if (_ignore_degrees[v] == 1)
return 0;
auto kin = in_degreeS()(v, _g);
auto kout = out_degreeS()(v, _g);
auto kin = in_degreeS()(v, _g, _eweight);
auto kout = out_degreeS()(v, _g, _eweight);
if (_ignore_degrees[v] == 2)
kout = 0;
double S = -lgamma_fast(kin + 1) - lgamma_fast(kout + 1);
......
......@@ -303,7 +303,8 @@ class BlockState(object):
if deg_corr and vweight:
if isinstance(self.degs, libinference.simple_degs_t):
degs = libinference.get_block_degs(self.g._Graph__graph,
_prop("v", self.g, self.b))
_prop("v", self.g, self.b),
self.eweight._get_any())
else:
degs = libinference.get_weighted_block_degs(self.g._Graph__graph,
self.degs,
......
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