Commit beefde29 authored by Tiago Peixoto's avatar Tiago Peixoto

blockmodel: Use static neighbour sampler if weighted

parent d84dd658
......@@ -1670,7 +1670,7 @@ public:
EGroups<g_t, is_weighted_t> _egroups;
typedef NeighbourSampler<g_t, is_weighted_t, std::true_type>
typedef NeighbourSampler<g_t, is_weighted_t, boost::mpl::false_>
neighbour_sampler_t;
neighbour_sampler_t _neighbour_sampler;
......
......@@ -1375,7 +1375,7 @@ public:
}
template <class Edge>
bool is_valid(size_t, vector<Edge>& elist)
bool is_valid(size_t, vector<Edge>&)
{
return true;
}
......
......@@ -39,6 +39,14 @@ public:
: _sampler(get(vertex_index_t(), g), num_vertices(g)),
_sampler_pos(get(vertex_index_t(), g), num_vertices(g)),
_eindex(get(edge_index_t(), g))
{
init(g, eweight, self_loops,
typename boost::mpl::and_<Weighted,
typename boost::mpl::not_<Dynamic>::type>::type());
}
template <class Eprop>
void init(Graph& g, Eprop& eweight, bool self_loops, boost::mpl::false_)
{
for (auto e : edges_range(g))
{
......@@ -65,6 +73,44 @@ public:
}
}
template <class Eprop>
void init(Graph& g, Eprop& eweight, bool self_loops, boost::mpl::true_)
{
for (auto v : vertices_range(g))
{
std::vector<item_t> us;
std::vector<double> probs;
for (auto e : out_edges_range(v, g))
{
auto u = target(e, g);
double w = eweight[e];
if (w == 0)
continue;
if (u == v)
{
if (!self_loops)
continue;
if (!is_directed::apply<Graph>::type::value)
w /= 2;
}
us.emplace_back(u, 0);
probs.push_back(w);
}
for (auto e : in_edges_range(v, g))
{
auto u = source(e, g);
double w = eweight[e];
if (w == 0 || u == v)
continue;
us.emplace_back(u, 0);
probs.push_back(w);
}
_sampler[v] = sampler_t(us, probs);
}
}
template <class RNG>
vertex_t sample(vertex_t v, RNG& rng)
{
......@@ -142,8 +188,8 @@ private:
sampler.push_back(u);
}
template <class Sampler, class Weight>
void insert_item(item_t& u, Weight w, Sampler& sampler,
template <class Weight>
void insert_item(item_t& u, Weight w, DynamicSampler<item_t>& sampler,
pos_map_t& sampler_pos)
{
assert(sampler_pos.find(u) == sampler_pos.end());
......@@ -153,7 +199,8 @@ private:
typedef typename std::conditional<Weighted::value,
typename std::conditional<Dynamic::value,
DynamicSampler<item_t>,
Sampler<item_t>>::type,
Sampler<item_t,
boost::mpl::false_>>::type,
vector<item_t>>::type
sampler_t;
......
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