Commit 1c155fb7 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

inference: Improve partition update

parent 25200e72
......@@ -1169,14 +1169,20 @@ public:
if (r != null_group)
{
dS += vt(_mrp[r] - kout, _mrm[r] - kin, _wr[r] - dwr );
dS -= vt(_mrp[r] , _mrm[r] , _wr[r] );
auto mrp_r = _mrp[r];
auto mrm_r = _mrm[r];
auto wr_r = _wr[r];
dS += vt(mrp_r - kout, mrm_r - kin, wr_r - dwr);
dS -= vt(mrp_r , mrm_r , wr_r );
}
if (nr != null_group)
{
dS += vt(_mrp[nr] + kout, _mrm[nr] + kin, _wr[nr] + dwnr);
dS -= vt(_mrp[nr] , _mrm[nr] , _wr[nr] );
auto mrp_nr = _mrp[nr];
auto mrm_nr = _mrm[nr];
auto wr_nr = _wr[nr];
dS += vt(mrp_nr + kout, mrm_nr + kin, wr_nr + dwnr);
dS -= vt(mrp_nr , mrm_nr , wr_nr );
}
return dS;
......@@ -1198,11 +1204,6 @@ public:
if (r == nr)
return 0;
int kin = 0, kout = 0;
kout += out_degreeS()(v, _g, _eweight);
if (is_directed::apply<g_t>::type::value)
kin += in_degreeS()(v, _g, _eweight);
vector<int> deltap(num_vertices(_bg), 0);
int deltal = 0;
for (auto e : out_edges_range(v, _g))
......@@ -1969,10 +1970,17 @@ public:
double p = 0;
size_t w = 0;
size_t kout = out_degreeS()(v, _g, _eweight);
size_t kin = kout;
if (is_directed::apply<g_t>::type::value)
kin = in_degreeS()(v, _g, _eweight);
size_t kout = 0, kin = 0;
degs_op(v, _vweight, _eweight, _degs, _g,
[&] (size_t din, size_t dout, auto c)
{
kout += dout * c;
if (graph_tool::is_directed(this->_g))
kin += din * c;
});
if (!graph_tool::is_directed(_g))
kin = kout;
m_entries.get_mes(_emat);
auto sum_prob = [&](auto& e, auto u)
......@@ -2089,7 +2097,7 @@ public:
return S * _vweight[v];
}
double get_deg_entropy(size_t v, typename degs_map_t::unchecked_t& degs)
double get_deg_entropy(size_t v, const typename degs_map_t::unchecked_t& degs)
{
if (_ignore_degrees[v] == 1)
return 0;
......
......@@ -44,7 +44,7 @@ void degs_op(size_t v, Vprop& vweight, Eprop& eweight, const simple_degs_t&,
template <class Graph, class Vprop, class Eprop, class F>
void degs_op(size_t v, Vprop& vweight, Eprop& eweight,
typename degs_map_t::unchecked_t& degs, Graph& g, F&& f)
const typename degs_map_t::unchecked_t& degs, Graph& g, F&& f)
{
auto& ks = degs[v];
if (ks.empty())
......@@ -485,11 +485,38 @@ public:
VWeight& vweight, EWeight& eweight, Degs& degs,
int diff)
{
degs_op(v, vweight, eweight, degs, g,
[&](auto kin, auto kout, auto n)
{
this->change_k(v, r, deg_corr, n, kin, kout, diff);
});
int vw = vweight[v];
int dv = vw * diff;
if (_total[r] == 0 && dv > 0)
_actual_B++;
if (_total[r] == vw && dv < 0)
_actual_B--;
_total[r] += dv;
_N += dv;
assert(_total[r] >= 0);
if (deg_corr && _ignore_degree[v] != 1)
{
degs_op(v, vweight, eweight, degs, g,
[&](auto kin, auto kout, auto n)
{
int dk = diff * n;
if (_ignore_degree[v] == 2)
kout = 0;
auto& h = _hist[r];
auto deg = make_pair(kin, kout);
auto iter = h.insert({deg, 0}).first;
iter->second += dk;
if (iter->second == 0)
h.erase(iter);
_em[r] += dk * deg.first;
_ep[r] += dk * deg.second;
});
}
}
template <class Graph, class VWeight, class EWeight, class Degs>
......@@ -537,6 +564,11 @@ public:
}
}
void change_E(int dE)
{
_E += dE;
}
size_t get_N()
{
return _N;
......
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