実験
http://www.kusastro.kyoto-u.ac.jp/~baba/wais/pagerank.html より参照
## pagerank.m - PageRank(TM) 計算用の簡単な GNU Octave スクリプト ## タイマーをセット。 tic(); ## 文書 i から文書 j へのリンクの状態を示す推移確率行列 M(i,j) を ## PageRank の定義に従って定義。 M = [ 0, 1/2, 1/3, 0; 1/2, 0, 1/3, 0; 1/2, 1/2, 0, 1; 0, 0, 1/3, 0; ] ## M の固有値と固有ベクトル列の組合わせのすべてを計算。 [V,D] = eig(M) ## 絶対値が最大の固有値に対応する固有ベクトルを EigenVector に保存。 EigenVector = V(:, find(abs(diag(D)) == max(abs(diag(D))))) ## PageRank は EigenVector を確率ベクトルに正規化したもの。 PageRank = EigenVector ./ norm(EigenVector, 1) ## かかった計算時間を表示。 elapsed_time = toc()
んでもって結果。
$ octave pagerank.m GNU Octave, version 2.1.69 (i386-pc-linux-gnu). Copyright (C) 2005 John W. Eaton. This is free software; see the source code for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, type `warranty'. Additional information about Octave is available at http://www.octave.org. Please contribute if you find this software useful. For more information, visit http://www.octave.org/help-wanted.html Report bugs to <bug@octave.org> (but first, please read http://www.octave.org/bugs.html to learn how to write a helpful report). M = 0.00000 0.50000 0.33333 0.00000 0.50000 0.00000 0.33333 0.00000 0.50000 0.50000 0.00000 1.00000 0.00000 0.00000 0.33333 0.00000 V = 4.7140e-01 4.9572e-01 7.0711e-01 2.3293e-01 4.7140e-01 4.9572e-01 -7.0711e-01 2.3293e-01 7.0711e-01 -4.0345e-01 3.6970e-16 -8.5862e-01 2.3570e-01 -5.8800e-01 4.7345e-18 3.9276e-01 D = 1.00000 0.00000 0.00000 0.00000 0.00000 0.22871 0.00000 0.00000 0.00000 0.00000 -0.50000 0.00000 0.00000 0.00000 0.00000 -0.72871 EigenVector = 0.47140 0.70711 0.23570 PageRank = 0.25000 0.37500 0.12500 elapsed_time = 0.034887
んー、速いのね。もうちょっとでかいデータでやってみるか。