Commit c86b0856 authored by Tiago Peixoto's avatar Tiago Peixoto

inference: avoid computing move probabilities in greedy mode

This also fixes a potential problem with layered SBMs, where the move
probabilities would be incorrectly computed.
parent d6c4ad94
......@@ -1703,6 +1703,8 @@ public:
{
auto r = rs_m.first.first;
auto s = rs_m.first.second;
if (rs_m.second == 0)
continue;
auto me = _emat.get_me(r, s);
if (me == _emat.get_null_edge())
{
......
......@@ -420,6 +420,25 @@ struct Layers
return virtual_move(v, r, s, ea, _m_entries);
}
template <class MEntries>
double get_move_prob(size_t v, size_t r, size_t s, double c,
bool reverse, MEntries& m_entries)
{
// m_entries may include entries from different levels
if (!reverse)
{
m_entries.clear();
BaseState::get_move_entries(v, r, s, m_entries);
}
return BaseState::get_move_prob(v, r, s, c, reverse, m_entries);
}
double get_move_prob(size_t v, size_t r, size_t s, double c,
bool reverse)
{
return BaseState::get_move_prob(v, r, s, c, reverse);
}
void merge_vertices(size_t u, size_t v)
{
std::set<size_t> ls;
......
......@@ -111,7 +111,7 @@ struct MCMC
double dS = _state.virtual_move(v, r, nr, _entropy_args,
_m_entries);
double a = 0;
if (!std::isinf(_c))
if (!std::isinf(_c) && !std::isinf(_beta))
{
double pf = _state.get_move_prob(v, r, nr, _c, false,
_m_entries);
......
......@@ -1080,6 +1080,36 @@ public:
disable_partition_stats();
}
bool check_edge_counts()
{
gt_hash_map<std::pair<size_t, size_t>, size_t> mrs;
for (auto e : edges_range(_g))
{
size_t r = _b[source(e, _g)];
size_t s = _b[target(e, _g)];
if (!is_directed::apply<g_t>::type::value && s < r)
std::swap(r, s);
mrs[std::make_pair(r, s)] += _eweight[e];
}
for (auto& rs_m : mrs)
{
auto r = rs_m.first.first;
auto s = rs_m.first.second;
auto me = _emat.get_me(r, s);
if (me == _emat.get_null_edge())
{
assert(false);
return false;
}
if (size_t(_mrs[me]) != rs_m.second)
{
assert(false);
return false;
}
}
return true;
}
//private:
typedef typename
......
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