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

Implement gamma parameter in absolute_trust()

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