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;
using namespace graph_tool;
void absolute_trust(GraphInterface& g, int64_t source, boost::any c,
boost::any t, double epslon, size_t max_iter, bool reversed,
size_t seed)
boost::any t, double epslon, size_t min_iter,
size_t max_iter, bool reversed, size_t 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,
if (!belongs<vertex_floating_vector_properties>()(t))
throw GraphException("vertex property must be of floating point vector value type");
run_action<>()
(g, bind<void>
(get_absolute_trust(),
_1, g.GetVertexIndex(), source, _2,
_3, epslon, max_iter, reversed, ref(rng)),
edge_floating_properties(),
vertex_floating_vector_properties())(c,t);
run_action<>()(g,
bind<void>(get_absolute_trust(), _1, g.GetVertexIndex(),
source, _2, _3, epslon,
make_pair(min_iter, max_iter), reversed,
ref(rng)),
edge_floating_properties(),
vertex_floating_vector_properties())(c, t);
}
void export_absolute_trust()
......
......@@ -39,13 +39,16 @@ struct get_absolute_trust
class InferredTrustMap>
void operator()(Graph& g, VertexIndex vertex_index, int64_t source,
TrustMap c, InferredTrustMap t, double epslon,
size_t max_iter, bool reversed, rng_t& rng)
const
pair<size_t,size_t> iter_range, bool reversed,
rng_t& rng) const
{
typedef typename property_traits<TrustMap>::value_type c_type;
typedef typename property_traits<InferredTrustMap>::value_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>
t_count(vertex_index, num_vertices(g));
unchecked_vector_property_map<vector<size_t>, VertexIndex>
......@@ -76,9 +79,9 @@ struct get_absolute_trust
random_salt(0, numeric_limits<size_t>::max());
size_t salt = random_salt(rng);
t_type delta = 2*epslon;
t_type delta = epslon + 1;
size_t iter = 0;
while (delta >= epslon || iter < 10)
while (delta > epslon || iter < min_iter)
{
delta = 0;
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,
return vprop
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"""
Samples the absolute trust centrality of each vertex in the graph, or only
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,
epslon : float, optional (default: 0.001)
Convergence condition. The iteration will stop if the total delta of all
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)
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)
Calculates the "reversed" trust instead: The direction of the edges are
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,
ic = libgraph_tool_centrality.\
get_absolute_trust(g._Graph__graph, source,
_prop("e", g, trust_map), _prop("v", g, vprop),
epslon, max_iter, reversed, seed)
epslon, min_iter, max_iter, reversed, seed)
if reversed:
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