pagerank_numpy

7 views
Skip to first unread message

Sudarshan Iyengar

unread,
Nov 26, 2009, 3:22:59 AM11/26/09
to networkx...@googlegroups.com
considering a path of length 10
>>>G=nx.path_graph(10)

pagerank_numpy gives:

[0.064384752387429953,
0.11619802055435763,
0.10934610989479178,
0.10579068620906137,
0.10428043095435952,
0.10428043095435952,
0.10579068620906139,
0.10934610989479179,
0.11619802055435767,
0.064384752387429953]

But the largest eigen vector is
[0.12013116478919983,
0.2305300235748291,
0.32225269079208374,
0.38786837458610535,
0.42206129431724548,
0.42206129431724548,
0.38786837458610535,
0.32225269079208374,
0.2305300235748291,
0.12013116478919983]

The values are very different... Pagerank essentially computes the
largest eigenvector right? Is there anything wrong with the
pagerank_numpy function or is something wrong in my understanding of
pagerank?

Sudarshan

Aric Hagberg

unread,
Nov 26, 2009, 7:33:21 AM11/26/09
to networkx...@googlegroups.com
On Thu, Nov 26, 2009 at 1:22 AM, Sudarshan Iyengar
<sudars...@gmail.com> wrote:
> considering a path of length 10
>>>>G=nx.path_graph(10)
>
> pagerank_numpy gives:
>
> [0.064384752387429953,
..
>
> But the largest eigen vector is
> [0.12013116478919983,
..
>
> The values are very different... Pagerank essentially computes the
> largest eigenvector right? Is there anything wrong with the
> pagerank_numpy function or is something wrong in my understanding of
> pagerank?

It depends on what you mean by "largest eigenvector". Pagerank
computes the eigenvector for the largest eigenvalue of the "Google
Matrix" which is related to the adjacency matrix.
http://en.wikipedia.org/wiki/Google_matrix


import networkx as nx
import numpy


edges=[(1,2),(1,3),\
(3,1),(3,2),(3,5),\
(4,5),(4,6),\
(5,4),(5,6),\
(6,4)]
G=nx.DiGraph(edges)

# find largest eigenval/eigenvec pair using linpack
M=nx.google_matrix(G,alpha=0.9)
e,ev=numpy.linalg.eig(M.T)
p=numpy.array(ev[:,0]/ev[:,0].sum())[:,0] # normalize
# 0.03721197 0.05395735 0.04150565 0.37508082 0.20599833 0.28624589]
print p
# numpy iterative version
print nx.pagerank_numpy(G,alpha=0.9)
# Python version
print nx.pagerank(G,alpha=0.9).values()

Aric
Reply all
Reply to author
Forward
0 new messages