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

inference: Delete unused block edges

parent fe8b6724
......@@ -267,6 +267,8 @@ public:
this->_c_brec[i][me] = 0;
this->_c_bdrec[i][me] = 0;
}
if (_coupled_state != nullptr)
_coupled_state->add_edge(me);
}
mid_op(me, delta);
......@@ -280,6 +282,15 @@ public:
assert(this->_mrm[s] >= 0);
end_op(me, delta);
if (!Add && this->_mrs[me] == 0)
{
this->_emat.remove_me(me, this->_bg);
if (_coupled_state != nullptr)
_coupled_state->remove_edge(me);
else
boost::remove_edge(me, this->_bg);
}
});
};
......@@ -312,14 +323,14 @@ public:
{
_B_E++;
if (_coupled_state != nullptr)
_coupled_state->add_edge(me);
_coupled_state->add_edge_rec(me);
}
if (!Add && mrs > 0 && mrs + get<1>(delta)[0] == 0)
{
_B_E--;
if (_coupled_state != nullptr)
_coupled_state->remove_edge(me);
_coupled_state->remove_edge_rec(me);
}
};
......@@ -393,7 +404,7 @@ public:
{
end_op(me, delta);
if (_coupled_state != nullptr)
_coupled_state->update_edge(me, get<1>(delta));
_coupled_state->update_edge_rec(me, get<1>(delta));
};
if (_Lrecdx[0] >= 0)
......@@ -431,7 +442,42 @@ public:
BlockState::remove_partition_node(v, r);
}
void add_edge(const GraphInterface::edge_t& e)
{
size_t r = _b[source(e, _g)];
size_t s = _b[target(e, _g)];
auto me = _emat.get_me(r, s);
if (me == _emat.get_null_edge())
{
me = boost::add_edge(r, s, _bg).first;
_emat.put_me(r, s, me);
_c_mrs[me] = 0;
for (size_t i = 0; i < _rec_types.size(); ++i)
{
_c_brec[i][me] = 0;
_c_bdrec[i][me] = 0;
}
if (_coupled_state != nullptr)
_coupled_state->add_edge(me);
}
}
void remove_edge(const GraphInterface::edge_t& e)
{
size_t r = _b[source(e, _g)];
size_t s = _b[target(e, _g)];
auto& me = _emat.get_me(r, s);
if (_mrs[me] == 0)
{
_emat.remove_me(me, _bg);
if (_coupled_state != nullptr)
_coupled_state->remove_edge(me);
}
boost::remove_edge(e, _g);
}
void add_edge_rec(const GraphInterface::edge_t& e)
{
if (_rec_types.empty())
return;
......@@ -483,9 +529,12 @@ public:
_Lrecdx[i+1] += _recdx[i] * _B_E_D;
}
}
if (_brec[0][me] == 1 && _coupled_state != nullptr)
_coupled_state->add_edge_rec(me);
}
void remove_edge(const GraphInterface::edge_t& e)
void remove_edge_rec(const GraphInterface::edge_t& e)
{
if (_rec_types.empty())
return;
......@@ -528,10 +577,13 @@ public:
_Lrecdx[i+1] += _recdx[i] * _B_E_D;
}
}
if (_brec[0][me] == 0 && _coupled_state != nullptr)
_coupled_state->remove_edge_rec(me);
}
void update_edge(const GraphInterface::edge_t& e,
const std::vector<double>& delta)
void update_edge_rec(const GraphInterface::edge_t& e,
const std::vector<double>& delta)
{
if (_rec_types.empty())
return;
......@@ -669,8 +721,12 @@ public:
}
}
// if (_mrs[me] == 0)
// _emat.remove_me(me, _bg);
if (_mrs[me] == 0)
{
_emat.remove_me(me, _bg);
if (_coupled_state != nullptr)
_coupled_state->remove_edge(me);
}
}
}
......
......@@ -74,7 +74,7 @@ public:
_mat[r][s] = _null_edge;
if (!is_directed::apply<BGraph>::type::value)
_mat[s][r] = _null_edge;
remove_edge(me, bg);
//remove_edge(me, bg);
}
const auto& get_null_edge() const { return _null_edge; }
......@@ -190,8 +190,11 @@ public:
if (!is_directed::apply<BGraph>::type::value && r > s)
std::swap(r, s);
assert(r < _hash.size());
_hash[r].erase(s);
remove_edge(me, bg);
auto& r_hash = _hash[r];
r_hash.erase(s);
if (r_hash.empty())
r_hash.resize(0);
//remove_edge(me, bg);
}
const auto& get_null_edge() const { return _null_edge; }
......
......@@ -42,8 +42,10 @@ public:
virtual size_t add_block() = 0;
virtual void add_edge(const GraphInterface::edge_t& e) = 0;
virtual void remove_edge(const GraphInterface::edge_t& e) = 0;
virtual void update_edge(const GraphInterface::edge_t& e,
const std::vector<double>& delta) = 0;
virtual void add_edge_rec(const GraphInterface::edge_t& e) = 0;
virtual void remove_edge_rec(const GraphInterface::edge_t& e) = 0;
virtual void update_edge_rec(const GraphInterface::edge_t& e,
const std::vector<double>& delta) = 0;
virtual double recs_dS(size_t, size_t,
const std::vector<std::tuple<size_t, size_t,
GraphInterface::edge_t, int,
......
......@@ -953,10 +953,20 @@ struct Layers
BaseState::remove_edge(e);
}
void update_edge(const GraphInterface::edge_t& e,
const std::vector<double>& delta)
void add_edge_rec(const GraphInterface::edge_t& e)
{
BaseState::update_edge(e, delta);
BaseState::add_edge_rec(e);
}
void remove_edge_rec(const GraphInterface::edge_t& e)
{
BaseState::remove_edge_rec(e);
}
void update_edge_rec(const GraphInterface::edge_t& e,
const std::vector<double>& delta)
{
BaseState::update_edge_rec(e, delta);
}
double recs_dS(size_t, size_t,
......
......@@ -181,6 +181,8 @@ public:
_c_brec[i][me] = 0;
_c_bdrec[i][me] = 0;
}
if (_coupled_state != nullptr)
_coupled_state->add_edge(me);
}
auto e = *out_edges(v, _g).first;
......@@ -202,8 +204,15 @@ public:
eop(e, me);
assert(_mrs[me] >= 0);
// if (_mrs[me] == 0)
// _emat.remove_me(me, _bg);
if (!Add && this->_mrs[me] == 0)
{
this->_emat.remove_me(me, this->_bg);
if (_coupled_state != nullptr)
_coupled_state->remove_edge(me);
else
boost::remove_edge(me, this->_bg);
}
}
u = _overlap_stats.get_in_neighbor(v);
......@@ -226,6 +235,8 @@ public:
_c_brec[i][me] = 0;
_c_bdrec[i][me] = 0;
}
if (_coupled_state != nullptr)
_coupled_state->add_edge(me);
}
auto e = *in_edge_iteratorS<g_t>().get_edges(v, _g).first;
......@@ -246,8 +257,14 @@ public:
eop(e, me);
// if (_mrs[me] == 0)
// _emat.remove_me(me, _bg);
if (!Add && this->_mrs[me] == 0)
{
this->_emat.remove_me(me, this->_bg);
if (_coupled_state != nullptr)
_coupled_state->remove_edge(me);
else
boost::remove_edge(me, this->_bg);
}
}
if (Add)
......@@ -301,14 +318,14 @@ public:
{
_B_E++;
if (_coupled_state != nullptr)
_coupled_state->add_edge(me);
_coupled_state->add_edge_rec(me);
}
if (!Add && mrs > 0 && mrs + one * this->_rec[0][e] == 0)
{
_B_E--;
if (_coupled_state != nullptr)
_coupled_state->remove_edge(me);
_coupled_state->remove_edge_rec(me);
}
};
......@@ -392,7 +409,7 @@ public:
_rdelta.clear();
for (size_t i = 0; i < this->_rec_types.size(); ++i)
_rdelta.push_back(one * this->_rec[i][e]);
_coupled_state->update_edge(me, _rdelta);
_coupled_state->update_edge_rec(me, _rdelta);
}
};
......@@ -1524,7 +1541,16 @@ public:
{
}
void update_edge(const GraphInterface::edge_t&, std::vector<double>&)
void add_edge_rec(const GraphInterface::edge_t&)
{
}
void remove_edge_rec(const GraphInterface::edge_t&)
{
}
void update_edge_rec(const GraphInterface::edge_t&,
const std::vector<double>&)
{
}
......
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