pagerank of weighted network

987 views
Skip to first unread message

satyam

unread,
Aug 2, 2011, 3:40:54 PM8/2/11
to networkx-discuss
Hi
How do I compute the pagerank of a weighted network?
I have a file which reads like this

1 2 14
1 3 15
2 5 16

and so on...Here the first column is node i and 2nd column is node j.
The third column is weight of the edge (from 1-->2).
thanks
Satyam

Nicholas Dronen

unread,
Aug 3, 2011, 4:23:30 PM8/3/11
to networkx...@googlegroups.com

I don't have python where I am right now, so I can't write an example,
but I recommend using read_edgelist to create a graph, then calling
the pagerank function. Both functions are well documented. Looking
at the pagerank code in networkx 1.5, it appears to do the right thing
with weighted directed networks, so I think you should be OK there.

Regards,

Nick

Aric Hagberg

unread,
Aug 3, 2011, 4:29:42 PM8/3/11
to networkx...@googlegroups.com
Yes, that should do it. e.g.

In [1]: import networkx as nx

In [2]: cat graph.edgelist


1 2 14
1 3 15
2 5 16


In [3]: G=nx.read_weighted_edgelist('graph.edgelist',nodetype=int)

In [4]: nx.pagerank(G)
Out[4]:
{1: 0.31576945228063863,
2: 0.32367032787416605,
3: 0.17632967212583389,
5: 0.18423054771936137}

satyam mukherjee

unread,
Aug 4, 2011, 8:23:22 PM8/4/11
to networkx...@googlegroups.com
Thanks. Should work with my dataset :)



--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.




--
-------------------------------------------
WHEN LIFE GIVES U HUNDRED REASONS TO CRY,SHOW LIFE THAT U HAVE THOUSAND REASONS TO SMILE :-)

satyam mukherjee
224-436-3672 (Mob)
847-491-7238 (Off)

satyam mukherjee

unread,
Aug 17, 2011, 9:26:42 PM8/17/11
to networkx...@googlegroups.com
Well it doesn't work correctly I guess. Just consider this edgelist

1 2 14
2 3 11
3 1 21
3 2 31

>>> G=nx.read_weighted_edgelist('graph.edgelist',nodetype=int)
>>> print G.edges(data=True)
[(1, 2, {'weight': 14.0}), (1, 3, {'weight': 21.0}), (2, 3, {'weight': 31.0})]

Just see everything gets interchanged. Any suggestion how to overcome this?
Thanks
Satyam

Moritz Beber

unread,
Aug 18, 2011, 2:37:40 AM8/18/11
to networkx...@googlegroups.com
Hi,


On 08/18/2011 03:26 AM, satyam mukherjee wrote:
Well it doesn't work correctly I guess. Just consider this edgelist

1 2 14
2 3 11
3 1 21
3 2 31

>>> G=nx.read_weighted_edgelist('graph.edgelist',nodetype=int)
>>> print G.edges(data=True)
[(1, 2, {'weight': 14.0}), (1, 3, {'weight': 21.0}), (2, 3, {'weight': 31.0})]

Just see everything gets interchanged. Any suggestion how to overcome this?

You probably want a directed graph, i.e., pass create_using=nx.DiGraph() to read_weighted_edgelist.

Moritz

satyam mukherjee

unread,
Aug 24, 2011, 9:21:01 PM8/24/11
to networkx...@googlegroups.com
Thanks.
Also I am trying to use the weighted pagerank in the following way :

P(i) = (1-d)(\Sum_{j}P(j) w_{ji}/s_{j}^{out} ) + d/N
where s_{j}^{out} is the strength of the outgoing link 
s_{j}^{out} = \sum_{i}w_{ji}
currently in the weighted pagerank algorithm, we have the first term like 
w_{ji}/k_{j}^{out}. Basically one can take a look at this paper.

--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.

satyam mukherjee

unread,
Aug 25, 2011, 12:27:23 PM8/25/11
to networkx...@googlegroups.com
Ok. I found the solution to do this :

In the file stochastic.py pass
degree = W.out_degree(weighted=True). 

Thanks
Satyam
Reply all
Reply to author
Forward
0 new messages