Commit 58fe4de2 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Include min_inter parameter in absolute_trust()

parent 40fb818c
...@@ -32,8 +32,8 @@ using namespace boost; ...@@ -32,8 +32,8 @@ using namespace boost;
using namespace graph_tool; using namespace graph_tool;
void absolute_trust(GraphInterface& g, int64_t source, boost::any c, void absolute_trust(GraphInterface& g, int64_t source, boost::any c,
boost::any t, double epslon, size_t max_iter, bool reversed, boost::any t, double epslon, size_t min_iter,
size_t seed) size_t max_iter, bool reversed, size_t seed)
{ {
rng_t rng(static_cast<rng_t::result_type>(seed)); rng_t rng(static_cast<rng_t::result_type>(seed));
...@@ -42,13 +42,13 @@ void absolute_trust(GraphInterface& g, int64_t source, boost::any c, ...@@ -42,13 +42,13 @@ void absolute_trust(GraphInterface& g, int64_t source, boost::any c,
if (!belongs<vertex_floating_vector_properties>()(t)) if (!belongs<vertex_floating_vector_properties>()(t))
throw GraphException("vertex property must be of floating point vector value type"); throw GraphException("vertex property must be of floating point vector value type");
run_action<>() run_action<>()(g,
(g, bind<void> bind<void>(get_absolute_trust(), _1, g.GetVertexIndex(),
(get_absolute_trust(), source, _2, _3, epslon,
_1, g.GetVertexIndex(), source, _2, make_pair(min_iter, max_iter), reversed,
_3, epslon, max_iter, reversed, ref(rng)), ref(rng)),
edge_floating_properties(), edge_floating_properties(),
vertex_floating_vector_properties())(c,t); vertex_floating_vector_properties())(c, t);
} }
void export_absolute_trust() void export_absolute_trust()
......
...@@ -39,13 +39,16 @@ struct get_absolute_trust ...@@ -39,13 +39,16 @@ struct get_absolute_trust
class InferredTrustMap> class InferredTrustMap>
void operator()(Graph& g, VertexIndex vertex_index, int64_t source, void operator()(Graph& g, VertexIndex vertex_index, int64_t source,
TrustMap c, InferredTrustMap t, double epslon, TrustMap c, InferredTrustMap t, double epslon,
size_t max_iter, bool reversed, rng_t& rng) pair<size_t,size_t> iter_range, bool reversed,
const rng_t& rng) const
{ {
typedef typename property_traits<TrustMap>::value_type c_type; typedef typename property_traits<TrustMap>::value_type c_type;
typedef typename property_traits<InferredTrustMap>::value_type typedef typename property_traits<InferredTrustMap>::value_type
::value_type t_type; ::value_type t_type;
size_t min_iter = iter_range.first;
size_t max_iter = iter_range.second;
unchecked_vector_property_map<vector<t_type>, VertexIndex> unchecked_vector_property_map<vector<t_type>, VertexIndex>
t_count(vertex_index, num_vertices(g)); t_count(vertex_index, num_vertices(g));
unchecked_vector_property_map<vector<size_t>, VertexIndex> unchecked_vector_property_map<vector<size_t>, VertexIndex>
...@@ -76,9 +79,9 @@ struct get_absolute_trust ...@@ -76,9 +79,9 @@ struct get_absolute_trust
random_salt(0, numeric_limits<size_t>::max()); random_salt(0, numeric_limits<size_t>::max());
size_t salt = random_salt(rng); size_t salt = random_salt(rng);
t_type delta = 2*epslon; t_type delta = epslon + 1;
size_t iter = 0; size_t iter = 0;
while (delta >= epslon || iter < 10) while (delta > epslon || iter < min_iter)
{ {
delta = 0; delta = 0;
typename graph_traits<Graph>::vertex_descriptor v = typename graph_traits<Graph>::vertex_descriptor v =
......
...@@ -391,7 +391,8 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epslon=1e-6, max_iter=0, ...@@ -391,7 +391,8 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epslon=1e-6, max_iter=0,
return vprop return vprop
def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001, def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001,
max_iter=None, reversed=False, seed=None, ret_iter=False): min_iter=100, max_iter=None, reversed=False, seed=None,
ret_iter=False):
r""" r"""
Samples the absolute trust centrality of each vertex in the graph, or only Samples the absolute trust centrality of each vertex in the graph, or only
for a given source, if one is provided. for a given source, if one is provided.
...@@ -411,8 +412,12 @@ def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001, ...@@ -411,8 +412,12 @@ def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001,
epslon : float, optional (default: 0.001) epslon : float, optional (default: 0.001)
Convergence condition. The iteration will stop if the total delta of all Convergence condition. The iteration will stop if the total delta of all
vertices are below this value. vertices are below this value.
min_iter : int, optional (default: 100)
If supplied, this will limit the minimal number of iterations (per
source vertex).
max_iter : int, optional (default: None) max_iter : int, optional (default: None)
If supplied, this will limit the total number of iterations. If supplied, this will limit the total number of iterations (per
source vertex).
reversed : bool, optional (default: False) reversed : bool, optional (default: False)
Calculates the "reversed" trust instead: The direction of the edges are Calculates the "reversed" trust instead: The direction of the edges are
inverted, but the path weighting is preserved in the original direction inverted, but the path weighting is preserved in the original direction
...@@ -515,7 +520,7 @@ def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001, ...@@ -515,7 +520,7 @@ def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001,
ic = libgraph_tool_centrality.\ ic = libgraph_tool_centrality.\
get_absolute_trust(g._Graph__graph, source, get_absolute_trust(g._Graph__graph, source,
_prop("e", g, trust_map), _prop("v", g, vprop), _prop("e", g, trust_map), _prop("v", g, vprop),
epslon, max_iter, reversed, seed) epslon, min_iter, max_iter, reversed, seed)
if reversed: if reversed:
g.pop_filter(reversed=True) g.pop_filter(reversed=True)
......
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