PageRank
参考http://www.doc88.com/p-11465283738.html
G = [0 1 1 0 1 1 0;
1 0 1 1 0 0 0;
1 0 0 1 1 0 0;
1 0 0 0 1 0 0;
1 0 0 1 0 1 1;
0 0 0 1 1 0 0;
1 0 0 0 0 0 0];
[n,n] = size(G);
p = 0.85
delta = (1-p)/n;
sn = sum(G,1); %按列求矩阵G的列和
D = diag(1./sn);
A = p*G*D + delta;
%幂迭代法
x = ones(n,1)/n; %迭代初始向量
z = zeros(n,1);
cnt = 0; %记录迭代步数
while max(abs(x-z)) > 0.0001
z = x;
x = A * x;
cnt = cnt + 1;
end
[x1,index] = sort(x);
x1 = flipud(x1);
index = flipud(index);
out = [1:n;x1';index'];
fprintf('迭代步数 = %d\n',cnt)
str1 = '排名';str2 ='PageRank得分'; str3 = '序号';
fprintf('%-6s %-15s %-5s\n',str1,str2,str3);
fprintf('%-6d %-15f %-5d\n',out);
结果
p =
0.8500
迭代步数 = 11
排名 PageRank得分 序号
1 0.276926 1
2 0.185228 5
3 0.147001 2
4 0.130779 3
5 0.107858 4
6 0.083714 6
7 0.068494 7