Commit 95b6a10a authored by Tiago Peixoto's avatar Tiago Peixoto

Implement gamma parameter in absolute_trust()

parent c6897dcd
......@@ -29,7 +29,7 @@ using namespace boost;
using namespace graph_tool;
void absolute_trust(GraphInterface& g, int64_t source, boost::any c,
boost::any t, size_t n_paths, bool reversed)
boost::any t, double gamma, size_t n_paths, bool reversed)
{
if (!belongs<edge_floating_properties>()(c))
throw ValueException("edge property must be of floating point value type");
......@@ -37,9 +37,10 @@ void absolute_trust(GraphInterface& g, int64_t source, boost::any c,
throw ValueException("vertex property must be of floating point vector value type");
run_action<>()(g,
bind<void>(get_absolute_trust(), _1, g.GetVertexIndex(),
g.GetEdgeIndex(), g.GetMaxEdgeIndex(),
source, _2, _3, n_paths, reversed),
bind<void>(get_absolute_trust(source, gamma, n_paths,
reversed),
_1, g.GetVertexIndex(), g.GetEdgeIndex(),
g.GetMaxEdgeIndex(), _2, _3),
edge_floating_properties(),
vertex_floating_vector_properties())(c, t);
}
......
......@@ -56,11 +56,14 @@ struct path_cmp
struct get_absolute_trust
{
get_absolute_trust(int64_t source, double gamma, size_t n_paths,
bool reversed)
: source(source), gamma(gamma), n_paths(n_paths), reversed(reversed) {}
template <class Graph, class VertexIndex, class EdgeIndex, class TrustMap,
class InferredTrustMap>
void operator()(Graph& g, VertexIndex vertex_index, EdgeIndex edge_index,
size_t max_edge_index, int64_t source, TrustMap c,
InferredTrustMap t, size_t n_paths, bool reversed) const
size_t max_edge_index, TrustMap c, InferredTrustMap t) const
{
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef typename graph_traits<Graph>::edge_descriptor edge_t;
......@@ -152,9 +155,10 @@ struct get_absolute_trust
get<0>(np).second *= c[*e];
get<0>(np).first *= c[*e];
}
weight_sum[a] += get<0>(np).second;
t[v][vertex_index[a]] +=
get<0>(np).second*get<0>(np).first;
t_type w = pow(get<0>(np).second, gamma);
weight_sum[a] += w;
t[v][vertex_index[a]] += w * get<0>(np).first;
get<1>(np).insert(a);
get<2>(np).push_back(*e);
......@@ -186,6 +190,10 @@ struct get_absolute_trust
}
}
int64_t source;
double gamma;
size_t n_paths;
bool reversed;
};
}
......
......@@ -406,8 +406,8 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epslon=1e-6, max_iter=0,
else:
return vprop
def absolute_trust(g, trust_map, source = None, vprop=None, n_paths=10000,
reversed=False):
def absolute_trust(g, trust_map, source = None, vprop=None, gamma = 1.0,
n_paths=10000, reversed=False):
r"""
Calculate the absolute trust centrality of each vertex in the graph, from a
given source.
......@@ -530,7 +530,8 @@ def absolute_trust(g, trust_map, source = None, vprop=None, n_paths=10000,
libgraph_tool_centrality.\
get_absolute_trust(g._Graph__graph, source,
_prop("e", g, trust_map),
_prop("v", g, vprop), n_paths, reversed)
_prop("v", g, vprop), gamma, n_paths,
reversed)
finally:
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