Commit 07a2d099 authored by Tiago Peixoto's avatar Tiago Peixoto

Docstrings and small fixes in centrality algorithms

This fully documents the centrality module.
parent 95405617
......@@ -28,21 +28,24 @@ using namespace std;
using namespace boost;
using namespace graph_tool;
void eigentrust(GraphInterface& g, boost::any c, boost::any t,
double epslon, size_t max_iter)
size_t eigentrust(GraphInterface& g, boost::any c, boost::any t,
double epslon, size_t max_iter)
{
if (!belongs<writable_edge_scalar_properties>()(c))
throw GraphException("edge property must be writable");
if (!belongs<vertex_floating_vector_properties>()(t))
throw GraphException("vertex property must be of floating point value type");
if (!belongs<vertex_floating_properties>()(t))
throw GraphException("vertex property must be of floating point"
" value type");
size_t iter = 0;
run_action<>()
(g, bind<void>
(get_eigentrust(),
_1, g.GetVertexIndex(), g.GetEdgeIndex(), _2,
_3, epslon, max_iter),
_3, epslon, max_iter, ref(iter)),
writable_edge_scalar_properties(),
vertex_floating_properties())(c,t);
return iter;
}
void export_eigentrust()
......
......@@ -33,7 +33,7 @@ struct get_eigentrust
class InferredTrustMap>
void operator()(Graph& g, VertexIndex vertex_index,
EdgeIndex edge_index, TrustMap c, InferredTrustMap t,
double epslon, size_t max_iter) const
double epslon, size_t max_iter, size_t& iter) const
{
typedef typename property_traits<TrustMap>::value_type c_type;
typedef typename property_traits<InferredTrustMap>::value_type t_type;
......@@ -88,7 +88,7 @@ struct get_eigentrust
}
// init inferred trust t
int i, N = num_vertices(g);
int i, N = num_vertices(g), V = HardNumVertices()(g);
#pragma omp parallel for default(shared) private(i) \
schedule(dynamic)
for (i = 0; i < N; ++i)
......@@ -96,11 +96,11 @@ struct get_eigentrust
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
continue;
t[v] = 1.0/N;
t[v] = 1.0/V;
}
t_type delta = 2*epslon;
size_t iter = 0;
t_type delta = epslon + 1;
iter = 0;
while (delta >= epslon)
{
delta = 0;
......@@ -129,6 +129,7 @@ struct get_eigentrust
delta += abs(t_temp[v] - t[v]);
}
swap(t_temp, t);
++iter;
if (max_iter > 0 && iter== max_iter)
break;
......
......@@ -33,7 +33,7 @@ size_t pagerank(GraphInterface& g, boost::any rank, double d, double epslon,
size_t max_iter)
{
if (!belongs<writable_vertex_scalar_properties>()(rank))
throw GraphException("vertex property must be of writable");
throw GraphException("vertex property must be writable");
size_t iter;
run_action<>()
......
This diff is collapsed.
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