Commit d8007e21 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

uncertain: fix edge sampling and updating

parent 70545896
......@@ -365,6 +365,8 @@ public:
_emat.remove_me(me, _bg);
if (_coupled_state != nullptr)
_coupled_state->remove_edge(me);
else
boost::remove_edge(me, _bg);
}
assert(e != _emat.get_null_edge());
boost::remove_edge(e, _g);
......@@ -787,12 +789,12 @@ public:
void add_edge(size_t u, size_t v, GraphInterface::edge_t& e, int dw)
{
modify_edge<true, false>(u, v, e, dw);
modify_edge<true, true>(u, v, e, dw);
}
void remove_edge(size_t u, size_t v, GraphInterface::edge_t& e, int dw)
{
modify_edge<false, false>(u, v, e, dw);
modify_edge<false, true>(u, v, e, dw);
}
void set_vertex_weight(size_t v, int w)
......
......@@ -238,7 +238,7 @@ struct Dynamics
_dstate.template update_edge<false>(v, u, x);
}
_E--;
_E -= dw;
}
void add_edge(size_t u, size_t v, int dw, double x)
......@@ -256,7 +256,8 @@ struct Dynamics
if (u != v && !graph_tool::is_directed(_u))
_dstate.template update_edge<true>(v, u, x);
}
_E++;
_E += dw;
}
void update_edge(size_t u, size_t v, double dx)
......
......@@ -260,11 +260,16 @@ struct MCMC
else
{
size_t m = get<0>(node_state(u, v));
_edge_sampler.update_edge(u, v, m, dm);
if (dm < 0)
{
_edge_sampler.update_edge(u, v, m, dm);
_state.remove_edge(u, v, -dm);
}
else
{
_state.add_edge(u, v, dm, dx);
_edge_sampler.update_edge(u, v, m, dm);
}
}
}
......
......@@ -338,17 +338,21 @@ struct MCMC
{
if (l == 0)
_edge_sampler.update_edge(u, v, m, -1);
if (nl == 0)
_edge_sampler.update_edge(u, v, m, 1);
}
for (size_t i = 0; i < m; ++i)
_state.remove_edge(l, u, v);
for (size_t i = 0; i < m; ++i)
_state.add_edge(nl, u, v);
if (_measured)
{
if (nl == 0)
_edge_sampler.update_edge(u, v, m, 1);
}
}
else
{
if (_measured && l == 0)
if (_measured && l == 0 && dm < 0)
_edge_sampler.update_edge(u, v, m, dm);
if (dm < 0)
......@@ -361,6 +365,9 @@ struct MCMC
for (int i = 0; i < dm; ++i)
_state.add_edge(l, u, v);
}
if (_measured && l == 0 && dm > 0)
_edge_sampler.update_edge(u, v, m, dm);
}
}
......
......@@ -133,16 +133,20 @@ public:
auto me = _state._emat.get_me(r, s);
if (me != _state._emat.get_null_edge())
{
auto ers = _state._mrs[me] + delta;
int ers = _state._mrs[me] + (delta < 0) ? delta : 0;
if (ers == 0)
{
_rs_sampler.remove(_rs_pos[me]);
_rs_pos[me] = std::numeric_limits<size_t>::max();
}
else
else if (delta == ers)
{
_rs_pos[me] = _rs_sampler.insert({r,s}, ers);
}
else
{
_rs_sampler.update(_rs_pos[me], delta, true);
}
}
if (_state._deg_corr)
......@@ -152,15 +156,18 @@ public:
get<0>(get_deg(v, _state._eweight, _state._degs, _state._g)) :
get<1>(get_deg(v, _state._eweight, _state._degs, _state._g));
if (u != v || graph_tool::is_directed(_state._g))
if (delta < 0)
{
ku += delta;
kv += delta;
}
else
{
ku += 2 * delta;
kv += 2 * delta;
if (u != v || graph_tool::is_directed(_state._g))
{
ku += delta;
kv += delta;
}
else
{
ku += 2 * delta;
kv += 2 * delta;
}
}
_v_out_sampler[r].remove(_v_out_pos[u]);
......
......@@ -147,12 +147,16 @@ struct MCMC
std::tie(u, v) = get_edge();
size_t m = node_state(u, v);
_edge_sampler.update_edge(u, v, m, dm);
if (dm < 0)
{
_edge_sampler.update_edge(u, v, m, dm);
_state.remove_edge(u, v, -dm);
}
else
{
_state.add_edge(u, v, dm);
_edge_sampler.update_edge(u, v, m, dm);
}
}
bool is_deterministic()
......
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