Permalink
Browse files

wikipedia example

  • Loading branch information...
1 parent d15e2d4 commit 3b1cac3e79d43e7fdf85ec38c4350308c2672e1d @igrigorik committed Feb 20, 2010
Showing with 35 additions and 10 deletions.
  1. +35 −10 pagerank-gsl.rb
View
@@ -23,6 +23,11 @@ def pagerank(g)
t*((i-s*g).invert)*p
end
+# each array represents an adjancency matrix for each node, hence
+# [0,0,1] for the first element indicates that node 3 links to 1
+# and because the weight is 1, that's the only node coming from
+# node 3
+
# page 1 -> page 2 (0.33)
# page 2 -> page 3 (0.33)
# page 3 -> page 1 (0.33)
@@ -43,13 +48,33 @@ def pagerank(g)
# page 3 -> page 3 (0.69)
puts "Linked:", pagerank(Matrix[[0.5,0.5,0], [0.5,0,0], [0,0.5,1.0]])
-
-
-
-
-
-
-
-
-
-
+# wikipedia example: http://en.wikipedia.org/wiki/File:PageRanks-Example.svg
+#
+# a b c d e f g h i j k
+# [0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ]
+a = [0 ,0 ,0 ,0.50,0 ,0 ,0 ,0 ,0 ,0 ,0 ]
+b = [0 ,0 ,1 ,0.50,0.33,0.50,0 ,0 ,0.50,0.50,0.50]
+c = [0 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ]
+d = [0 ,0 ,0 ,0 ,0.33,0 ,0 ,0 ,0 ,0 ,0 ]
+e = [0 ,0 ,0 ,0 ,0 ,0.50,1 ,1 ,0.50,0.50,0.50]
+f = [0 ,0 ,0 ,0 ,0.33,0 ,0 ,0 ,0 ,0 ,0 ]
+g = [0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ]
+h = [0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ]
+i = [0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ]
+j = [0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ]
+k = [0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ]
+
+puts "Wikipedia: ", pagerank(Matrix[a,b,c,d,e,f,g,h,i,j,k])
+
+# Wikipedia:
+# a 2.755e-02
+# b 3.227e-01
+# c 2.879e-01
+# d 3.274e-02
+# e 6.812e-02
+# f 3.274e-02
+# g 1.364e-02
+# h 1.364e-02
+# i 1.364e-02
+# j 1.364e-02
+# k 1.364e-02

0 comments on commit 3b1cac3

Please sign in to comment.