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

Remove 'ignore_degrees' remnant

parent d9a6289b
...@@ -176,8 +176,7 @@ void export_blockmodel_state() ...@@ -176,8 +176,7 @@ void export_blockmodel_state()
.value("real_normal", weight_type::REAL_NORMAL) .value("real_normal", weight_type::REAL_NORMAL)
.value("discrete_geometric", weight_type::DISCRETE_GEOMETRIC) .value("discrete_geometric", weight_type::DISCRETE_GEOMETRIC)
.value("discrete_poisson", weight_type::DISCRETE_POISSON) .value("discrete_poisson", weight_type::DISCRETE_POISSON)
.value("discrete_binomial", weight_type::DISCRETE_BINOMIAL) .value("discrete_binomial", weight_type::DISCRETE_BINOMIAL);
.value("delta_t", weight_type::DELTA_T);
def("make_block_state", &make_block_state); def("make_block_state", &make_block_state);
......
...@@ -102,8 +102,6 @@ typedef mpl::vector1<std::false_type> rmap_tr; ...@@ -102,8 +102,6 @@ typedef mpl::vector1<std::false_type> rmap_tr;
((recdx, &, std::vector<double>&, 0)) \ ((recdx, &, std::vector<double>&, 0)) \
((Lrecdx, &, std::vector<double>&, 0)) \ ((Lrecdx, &, std::vector<double>&, 0)) \
((epsilon, &, std::vector<double>&, 0)) \ ((epsilon, &, std::vector<double>&, 0)) \
((ignore_degrees,, typename vprop_map_t<uint8_t>::type, 0)) \
((bignore_degrees,, typename vprop_map_t<uint8_t>::type, 0)) \
((allow_empty,, bool, 0)) ((allow_empty,, bool, 0))
GEN_STATE_BASE(BlockStateBase, BLOCK_STATE_params) GEN_STATE_BASE(BlockStateBase, BLOCK_STATE_params)
...@@ -272,19 +270,6 @@ public: ...@@ -272,19 +270,6 @@ public:
BlockState::add_partition_node(v, r); BlockState::add_partition_node(v, r);
else else
BlockState::remove_partition_node(v, r); BlockState::remove_partition_node(v, r);
if (!_rec_types.empty() &&
_rec_types[1] == weight_type::DELTA_T) // waiting times
{
if (_ignore_degrees[v] > 0)
{
auto dt = out_degreeS()(v, _g, _rec[1]);
if (Add)
_brecsum[r] += dt;
else
_brecsum[r] -= dt;
}
}
} }
bool allow_move(size_t v, size_t r, size_t nr, bool allow_empty = true) bool allow_move(size_t v, size_t r, size_t nr, bool allow_empty = true)
...@@ -317,17 +302,6 @@ public: ...@@ -317,17 +302,6 @@ public:
BlockState::remove_partition_node(v, r); BlockState::remove_partition_node(v, r);
BlockState::add_partition_node(v, nr); BlockState::add_partition_node(v, nr);
if (!_rec_types.empty() &&
_rec_types[1] == weight_type::DELTA_T) // waiting times
{
if (_ignore_degrees[v] > 0)
{
auto dt = out_degreeS()(v, _g, _rec[1]);
_brecsum[r] -= dt;
_brecsum[nr] += dt;
}
}
} }
// move a vertex from its current block to block nr // move a vertex from its current block to block nr
...@@ -1167,7 +1141,6 @@ public: ...@@ -1167,7 +1141,6 @@ public:
add_element(_empty_blocks, _empty_pos, r); add_element(_empty_blocks, _empty_pos, r);
for (auto& p : _partition_stats) for (auto& p : _partition_stats)
p.add_block(); p.add_block();
_bignore_degrees.resize(num_vertices(_bg));
if (!_egroups.empty()) if (!_egroups.empty())
_egroups.init(_b, _eweight, _g, _bg); _egroups.init(_b, _eweight, _g, _bg);
if (_coupled_state != nullptr) if (_coupled_state != nullptr)
...@@ -1182,7 +1155,6 @@ public: ...@@ -1182,7 +1155,6 @@ public:
_bfield.resize(num_vertices(_g)); _bfield.resize(num_vertices(_g));
init_vertex_weight(v); init_vertex_weight(v);
_pclabel.resize(num_vertices(_g)); _pclabel.resize(num_vertices(_g));
_ignore_degrees.resize(num_vertices(_g));
resize_degs(_degs); resize_degs(_degs);
_neighbor_sampler.resize(num_vertices(_g)); _neighbor_sampler.resize(num_vertices(_g));
} }
...@@ -1985,27 +1957,19 @@ public: ...@@ -1985,27 +1957,19 @@ public:
double get_deg_entropy(size_t v, const simple_degs_t&) double get_deg_entropy(size_t v, const simple_degs_t&)
{ {
if (_ignore_degrees[v] == 1)
return 0;
auto kin = in_degreeS()(v, _g, _eweight); auto kin = in_degreeS()(v, _g, _eweight);
auto kout = out_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); double S = -lgamma_fast(kin + 1) - lgamma_fast(kout + 1);
return S * _vweight[v]; return S * _vweight[v];
} }
double get_deg_entropy(size_t v, const 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;
double S = 0; double S = 0;
for (auto& ks : degs[v]) for (auto& ks : degs[v])
{ {
auto kin = get<0>(ks); auto kin = get<0>(ks);
auto kout = get<1>(ks); auto kout = get<1>(ks);
if (_ignore_degrees[v] == 2)
kout = 0;
int n = get<2>(ks); int n = get<2>(ks);
S -= n * (lgamma_fast(kin + 1) + lgamma_fast(kout + 1)); S -= n * (lgamma_fast(kin + 1) + lgamma_fast(kout + 1));
} }
...@@ -2422,8 +2386,7 @@ public: ...@@ -2422,8 +2386,7 @@ public:
for (size_t c = 0; c < C; ++c) for (size_t c = 0; c < C; ++c)
_partition_stats.emplace_back(_g, _b, vcs[c], E, B, _partition_stats.emplace_back(_g, _b, vcs[c], E, B,
_vweight, _eweight, _degs, _vweight, _eweight, _degs,
_ignore_degrees, _bmap, _bmap, _allow_empty);
_allow_empty);
for (auto r : vertices_range(_bg)) for (auto r : vertices_range(_bg))
_partition_stats[rc[r]].get_r(r); _partition_stats[rc[r]].get_r(r);
......
...@@ -128,7 +128,6 @@ struct Merge ...@@ -128,7 +128,6 @@ struct Merge
void perform_merge(size_t r, size_t s) void perform_merge(size_t r, size_t s)
{ {
assert(_state._bclabel[r] == _state._bclabel[s]); assert(_state._bclabel[r] == _state._bclabel[s]);
assert(_state._ignore_degrees[r] == _state._ignore_degrees[s]);
_state.move_vertex(r, s); _state.move_vertex(r, s);
_state.merge_vertices(r, s); _state.merge_vertices(r, s);
} }
......
...@@ -68,11 +68,10 @@ public: ...@@ -68,11 +68,10 @@ public:
typedef gt_hash_map<pair<size_t,size_t>, int> map_t; typedef gt_hash_map<pair<size_t,size_t>, int> map_t;
template <class Graph, class Vprop, class VWprop, class Eprop, class Degs, template <class Graph, class Vprop, class VWprop, class Eprop, class Degs,
class Mprop, class Vlist> class Vlist>
partition_stats(Graph& g, Vprop& b, Vlist& vlist, size_t E, size_t B, partition_stats(Graph& g, Vprop& b, Vlist& vlist, size_t E, size_t B,
VWprop& vweight, Eprop& eweight, Degs& degs, VWprop& vweight, Eprop& eweight, Degs& degs,
const Mprop& ignore_degree, std::vector<size_t>& bmap, std::vector<size_t>& bmap, bool allow_empty)
bool allow_empty)
: _bmap(bmap), _N(0), _E(E), _total_B(B), _allow_empty(allow_empty) : _bmap(bmap), _N(0), _E(E), _total_B(B), _allow_empty(allow_empty)
{ {
if (!use_rmap) if (!use_rmap)
...@@ -89,21 +88,13 @@ public: ...@@ -89,21 +88,13 @@ public:
continue; continue;
auto r = get_r(b[v]); auto r = get_r(b[v]);
if (v >= _ignore_degree.size())
_ignore_degree.resize(v + 1, 0);
_ignore_degree[v] = ignore_degree[v];
degs_op(v, vweight, eweight, degs, g, degs_op(v, vweight, eweight, degs, g,
[&](auto kin, auto kout, auto n) [&](auto kin, auto kout, auto n)
{ {
if (_ignore_degree[v] == 2) _hist[r][make_pair(kin, kout)] += n;
kout = 0; _em[r] += kin * n;
if (_ignore_degree[v] != 1) _ep[r] += kout * n;
{
_hist[r][make_pair(kin, kout)] += n;
_em[r] += kin * n;
_ep[r] += kout * n;
}
_total[r] += n; _total[r] += n;
_N += n; _N += n;
}); });
...@@ -371,7 +362,7 @@ public: ...@@ -371,7 +362,7 @@ public:
double get_delta_deg_dl(size_t v, size_t r, size_t nr, VProp& vweight, double get_delta_deg_dl(size_t v, size_t r, size_t nr, VProp& vweight,
EProp& eweight, Degs& degs, Graph& g, int kind) EProp& eweight, Degs& degs, Graph& g, int kind)
{ {
if (r == nr || _ignore_degree[v] == 1 || vweight[v] == 0) if (r == nr || vweight[v] == 0)
return 0; return 0;
if (r != null_group) if (r != null_group)
r = get_r(r); r = get_r(r);
...@@ -381,19 +372,8 @@ public: ...@@ -381,19 +372,8 @@ public:
auto dop = auto dop =
[&](auto&& f) [&](auto&& f)
{ {
if (_ignore_degree[v] == 2) degs_op(v, vweight, eweight, degs, g,
{ [&](auto... k) { f(k...); });
degs_op(v, vweight, eweight, degs, g,
[&](auto kin, auto, auto n)
{
f(kin, 0, n);
});
}
else
{
degs_op(v, vweight, eweight, degs, g,
[&](auto... k) { f(k...); });
}
}; };
double dS = 0; double dS = 0;
...@@ -407,15 +387,15 @@ public: ...@@ -407,15 +387,15 @@ public:
break; break;
case deg_dl_kind::UNIFORM: case deg_dl_kind::UNIFORM:
if (r != null_group) if (r != null_group)
dS += get_delta_deg_dl_uniform_change(v, r, dop, -1); dS += get_delta_deg_dl_uniform_change(r, dop, -1);
if (nr != null_group) if (nr != null_group)
dS += get_delta_deg_dl_uniform_change(v, nr, dop, +1); dS += get_delta_deg_dl_uniform_change(nr, dop, +1);
break; break;
case deg_dl_kind::DIST: case deg_dl_kind::DIST:
if (r != null_group) if (r != null_group)
dS += get_delta_deg_dl_dist_change(v, r, dop, -1); dS += get_delta_deg_dl_dist_change(r, dop, -1);
if (nr != null_group) if (nr != null_group)
dS += get_delta_deg_dl_dist_change(v, nr, dop, +1); dS += get_delta_deg_dl_dist_change(nr, dop, +1);
break; break;
default: default:
dS = numeric_limits<double>::quiet_NaN(); dS = numeric_limits<double>::quiet_NaN();
...@@ -455,8 +435,7 @@ public: ...@@ -455,8 +435,7 @@ public:
} }
template <class DegOP> template <class DegOP>
double get_delta_deg_dl_uniform_change(size_t v, size_t r, DegOP&& dop, double get_delta_deg_dl_uniform_change(size_t r, DegOP&& dop, int diff)
int diff)
{ {
auto get_Se = [&](int dn, int dkin, int dkout) auto get_Se = [&](int dn, int dkin, int dkout)
{ {
...@@ -471,8 +450,7 @@ public: ...@@ -471,8 +450,7 @@ public:
dop([&](auto kin, auto kout, int nk) dop([&](auto kin, auto kout, int nk)
{ {
tkin += kin * nk; tkin += kin * nk;
if (_ignore_degree[v] != 2) tkout += kout * nk;
tkout += kout * nk;
n += nk; n += nk;
}); });
...@@ -482,8 +460,7 @@ public: ...@@ -482,8 +460,7 @@ public:
} }
template <class DegOP> template <class DegOP>
double get_delta_deg_dl_dist_change(size_t v, size_t r, DegOP&& dop, double get_delta_deg_dl_dist_change(size_t r, DegOP&& dop, int diff)
int diff)
{ {
auto get_Se = [&](int delta, int kin, int kout) auto get_Se = [&](int delta, int kin, int kout)
{ {
...@@ -517,8 +494,7 @@ public: ...@@ -517,8 +494,7 @@ public:
dop([&](size_t kin, size_t kout, int nk) dop([&](size_t kin, size_t kout, int nk)
{ {
tkin += kin * nk; tkin += kin * nk;
if (_ignore_degree[v] != 2) tkout += kout * nk;
tkout += kout * nk;
n += nk; n += nk;
auto deg = make_pair(kin, kout); auto deg = make_pair(kin, kout);
...@@ -554,14 +530,12 @@ public: ...@@ -554,14 +530,12 @@ public:
assert(_total[r] >= 0); assert(_total[r] >= 0);
if (deg_corr && _ignore_degree[v] != 1) if (deg_corr)
{ {
degs_op(v, vweight, eweight, degs, g, degs_op(v, vweight, eweight, degs, g,
[&](auto kin, auto kout, auto n) [&](auto kin, auto kout, auto n)
{ {
int dk = diff * n; int dk = diff * n;
if (_ignore_degree[v] == 2)
kout = 0;
auto& h = _hist[r]; auto& h = _hist[r];
auto deg = make_pair(kin, kout); auto deg = make_pair(kin, kout);
auto iter = h.insert({deg, 0}).first; auto iter = h.insert({deg, 0}).first;
...@@ -608,10 +582,8 @@ public: ...@@ -608,10 +582,8 @@ public:
assert(_total[r] >= 0); assert(_total[r] >= 0);
if (deg_corr && _ignore_degree[v] != 1) if (deg_corr)
{ {
if (_ignore_degree[v] == 2)
kout = 0;
auto deg = make_pair(kin, kout); auto deg = make_pair(kin, kout);
auto iter = _hist[r].insert({deg, 0}).first; auto iter = _hist[r].insert({deg, 0}).first;
iter->second += diff * vweight; iter->second += diff * vweight;
...@@ -703,7 +675,6 @@ private: ...@@ -703,7 +675,6 @@ private:
vector<int> _total; vector<int> _total;
vector<int> _ep; vector<int> _ep;
vector<int> _em; vector<int> _em;
vector<uint8_t> _ignore_degree;
}; };
} //namespace graph_tool } //namespace graph_tool
......
...@@ -32,8 +32,7 @@ enum weight_type ...@@ -32,8 +32,7 @@ enum weight_type
REAL_NORMAL, REAL_NORMAL,
DISCRETE_GEOMETRIC, DISCRETE_GEOMETRIC,
DISCRETE_POISSON, DISCRETE_POISSON,
DISCRETE_BINOMIAL, DISCRETE_BINOMIAL
DELTA_T
}; };
// exponential // exponential
...@@ -194,14 +193,6 @@ std::tuple<double,double> rec_entropy(State& state, entropy_args_t& ea) ...@@ -194,14 +193,6 @@ std::tuple<double,double> rec_entropy(State& state, entropy_args_t& ea)
wp[3], state._epsilon[i]); wp[3], state._epsilon[i]);
} }
break; break;
case weight_type::DELTA_T: // waiting times
// for (auto r : vertices_range(state._bg))
// {
// if (state._bignore_degrees[r] > 0)
// S += -positive_w_log_P(state._mrp[r], state._brecsum[r], wp[0],
// wp[1], state._epsilon[i]);
// }
break;
} }
} }
return std::make_tuple(S, S_dl); return std::make_tuple(S, S_dl);
...@@ -429,30 +420,6 @@ std::tuple<double, double> rec_entries_dS(State& state, MEntries& m_entries, ...@@ -429,30 +420,6 @@ std::tuple<double, double> rec_entries_dS(State& state, MEntries& m_entries,
} }
} }
break; break;
case weight_type::DELTA_T: // waiting times
// auto r = m_entries.get_move().first;
// auto nr = m_entries.get_move().second;
// if (state._ignore_degrees[v] > 0)
// {
// auto dt = out_degreeS()(v, state._g, state._rec[i]);
// int k = out_degreeS()(v, state._g, state._eweight);
// dS -= -positive_w_log_P(state._mrp[r], state._brecsum[r],
// wp[0], wp[1],
// state._epsilon[i]);
// dS += -positive_w_log_P(state._mrp[r] - k,
// state._brecsum[r] - dt,
// wp[0], wp[1],
// state._epsilon[i]);
// dS -= -positive_w_log_P(state._mrp[nr], state._brecsum[nr],
// wp[0], wp[1],
// state._epsilon[i]);
// dS += -positive_w_log_P(state._mrp[nr] + k,
// state._brecsum[nr] + dt,
// wp[0], wp[1],
// state._epsilon[i]);
// }
break;
} }
} }
return std::make_tuple(dS, dS_dl); return std::make_tuple(dS, dS_dl);
......
...@@ -432,12 +432,6 @@ class BlockState(object): ...@@ -432,12 +432,6 @@ class BlockState(object):
self.use_hash = self.B > self.max_BE self.use_hash = self.B > self.max_BE
self.use_rmap = kwargs.pop("use_rmap", False) self.use_rmap = kwargs.pop("use_rmap", False)
self.ignore_degrees = kwargs.pop("ignore_degrees", None)
if self.ignore_degrees is None:
self.ignore_degrees = self.g.new_vp("bool", False)
else:
self.ignore_degrees = self.g.own_property(self.ignore_degrees).copy("bool")
self.merge_map = kwargs.pop("merge_map", self.merge_map = kwargs.pop("merge_map",
self.g.vertex_index.copy("int")) self.g.vertex_index.copy("int"))
self.merge_map = self.g.own_property(self.merge_map) self.merge_map = self.g.own_property(self.merge_map)
...@@ -512,24 +506,13 @@ class BlockState(object): ...@@ -512,24 +506,13 @@ class BlockState(object):
rt = libinference.rec_type.discrete_poisson rt = libinference.rec_type.discrete_poisson
elif rec_type == "discrete-binomial": elif rec_type == "discrete-binomial":
rt = libinference.rec_type.discrete_binomial rt = libinference.rec_type.discrete_binomial
elif rec_type == "delta_t":
rt = libinference.rec_type.delta_t
else: else:
rt = rec_type rt = rec_type
self.rec_types.append(rt) self.rec_types.append(rt)
self.brec = [self.bg.own_property(p) for p in self.bg.gp.rec] self.brec = [self.bg.own_property(p) for p in self.bg.gp.rec]
self.bdrec = [self.bg.own_property(p) for p in self.bg.gp.drec] self.bdrec = [self.bg.own_property(p) for p in self.bg.gp.drec]
self.brecsum = self.bg.new_vp("double")
if (len(self.rec_types) > 0 and
self.rec_types[0] == libinference.rec_type.delta_t): # waiting times
self.brecsum = self.bg.degree_property_map("out", self.brec)
mem = self.ignore_degrees.copy()
self.bignore_degrees = self.get_bclabel(clabel=mem).copy("bool")
self.brecsum.a[self.bignore_degrees.a == 0] = 0
else:
self.brecsum = self.bg.new_vp("double")
self.bignore_degrees = self.bg.new_vp("bool")
self.rec_params = rec_params = list(rec_params) self.rec_params = rec_params = list(rec_params)
while len(rec_params) < len(self.rec_types): while len(rec_params) < len(self.rec_types):
...@@ -575,9 +558,6 @@ class BlockState(object): ...@@ -575,9 +558,6 @@ class BlockState(object):
defaults = OrderedDict([("N", self.rec[i].fa.max()), defaults = OrderedDict([("N", self.rec[i].fa.max()),
("alpha", numpy.nan), ("alpha", numpy.nan),
("beta", numpy.nan)]) ("beta", numpy.nan)])
else: # delta_t
defaults = OrderedDict([("alpha", 1),
("beta", self.rec[i].fa.mean())])
ks = list(defaults.keys()) ks = list(defaults.keys())
if rec_params[i] != "microcanonical": if rec_params[i] != "microcanonical":
...@@ -648,8 +628,6 @@ class BlockState(object): ...@@ -648,8 +628,6 @@ class BlockState(object):
rec_types=kwargs.pop("rec_types", self.rec_types), rec_types=kwargs.pop("rec_types", self.rec_types),
rec_params=kwargs.pop("rec_params", rec_params=kwargs.pop("rec_params",
self.rec_params), self.rec_params),
ignore_degrees=kwargs.pop("ignore_degrees",
self.ignore_degrees),
allow_empty=kwargs.pop("allow_empty", allow_empty=kwargs.pop("allow_empty",
self.allow_empty), self.allow_empty),
Lrecdx=kwargs.pop("Lrecdx", self.Lrecdx.copy()), Lrecdx=kwargs.pop("Lrecdx", self.Lrecdx.copy()),
...@@ -701,7 +679,6 @@ class BlockState(object): ...@@ -701,7 +679,6 @@ class BlockState(object):
drec=self.drec, drec=self.drec,
rec_types=self.rec_types, rec_types=self.rec_types,
rec_params=self.rec_params, rec_params=self.rec_params,
ignore_degrees=self.ignore_degrees.copy("int"),
merge_map=self.merge_map) merge_map=self.merge_map)
return state return state
...@@ -816,8 +793,6 @@ class BlockState(object): ...@@ -816,8 +793,6 @@ class BlockState(object):
recs=recs, recs=recs,
drec=drec, drec=drec,
rec_params=rec_params, rec_params=rec_params,
ignore_degrees=kwargs.pop("ignore_degrees",
self.get_bclabel(clabel=self.ignore_degrees)),
clabel=kwargs.pop("clabel", self.get_bclabel()), clabel=kwargs.pop("clabel", self.get_bclabel()),
pclabel=kwargs.pop("pclabel", self.get_bpclabel()), pclabel=kwargs.pop("pclabel", self.get_bpclabel()),