I am trying to implement textrank algorithm for sentence extraction as described here. For that in need to complement pagerank algorithm with weighted edges and get it to run on undirected graphs.
Networkx pagerank algorithm implementation allows me to easely integrate weighted edges and is said to convert directed graphs to undirected: see here.
However, when I tested it still seems to use directed graph. What am I missing here? Help greatly appriciated.
Example:
import networkx as nx
D=nx.DiGraph()
D.add_weighted_edges_from([('A','B',0.5),('A','C',1)])
print nx.pagerank(D)
Outpunt: {‘A’: 0.25974025929223499, ‘C’: 0.40692640737443164, ‘B’: 0.33333333333333331}
I think you misinterpreted the note on the networkx documentation. Though, I must admit it might be worded better.
What this tells is that, PageRank algorithm is designed for directed graphs, but it can be used for undirected graphs. To do so, it converts the undirected network to a directed network by replacing each edge with two directed edges (in and out).
Therefore, if you give it a directed network, it will calculate the PageRank according to the directed structure. So either start with an undirected network:
or if you already have a directed network, convert it to an undirected one: