Commit e0bd13c1 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Revert and modify path weighting strategy in absolute_trust()

parent 95b6a10a
...@@ -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, double gamma, size_t n_paths, bool reversed) boost::any t, 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,10 +37,9 @@ void absolute_trust(GraphInterface& g, int64_t source, boost::any c, ...@@ -37,10 +37,9 @@ 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(source, gamma, n_paths, bind<void>(get_absolute_trust(), _1, g.GetVertexIndex(),
reversed), g.GetEdgeIndex(), g.GetMaxEdgeIndex(),
_1, g.GetVertexIndex(), g.GetEdgeIndex(), source, _2, _3, n_paths, reversed),
g.GetMaxEdgeIndex(), _2, _3),
edge_floating_properties(), edge_floating_properties(),
vertex_floating_vector_properties())(c, t); vertex_floating_vector_properties())(c, t);
} }
......
...@@ -56,14 +56,11 @@ struct path_cmp ...@@ -56,14 +56,11 @@ 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, TrustMap c, InferredTrustMap t) const size_t max_edge_index, int64_t source, TrustMap c,
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;
...@@ -92,12 +89,14 @@ struct get_absolute_trust ...@@ -92,12 +89,14 @@ struct get_absolute_trust
get<1>(paths.back()).insert(v); get<1>(paths.back()).insert(v);
queue.push(0); queue.push(0);
// this is the queue with paths with maximum weights // this is the actual queue of paths which will be used to compute
// the trust values
queue_t final_queue = queue_t(path_cmp<path_t>(paths)); queue_t final_queue = queue_t(path_cmp<path_t>(paths));
// sum of weights that lead to a given vertex // store all paths which reach a given vertex
unchecked_vector_property_map<t_type, VertexIndex> unchecked_vector_property_map<tr1::unordered_set<size_t>,
weight_sum(vertex_index, num_vertices(g)); VertexIndex>
path_map(vertex_index, num_vertices(g));
while (!queue.empty()) while (!queue.empty())
{ {
...@@ -110,6 +109,9 @@ struct get_absolute_trust ...@@ -110,6 +109,9 @@ struct get_absolute_trust
{ {
w = target(get<2>(paths[pi]).back(), g); w = target(get<2>(paths[pi]).back(), g);
final_queue.push(pi); final_queue.push(pi);
// augment path map
path_map[target(get<2>(paths[pi]).back(),g)].insert(pi);
} }
else else
{ {
...@@ -122,7 +124,10 @@ struct get_absolute_trust ...@@ -122,7 +124,10 @@ struct get_absolute_trust
size_t bi = final_queue.bottom(); size_t bi = final_queue.bottom();
final_queue.pop_bottom(); final_queue.pop_bottom();
// do not augment if the path is the removed bottom // remove path from path map
path_map[boost::target(get<2>(paths[bi]).back(),g)].
erase(bi);
if (bi == pi) if (bi == pi)
continue; continue;
} }
...@@ -135,44 +140,152 @@ struct get_absolute_trust ...@@ -135,44 +140,152 @@ struct get_absolute_trust
// no loops // no loops
if (get<1>(paths[pi]).find(a) == get<1>(paths[pi]).end()) if (get<1>(paths[pi]).find(a) == get<1>(paths[pi]).end())
{ {
size_t npi; // only follow non-zero paths
paths.push_back(paths[pi]); // clone last path if (c[*e] > 0 || (reversed &&
npi = paths.size()-1; get<1>(paths[pi]).size() == 1))
{
size_t npi;
paths.push_back(paths[pi]); // clone last path
npi = paths.size()-1;
path_t& np = paths[npi]; // new path path_t& np = paths[npi]; // new path
if (!reversed) if (!reversed)
{ {
// path weight // path weight
get<0>(np).second = get<0>(np).first; get<0>(np).second = get<0>(np).first;
// path value
get<0>(np).first *= c[*e];
}
else
{
if (get<1>(np).size() > 1)
get<0>(np).second *= c[*e];
get<0>(np).first *= c[*e];
}
get<1>(np).insert(a);
get<2>(np).push_back(*e);
// path value // keep following paths only if there is a chance
get<0>(np).first *= c[*e]; // they will make it into the final queue
if ((n_paths > 0 && final_queue.size() < n_paths) ||
(final_queue.size() == 0 ||
(get<0>(np).second >=
get<0>(paths[final_queue.bottom()]).second)))
queue.push(npi);
else
paths.pop_back();
} }
else }
}
}
unchecked_vector_property_map<t_type, VertexIndex>
weight_sum(vertex_index, num_vertices(g));
// paths which were already calculated and can be skipped
tr1::unordered_set<size_t> skip;
// calculate trust from paths in the final queue
while (!final_queue.empty())
{
size_t pi = final_queue.top();
final_queue.pop_top();
path_t& p = paths[pi];
if (skip.find(pi) != skip.end())
continue;
tr1::unordered_set<size_t>& apaths =
path_map[target(get<2>(p).back(), g)]; // all paths with the
// same final target
tr1::unordered_set<size_t> vlist; // all vertices involved
// compute cumulative edge weight
unchecked_vector_property_map
<tr1::unordered_map<vertex_t, t_type>, EdgeIndex>
cum_weight(edge_index, max_edge_index+1);
for (typeof(apaths.begin()) iter = apaths.begin();
iter != apaths.end(); ++iter)
{
size_t path_size = get<2>(paths[*iter]).size();
vertex_t ptarget = target(get<2>(paths[*iter]).back(),g);
t_type w = 1;
for (size_t j = 0; j < path_size; ++j)
{
edge_t e = get<2>(paths[*iter])[path_size - 1 - j];
if (!reversed && j < path_size - 1)
w *= c[e];
if (reversed && j > 0)
w *= c[e];
cum_weight[e][ptarget] += w;
vlist.insert(target(e,g));
}
vlist.insert(boost::source(get<2>(paths[*iter]).front(),g));
}
// compute out-weight
unchecked_vector_property_map
<tr1::unordered_map<vertex_t, t_type>, VertexIndex>
out_weight(vertex_index, num_vertices(g));
for (typeof(vlist.begin()) viter = vlist.begin();
viter != vlist.end(); ++viter)
{
vertex_t u = *viter;
if (!reversed)
{
typename graph_traits<Graph>::out_edge_iterator e,e_end;
for (tie(e, e_end) = out_edges(u, g); e != e_end; ++e)
for (typeof(cum_weight[*e].begin()) witer =
cum_weight[*e].begin();
witer != cum_weight[*e].end(); ++witer)
out_weight[u][witer->first] += witer->second;
}
else
{
// if reversed, use "in-trust" instead
typename in_edge_iteratorS<Graph>::type e, e_end;
for (tie(e, e_end) =
in_edge_iteratorS<Graph>::get_edges(v, g);
e != e_end; ++e)
for (typeof(cum_weight[*e].begin()) witer =
cum_weight[*e].begin();
witer != cum_weight[*e].end(); ++witer)
out_weight[u][witer->first] += witer->second;
}
}
for (typeof(apaths.begin()) iter = apaths.begin();
iter != apaths.end(); ++iter)
{
size_t pi = *iter;
path_t& p = paths[pi];
vertex_t ptarget = target(get<2>(paths[*iter]).back(),g);
// calculate the trust value and weight of the path
t_type w = 1, val = 1;
for (size_t i = 0; i < get<2>(p).size(); ++i)
{
edge_t e = get<2>(p)[i];
vertex_t u = (!reversed) ?
boost::source(e,g) : target(e,g);
if (out_weight[u][ptarget] > 0)
{ {
if (get<1>(np).size() > 1) if ((!reversed && i < get<2>(p).size()-1) ||
get<0>(np).second *= c[*e]; (reversed && i > 0))
get<0>(np).first *= c[*e]; w *= c[e]*cum_weight[e][ptarget]/
out_weight[u][ptarget];
} }
val *= c[e];
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);
// keep following paths only if there is a chance
// they will make it into the final queue
if ((n_paths > 0 && final_queue.size() < n_paths) ||
(final_queue.size() == 0 ||
(get<0>(np).second >=
get<0>(paths[final_queue.bottom()]).second)))
queue.push(npi);
else
paths.pop_back();
} }
vertex_t u = target(get<2>(p).back(), g);
weight_sum[u] += w;
t[v][u] += w*val;
skip.insert(pi);
} }
} }
...@@ -190,10 +303,6 @@ struct get_absolute_trust ...@@ -190,10 +303,6 @@ struct get_absolute_trust
} }
} }
int64_t source;
double gamma;
size_t n_paths;
bool reversed;
}; };
} }
......
...@@ -105,23 +105,23 @@ def pagerank(g, damping=0.8, prop=None, epslon=1e-6, max_iter=None, ...@@ -105,23 +105,23 @@ def pagerank(g, damping=0.8, prop=None, epslon=1e-6, max_iter=None,
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3))) >>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> pr = gt.pagerank(g) >>> pr = gt.pagerank(g)
>>> print pr.get_array() >>> print pr.get_array()
[ 0.89482844 1.37847566 0.24 1.30716676 0.2 0.70397009 [ 0.99988081 0.39997616 0.80428057 0.43237369 0.2 0.75830329
0.40205781 0.74783725 1.37167015 0.66836587 0.5868133 0.47968714 0.41447482 1.56621542 0.30841665 0.86432715 0.79374139 0.54573086
1.52225854 1.07388611 0.76316432 0.39214247 0.9302883 0.86455762 0.89372179 0.93590145 0.25159724 1.12033843 0.2 0.98486039
0.77546264 1.87740317 0.25482139 0.29902553 0.2 0.24756383 0.28191404 0.88133806 0.31166878 1.73878838 0.6903469 0.94100349
0.97205301 0.29727392 1.34742309 0.30905457 0.55032542 0.56654712 0.25159724 0.32248278 1.03788472 0.58022932 0.35009064 0.94542317
0.40895463 0.77928729 0.73227413 0.59911926 1.39946277 0.72793699 0.85751934 0.69608227 1.11373543 1.13477707 0.2 0.71559888
2.27008393 0.88929335 0.48636962 0.73070609 0.2 0.232 0.30461189 0.2 1.02871995 1.14657561 0.2 0.25031945
0.96857512 2.97683022 0.58581032 0.80217847 0.37896569 0.93866821 0.51841423 0.44709022 0.75239816 0.76551737 0.25638281 1.51657252
0.27337672 0.98201842 0.48551839 1.22651796 0.73263045 0.43013228 0.30841665 0.59707408 0.34179258 1.0590272 2.16427996 0.51196274
1.00971133 0.72075953 0.66715456 0.58705749 0.74286661 0.37785867 1.2264604 1.71578696 0.85838961 0.41931136 0.96797602 0.61882367
1.8475279 0.26432925 0.33994628 0.97319326 0.78104447 0.2 1.07826603 0.2984934 1.1305187 0.75006564 0.48066231 1.61759314
0.33333761 0.51756267 0.47811583 0.85905246 1.46428623 0.2 0.73870051 1.08374044 0.38258693 0.98112013 0.2 0.25590818
1.70687671 1.0107342 0.94504737 1.29858046 2.19707395 0.55931282 1.17500568 1.2288973 0.29613246 1.45937444 0.39997616 1.18311783
0.85129509 1.09493368 1.22168331 0.64108136 0.70690188 0.2 0.67063807 0.39229458 0.72314004 0.88473325 0.32859279 0.40656244
0.31736266 0.42372513 0.79429328 1.44749664 1.20741669 0.65763236 0.51754349 0.5315028 0.55196274 0.2335463 1.56357203 0.91464458
0.40895463 0.62628812 0.32671006 0.85626447 0.59925496 0.3399879 0.46999727 1.06779933 0.4852867 0.48933035 0.58997931 0.52883683
0.81215046 0.71506902 2.25678844 1.04882679] 0.79385874 0.59244805 0.99896399 1.0470592 ]
References References
---------- ----------
...@@ -202,23 +202,23 @@ def betweenness(g, vprop=None, eprop=None, weight=None, norm=True): ...@@ -202,23 +202,23 @@ def betweenness(g, vprop=None, eprop=None, weight=None, norm=True):
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3))) >>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> vb, eb = gt.betweenness(g) >>> vb, eb = gt.betweenness(g)
>>> print vb.get_array() >>> print vb.get_array()
[ 0.03047981 0.07396685 0.00270882 0.044637 0. 0.03259048 [ 0.06129648 0.02004734 0.04305659 0.01071136 0. 0.0252028
0.0243547 0.04265909 0.06274696 0.01778475 0.03502657 0.02692273 0.00679622 0.06981881 0.00541371 0.02462107 0.05328111 0.0107051
0.05170277 0.05522454 0.02303023 0.0038858 0. 0.04852871 0.05981227 0. 0.01315561 0.00131498 0. 0.01883264
0.02398655 0.00232365 0. 0.01064643 0. 0.01105872 0.01663386 0.03195175 0.01942617 0.13693745 0.01378875 0.00962001
0.03564021 0.0222059 0.05170383 0.00140447 0.03935299 0.02644813 0.01325009 0.04685362 0.03839758 0.03395201 0.02160984 0.01727593
0.01831885 0. 0.0453981 0.04552396 0.1242787 0.04983878 0.0478231 0. 0.03826993 0.05124999 0. 0.
0.07248363 0.04676976 0.03481327 0.04473583 0. 0.0027417 0.00705917 0. 0.02190356 0.04505211 0. 0.00676419
0.01061048 0.0470108 0.01059109 0.05290495 0. 0.02541583 0.00110802 0.00169839 0.08733666 0.10546473 0. 0.12058932
0. 0.04012033 0.02616307 0.09056515 0.01640322 0.01599007 0. 0.00907921 0.02182859 0.08865455 0. 0.0418017
0.02784563 0.05008998 0.03788222 0.03028745 0.01097982 0.00178571 0.03500162 0.07492683 0.03856307 0.04300598 0.02173347 0.00488363
0.05804645 0.01015181 0.0061582 0.0255485 0.05504439 0. 0.03739852 0.01113193 0.04386369 0.02994719 0.03383728 0.
0.00179516 0.03367643 0.00304982 0.02333254 0.00843039 0. 0.09230395 0.05449223 0.02507715 0.04944675 0. 0.00215935
0.05947385 0.01936996 0.0521946 0.04928937 0.03955121 0.01360865 0.04371057 0.01749238 0.00104315 0.04688928 0.00444627 0.0178016
0.02942447 0. 0.05149102 0.01054765 0. 0. 0.01358585 0.02193068 0.03184527 0.05640358 0.00214389 0.03922583
0.00537915 0.01251828 0.01097982 0.06667564 0.04090169 0.02161779 0.02195544 0.02613584 0.02246488 0.00066481 0.0755375 0.03142692
0.02941671 0.01793679 0.02360528 0.02638257 0.0062989 0.00946123 0.04533332 0.03188087 0.04227853 0.03926328 0.00810412 0.02888085
0. 0.02255701 0.05081734 0.04846652] 0.0455241 0.01373183 0.07029039 0.04382892]
References References
---------- ----------
...@@ -283,7 +283,7 @@ def central_point_dominance(g, betweenness): ...@@ -283,7 +283,7 @@ def central_point_dominance(g, betweenness):
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3))) >>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> vb, eb = gt.betweenness(g) >>> vb, eb = gt.betweenness(g)
>>> print gt.central_point_dominance(g, vb) >>> print gt.central_point_dominance(g, vb)
0.0980212339559 0.108411171667
References References
---------- ----------
...@@ -359,31 +359,31 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epslon=1e-6, max_iter=0, ...@@ -359,31 +359,31 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epslon=1e-6, max_iter=0,
>>> trust.get_array()[:] = random(g.num_edges())*42 >>> trust.get_array()[:] = random(g.num_edges())*42
>>> t = gt.eigentrust(g, trust, norm=True) >>> t = gt.eigentrust(g, trust, norm=True)
>>> print t.get_array() >>> print t.get_array()
[ 1.04935746e-02 2.82745068e-02 0.00000000e+00 1.81121002e-02 [ 1.78295032e-02 1.10159977e-03 8.27504534e-03 3.34579667e-03
0.00000000e+00 3.70898521e-03 1.00108703e-03 1.29620638e-02 0.00000000e+00 9.28795883e-03 7.56225537e-03 2.03772288e-02
1.71874047e-02 7.07523828e-03 8.29873222e-03 1.79259666e-03 6.87447577e-04 8.87085111e-03 2.84707349e-03 2.55095571e-03
4.08925756e-02 1.55855653e-02 2.92256968e-03 1.71520782e-03 7.65302351e-03 5.06044724e-02 3.98617107e-04 1.02897822e-02
5.04335865e-03 1.25678184e-02 1.92903241e-02 2.46642649e-02 0.00000000e+00 6.76980749e-03 6.91342330e-04 1.13998018e-02
1.76431290e-04 1.85066489e-04 0.00000000e+00 4.52686439e-04 1.91846222e-03 3.74940757e-02 8.65907932e-03 5.76596060e-03
7.13943855e-03 2.36002975e-03 1.44366165e-02 4.39632543e-04 1.11786939e-05 8.20855949e-04 9.45056085e-03 1.76099276e-02
7.50316671e-03 8.13521884e-03 3.98083843e-03 1.04883920e-02 2.67746802e-03 1.03182164e-02 1.80748361e-02 8.49781556e-03
7.42099689e-03 2.46651355e-03 2.08148781e-02 8.02104873e-03 7.89442825e-03 1.11838761e-02 0.00000000e+00 4.37095317e-03
2.59366573e-02 2.11125347e-02 7.45781416e-03 6.62338254e-03 2.50451228e-05 0.00000000e+00 6.04054677e-03 1.51361293e-02
0.00000000e+00 0.00000000e+00 1.72521147e-02 4.74346499e-02 0.00000000e+00 1.62557422e-04 1.02859153e-03 3.38079641e-03
8.10593668e-03 2.27229702e-02 2.21525586e-03 6.24223052e-03 3.06115271e-03 2.96226918e-03 7.40021010e-05 1.64096932e-02
2.59753300e-03 9.15181124e-03 3.67310718e-03 1.18998211e-02 1.12026631e-03 3.33521569e-03 1.77214999e-03 6.62472745e-03
1.66177496e-02 6.44748287e-03 8.01978992e-03 1.48621102e-02 3.17014482e-02 1.93793538e-03 5.24056364e-02 4.04200200e-02
6.65606246e-03 3.39887550e-03 1.20188240e-02 3.51012614e-03 2.96053927e-02 2.06294202e-03 2.93045979e-02 1.87688605e-03
2.79661104e-02 7.90103914e-05 1.18015521e-03 8.17179744e-03 1.13962350e-02 6.94033709e-03 1.57347756e-02 3.97987237e-03
1.05694658e-02 0.00000000e+00 4.49123443e-04 9.80728243e-04 1.15994824e-03 1.81252731e-02 2.06848985e-02 3.73314296e-03
2.70933271e-03 1.61865322e-02 2.13504124e-02 0.00000000e+00 1.27163202e-03 1.08081901e-02 0.00000000e+00 2.25590063e-04
1.17773123e-02 4.63490203e-03 1.79331966e-02 1.46366115e-02 8.55970439e-03 4.15387826e-02 8.61792076e-05 6.48435253e-02
3.26856602e-02 4.31126006e-03 1.68787878e-02 2.02752156e-02 5.61799591e-03 4.69096686e-02 4.24627753e-03 9.16721227e-04
1.48203062e-02 1.17346898e-03 7.87933309e-03 0.00000000e+00 4.86522362e-03 4.42735866e-03 5.50595265e-04 3.12087221e-03
1.13274458e-03 2.25418313e-03 1.27966643e-02 2.46154526e-02 8.75442087e-03 4.25588041e-03 2.91851609e-03 1.80331544e-06
7.15248968e-03 8.35660945e-03 3.88259360e-03 5.95428313e-03 2.89281502e-02 1.75099401e-02 1.14704807e-02 3.30940821e-02
1.16751480e-04 5.78637193e-03 6.50575506e-03 1.47111816e-03 2.84005465e-03 4.92435108e-03 4.34713976e-03 2.72336599e-03
1.22855215e-02 1.34294277e-02 4.03141738e-02 2.77313687e-02] 9.37679329e-03 8.64912360e-03 3.96113432e-03 1.07637051e-02]
References References
---------- ----------
...@@ -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, gamma = 1.0, def absolute_trust(g, trust_map, source = None, vprop=None, n_paths=10000,
n_paths=10000, reversed=False): 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.
...@@ -426,8 +426,7 @@ def absolute_trust(g, trust_map, source = None, vprop=None, gamma = 1.0, ...@@ -426,8 +426,7 @@ def absolute_trust(g, trust_map, source = None, vprop=None, gamma = 1.0,
Vector vertex property map where the values of trust for each source Vector vertex property map where the values of trust for each source
must be stored. must be stored.
n_paths : int, optimal (default: 10000) n_paths : int, optimal (default: 10000)
Number of paths (per source vertex) with largest weights to Maximum number of paths to consider.
consider. When all these paths have been found, the algorithm stops.
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
...@@ -465,11 +464,13 @@ def absolute_trust(g, trust_map, source = None, vprop=None, gamma = 1.0, ...@@ -465,11 +464,13 @@ def absolute_trust(g, trust_map, source = None, vprop=None, gamma = 1.0,
.. math:: .. math::
w_{\{i\to j\}} = \prod_{e\in \{i\to j\}}\{c_e(1-\delta_{t(e),j}) + w_{\{i\to j\}} = \prod_{e\in \{i\to j\}}\frac{c_e}{\Gamma^+_{\{i\to j\}}(s(e))}
\delta_{t(e),j}\}, \{c_e(1-\delta_{t(e),j}) + \delta_{t(e),j}},
such that the direct trust of the last edge on the path is not such that the direct trust of the last edge on the path is not
considered. considered. The value :math:`\Gamma^+_{\{i\to j\}}(s(e))` is the sum of
trust values of the selected out-edges of vertex :math:`s(e)`, which also
belong to the set of edge-disjoint of paths from i to j.
The algorithm measures the absolute trust by following all vertex-disjoint The algorithm measures the absolute trust by following all vertex-disjoint
paths, and keeping them on a priority queue. Each iteration the path with paths, and keeping them on a priority queue. Each iteration the path with
...@@ -488,23 +489,32 @@ def absolute_trust(g, trust_map, source = None, vprop=None, gamma = 1.0, ...@@ -488,23 +489,32 @@ def absolute_trust(g, trust_map, source = None, vprop=None, gamma = 1.0,
>>> trust.get_array()[:] = random(g.num_edges()) >>> trust.get_array()[:] = random(g.num_edges())
>>> t = gt.absolute_trust(g, trust, source=g.vertex(0)) >>> t = gt.absolute_trust(g, trust, source=g.vertex(0))
>>> print t.a >>> print t.a
[ 0. 0.02313155 0. 0.0137347 0. 0.01102793 [ 0.00000000e+00 5.14258135e-02 2.42874582e-04 1.05347472e-06
0.01128784 0.04625048 0.03853915 0.01845147 0.04615215 0.0029449 0.00000000e+00 3.13429149e-04 1.53697222e-04 3.83063399e-05
0.00694276 0.18236335 0.00217966 0.00339272 0.00850374 0.01893049 2.65668937e-06 2.04029901e-05 1.19582153e-05 2.67743821e-06
0.03348913 0.01321992 0.00080411 0.04414003 0. 0.13552437 1.50606560e-04 1.51595650e-05 5.72684475e-05 2.16466381e-06
0.00941916 0.19501805 0.02914234 0.01086888 0.03168659 0.00628033 0.00000000e+00 4.08340061e-05 3.26896572e-06 7.80860267e-05
0.05111872 0.06860108 0.01768409 0.01173521 0.0298894 0.02298583 7.31033290e-05 7.81690832e-05 2.93440658e-04 1.19013202e-05
0.03934682 0.06823432 0.19336846 0.02223112 0. 0. 0.0286787 1.60601849e-06 6.79167712e-05 9.35414301e-05 1.98991248e-05
0.01942249 0.03179068 0.00325739 0.34593499 0.00958355 0.02272858 2.08142130e-05 1.28565785e-04 2.83893891e-03 8.45362053e-05
0.01339147 0.02373504 0.0395046 0.02559305 0.06796198 0.0190701 1.15751883e-05 1.97248846e-05 0.00000000e+00 7.51004486e-06
0.59591656 0.01690353 0.03425196 0.04172327 0.04237095 0.03286538 5.49704676e-07 0.00000000e+00 1.06219388e-04 9.64852468e-04
0.00342536 0.01641873 0.02524374 0.02455111 0. 0.01524952 0.00000000e+00 4.70496027e-05 5.49108602e-05 6.23617670e-06
0.00146199 0.11204837 0.03967154 0.01779094 0. 0.0111206 1.32625806e-06 7.35202433e-05 2.09546902e-06 1.99138155e-03
0.00494046 0.03037591 0.0248954 0.02045298 0.02783211 0.04825638 4.32934771e-06 2.61887887e-05 2.55099939e-05 3.90874553e-06
0.01445001 0.01134507 0.00710798 0.02194733 0. 0.02747093 9.07765143e-05 2.59243068e-06 7.50032403e-06 8.36211398e-05
0.02335361 0.00816605 0.01416937 0.01496241 0.00783877 0.05209053 7.80814352e-04 8.12133072e-06 6.24066931e-04 2.19465770e-06
0.02135097 0.00102158 0.01213873 0.11390882 0.03516289 0.01956201 4.15039190e-05 5.41464668e-05 1.84421073e-03 8.02449156e-06
0.02973489 0.01396339 0.02814348] 4.01472852e-06 3.76746767e-01 7.02886863e-05 1.52365123e-04
4.58687938e-06 3.70470973e-02 0.00000000e+00 1.85922960e-06
2.05481272e-05 1.41021895e-04 1.45217040e-06 3.18562543e-06
2.62264044e-01 7.41140347e-06 1.39150089e-05 3.86583428e-06
2.85681164e-06 4.12923146e-06 7.05705402e-07 2.12584322e-05
1.65948868e-04 3.10144404e-05 5.08749580e-06 0.00000000e+00
1.45435603e-03 4.19224443e-03 4.88198531e-05 3.00152848e-04
5.61591759e-05 2.31951396e-04 1.19051653e-05 2.34710286e-05
6.27636571e-04 1.65759606e-02 1.30944429e-05 1.26282526e-05]
""" """
if vprop == None: if vprop == None:
...@@ -530,8 +540,7 @@ def absolute_trust(g, trust_map, source = None, vprop=None, gamma = 1.0, ...@@ -530,8 +540,7 @@ def absolute_trust(g, trust_map, source = None, vprop=None, gamma = 1.0,
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), gamma, n_paths, _prop("v", g, vprop), n_paths, reversed)
reversed)
finally: