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