Commit be0a81d4 authored by Tiago Peixoto's avatar Tiago Peixoto

Make initialization of eigenvector() and pagerank() optional

parent 4938eb8b
......@@ -43,22 +43,10 @@ struct get_eigenvector
CentralityMap c_temp(vertex_index, num_vertices(g));
// init centrality
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)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
continue;
c[v] = 1.0 / V;
}
t_type norm = 0;
t_type delta = epsilon + 1;
size_t iter = 0;
int i, N = num_vertices(g);
while (delta >= epsilon)
{
norm = 0;
......
......@@ -40,7 +40,7 @@ struct get_pagerank
RankMap r_temp(vertex_index, num_vertices(g));
RankMap deg(vertex_index, num_vertices(g));
// init ranks
// init degs
int i, N = num_vertices(g);
#pragma omp parallel for default(shared) private(i) \
schedule(dynamic)
......@@ -49,10 +49,8 @@ struct get_pagerank
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
continue;
put(rank, v, get(pers, v));
typename graph_traits<Graph>::out_edge_iterator e, e_end;
put(deg, v, 0);
typename graph_traits<Graph>::out_edge_iterator e, e_end;
for (tie(e, e_end) = out_edges(v, g); e!= e_end; ++e)
put(deg, v, get(deg, v) + get(weight, *e));
}
......
......@@ -73,7 +73,8 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6,
weight : :class:`~graph_tool.PropertyMap`, optional (default: None)
Edge weights. If omitted, a constant value of 1 will be used.
prop : :class:`~graph_tool.PropertyMap`, optional (default: None)
Vertex property map to store the PageRank values.
Vertex property map to store the PageRank values. If supplied, it will
be used uninitialized.
epsilon : float, optional (default: 1e-6)
Convergence condition. The iteration will stop if the total delta of all
vertices are below this value.
......@@ -198,6 +199,8 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6,
max_iter = 0
if prop == None:
prop = g.new_vertex_property("double")
N = len(prop.a)
prop.a = pers.a[:N] if pers is not None else 1. / g.num_vertices()
ic = libgraph_tool_centrality.\
get_pagerank(g._Graph__graph, _prop("v", g, prop),
_prop("v", g, pers), _prop("e", g, weight),
......@@ -375,7 +378,8 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None):
weight : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
Edge property map with the edge weights.
vprop : :class:`~graph_tool.PropertyMap`, optional (default: ``None``)
Vertex property map where the values of eigenvector must be stored.
Vertex property map where the values of eigenvector must be stored. If
provided, it will be used uninitialized.
epsilon : float, optional (default: ``1e-6``)
Convergence condition. The iteration will stop if the total delta of all
vertices are below this value.
......@@ -460,8 +464,9 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None):
"""
if vprop == None:
if vprop is None:
vprop = g.new_vertex_property("double")
vprop.a = 1. / g.num_vertices()
if max_iter is None:
max_iter = 0
ee = libgraph_tool_centrality.\
......
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